创建窗口

来源:互联网 发布:万网临时域名怎么申请 编辑:程序博客网 时间:2024/05/01 02:12

#include <windows.h>

LRESULT CALLBACK WindowProc( 
       HWND hwnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM lParam
       );

int WinMain(HINSTANCE hInstance,
             HINSTANCE hPrevInstance,
               LPSTR     lpCmdLine,
                int       nCmdShow)
{
 MSG uMsg;
 HWND hwnd;
 WNDCLASSEX wcs;
  {
  wcs.cbSize = sizeof(WNDCLASSEX);
  wcs.style = CS_HREDRAW |CS_VREDRAW ;
  
  wcs.cbClsExtra = 0;
  wcs.cbWndExtra = 0;
 
  wcs.lpfnWndProc=(WNDPROC)WindowProc ; 
  wcs.hInstance = hInstance;
  
  wcs.hIcon = NULL;
  wcs.hCursor = NULL;
 
  wcs.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);;
  wcs.lpszClassName ="test";
  wcs.lpszMenuName = "HELLO";
  
  wcs.hIconSm = NULL;
 }
    RegisterClassEx(&wcs);

 hwnd = CreateWindow("test","ttyy",WS_OVERLAPPEDWINDOW,
      0,0,500,200,NULL,NULL,hInstance,NULL);
 
 ShowWindow(hwnd,SW_SHOW);
 UpdateWindow(hwnd);

while (GetMessage(&uMsg, NULL, 0, 0))
 {
   TranslateMessage(&uMsg);
   DispatchMessage(&uMsg);
 
 }

  return 0;
}
LRESULT CALLBACK WindowProc( 
       HWND hwnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM lParam
       )
{
 switch (uMsg)
 {
  case WM_DESTROY:
   PostQuitMessage(0);
   break;
  default:
   return DefWindowProc(hwnd, uMsg, wParam, lParam);
   }
   return 0;
}