Windows窗口模板

时间:2022-07-28
本文章向大家介绍Windows窗口模板,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.界面效果

2.相关代码

#include<Windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdshow)
{
static TCHAR szAppName[] = TEXT("你好");
 HWND hwnd;
 MSG msg;
 WNDCLASS wndclass;
 wndclass.style = CS_VREDRAW | CS_HREDRAW;//窗口风格
 wndclass.lpfnWndProc = WindowProc;  //消息响应
 wndclass.cbClsExtra = 0;
 wndclass.cbWndExtra = 0;
 wndclass.hInstance = hInstance;//句柄
 wndclass.hIcon = LoadIcon(NULL, IDI_ERROR);//图标
 wndclass.hCursor = LoadCursor(NULL, IDI_APPLICATION);//光标
 wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//背景
 wndclass.lpszMenuName= NULL;
 wndclass.lpszClassName = szAppName;
 if (!RegisterClass(&wndclass))
 {
   MessageBox(NULL, TEXT("This program requires Windows NT!"),
   szAppName, MB_ICONERROR);
  return 0;
 }
  hwnd=CreateWindow( szAppName,
  TEXT("第二个程序"),
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, // initial x position  
  CW_USEDEFAULT, // initial y position    
  CW_USEDEFAULT, // initial x size   
  CW_USEDEFAULT, // initial y size  
  NULL,   // parent window handle  
  NULL,         // window menu handle  
  hInstance,     // program instance handle   
  NULL) ;      // creation parameters
 ShowWindow(hwnd, nCmdshow);
 UpdateWindow(hwnd);
 while (GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 return 0;
 }
 LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 RECT  rect;
 switch (uMsg)
 {
  case WM_CREATE:
  return 0;
  case WM_PAINT:
  return 0;
 case WM_DESTROY:   
  return 0;
 }
  return DefWindowProc(hwnd, uMsg, wParam, lParam);
}