1 #define WIN32_LEAN_AND_MEAN 2 #include <windows.h> 3 #include <windowsx.h> 4 #include <math.h> 5 #define WINDOW_CLASS_NAME L"WINCLASS1" 6 //窗口处理函数 7 LRESULT CALLBACK WindowProc(HWND hwnd, 8 UINT msg, 9 WPARAM wParam, 10 LPARAM lPram) 11 { 12 PAINTSTRUCT ps; 13 HDC hdc; 14 switch (msg) 15 { 16 case WM_CREATE: 17 { 18 return 0; 19 }break; 20 case WM_PAINT: 21 { 22 hdc = BeginPaint(hwnd, &ps); 23 EndPaint(hwnd, &ps); 24 return 0; 25 }break; 26 default:break; 27 } 28 return DefWindowProc(hwnd, msg, wParam, lPram); 29 } 30 void GameMain() 31 { 32 return; 33 } 34 int WINAPI WinMain(HINSTANCE hInstance, 35 HINSTANCE hPrevInstance, 36 LPSTR lpCmdLine, 37 int nCmdShow) 38 { 39 //定义窗口类 40 WNDCLASSEX winClass; 41 HWND hWnd; 42 MSG msg; 43 //填充窗口类的个成员 44 winClass.cbSize = sizeof(WNDCLASSEX); 45 winClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; 46 winClass.lpfnWndProc = WindowProc; //窗口消息处理函数 47 winClass.cbClsExtra = 0; 48 winClass.cbWndExtra = 0; 49 winClass.hInstance = hInstance; 50 winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); 51 winClass.hCursor = LoadCursor(NULL, IDC_ARROW); 52 winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 53 winClass.lpszMenuName = NULL; 54 winClass.lpszClassName = WINDOW_CLASS_NAME; //窗口类名 55 winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 56 57 //注册窗口类 58 if (!RegisterClassEx(&winClass)) 59 { 60 return 0; 61 } 62 63 //创建窗口类的一个成员 64 if (!(hWnd = CreateWindowEx(NULL, 65 WINDOW_CLASS_NAME, 66 L"hello world", 67 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 68 0, 0, 69 640, 480, 70 NULL, 71 NULL, 72 hInstance, 73 NULL))) 74 { 75 return 0; 76 } 77 78 //消息循环 79 while (true) 80 { 81 if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)) 82 { 83 if (msg.message == WM_QUIT) 84 { 85 break; 86 } 87 TranslateMessage(&msg); 88 DispatchMessage(&msg); 89 } 90 GameMain(); 91 } 92 return msg.wParam; 93 }