1 #include <Windows.h> 2 #include <tchar.h> 3 4 5 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 6 7 8 int APIENTRY _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nCmdShow) 9 { 10 MSG msg; 11 WNDCLASSEX wcex; 12 HWND hWnd; 13 14 wcex.cbClsExtra = 0; 15 wcex.cbSize = sizeof(WNDCLASSEX); 16 wcex.cbWndExtra = 0; 17 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); 18 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 19 wcex.hIcon = NULL; 20 wcex.hIconSm = NULL; 21 wcex.hInstance = hInst; 22 wcex.lpfnWndProc = WndProc; 23 wcex.lpszClassName = _T("Wnd"); 24 wcex.lpszMenuName = NULL; 25 wcex.style = CS_VREDRAW | CS_HREDRAW; 26 if (!RegisterClassEx(&wcex)) 27 { 28 MessageBox(NULL, _T("RegisterClassEx()"), NULL, MB_ICONERROR); 29 return 0; 30 } 31 32 hWnd = CreateWindowEx(0, _T("Wnd"), _T("WinMain"), 33 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 34 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 35 NULL, NULL, hInst, NULL); 36 if (!hWnd) 37 { 38 MessageBox(NULL, _T("CreateWindowEx()"), NULL, MB_ICONERROR); 39 return 0; 40 } 41 42 while (GetMessage(&msg, NULL, 0, 0)) 43 { 44 TranslateMessage(&msg); 45 DispatchMessage(&msg); 46 } 47 48 return 0; 49 } 50 51 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 52 { 53 switch (uMsg) 54 { 55 case WM_DESTROY: 56 PostQuitMessage(0); 57 break; 58 default: 59 return DefWindowProc(hWnd, uMsg, wParam, lParam); 60 } 61 62 return 0; 63 }
转载于:https://www.cnblogs.com/qbj196/p/10634993.html