1 LRESULT WINAPI WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) 2 { 3 PAINTSTRUCT ps; 4 switch (msg) 5 { 6 case WM_PAINT: 7 { 8 BeginPaint(hWnd,&ps); 9 EndPaint(hWnd,&ps); 10 return 0; 11 } 12 case WM_DESTROY: 13 { 14 PostQuitMessage(0); 15 return 0; 16 } 17 } 18 19 return DefWindowProc(hWnd,msg,wParam,lParam); 20 } 21 void initWndClass(HINSTANCE hInstance,WNDCLASSEX &wndClass) 22 { 23 wndClass.cbSize = sizeof(WNDCLASSEX); 24 wndClass.style = CS_HREDRAW | CS_VREDRAW; 25 wndClass.lpfnWndProc = WndProc; 26 wndClass.cbClsExtra = 0; 27 wndClass.cbWndExtra = 0; 28 wndClass.hInstance = hInstance; 29 wndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION); 30 wndClass.hCursor = LoadCursor(NULL,IDC_ARROW); 31 wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); 32 wndClass.lpszClassName = TEXT(CLASSNAME); 33 wndClass.lpszMenuName = NULL; 34 wndClass.hIconSm = LoadIcon(NULL,IDI_WINLOGO); 35 }
1 int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) 2 { 3 HWND hWnd; 4 5 WNDCLASSEX wndClass; 6 initWndClass(hInstance,wndClass); 7 8 RegisterClassEx(&wndClass); 9 10 hWnd = CreateWindow( 11 TEXT(CLASSNAME), 12 TEXT(APPNAME), 13 WS_OVERLAPPEDWINDOW, 14 CW_USEDEFAULT, 15 CW_USEDEFAULT, 16 SCREEN_W, 17 SCREEN_H, 18 NULL, 19 NULL, 20 hInstance, 21 NULL 22 ); 23 24 if (NULL == hWnd) 25 { 26 MessageBox(NULL,TEXT("NULL == hWnd"),NULL,MB_OK); 27 return 0; 28 } 29 30 UpdateWindow(hWnd); 31 ShowWindow(hWnd,nShowCmd); 32 MSG msg; 33 while (true) 34 { 35 if ( PeekMessage(&msg,NULL,0,0,PM_REMOVE) ) 36 { 37 if (WM_QUIT == msg.message) 38 { 39 break; 40 } 41 TranslateMessage(&msg); 42 DispatchMessage(&msg); 43 } 44 else 45 { 46 Render(); 47 } 48 } 49 Release(); 50 return msg.lParam; 51 }