1 #include <windows.h> 2 3 #define WIN_CLASS "GameFrame" //窗口类名 4 #define WIN_NAME "SampleGame" //窗口标题 5 #define WIN_WIDTH 800 //窗口宽度 6 #define WIN_HEIGHT 600 //窗口高度 7 8 9 //窗口消息处理函数 10 LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) 11 { 12 switch (msg) 13 { 14 case WM_DESTROY: 15 PostQuitMessage(0); 16 break; 17 case WM_LBUTTONUP: 18 MessageBox(NULL,"Hello Directx!","Info",MB_OK); 19 break; 20 } 21 return DefWindowProc(hwnd,msg,wparam,lparam); 22 } 23 24 25 //标准win32程序入口 26 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) 27 { 28 WNDCLASSEX wc={sizeof(WNDCLASSEX),CS_CLASSDC,WndProc,0,0,hInstance,LoadIcon(NULL,IDI_APPLICATION),LoadCursor(NULL,IDC_ARROW),NULL,NULL,WIN_CLASS,NULL}; 29 RegisterClassEx(&wc); 30 HWND hwnd= CreateWindow(WIN_CLASS,WIN_NAME,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,WIN_WIDTH,WIN_HEIGHT,NULL,NULL,hInstance,NULL); 31 if (hwnd==0) 32 { 33 return 0; 34 } 35 ShowWindow(hwnd,nShowCmd); 36 UpdateWindow(hwnd); 37 MSG msg; 38 ZeroMemory(&msg,sizeof(MSG)); 39 while (msg.message!=WM_QUIT) 40 { 41 if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) 42 { 43 TranslateMessage(&msg); 44 DispatchMessage(&msg); 45 } 46 } 47 UnregisterClass(WIN_CLASS,wc.hInstance); 48 return 0; 49 }
时间: 2024-10-29 19:09:53