记录一下模版
#include <Windows.h> LRESULT CALLBACK myProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); //程序入口 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, char * lpCmdLine, int nCmdShow) { WNDCLASS wnd = { 0 }; wnd.cbClsExtra = 0; wnd.cbWndExtra = 0; wnd.hbrBackground = (HBRUSH)GetStockObject(WHITENESS); wnd.hCursor = LoadCursor(NULL, IDC_ARROW); wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd.hInstance = hInstance; wnd.lpfnWndProc = myProc; //过程函数 wnd.lpszClassName = "test"; wnd.lpszMenuName = NULL; wnd.style = CS_VREDRAW | CS_HREDRAW; //注册窗口 if (!RegisterClass(&wnd)) { MessageBox(NULL, "注册窗口失败", "error", MB_OK); return false; } float app_centerX = GetSystemMetrics(SM_CXSCREEN) / 2.0f; float app_centerY = GetSystemMetrics(SM_CYSCREEN) / 2.0f; float dm_width = 600; float dm_height = 800; //创建窗口 HWND hwnd = CreateWindow( "test", "title", WS_OVERLAPPEDWINDOW, //此处显示为没有标题栏和菜单栏 WS_VISIBLE | WS_POPUP app_centerX - dm_width / 2.0f, app_centerY - dm_height / 2.0f, static_cast<int>(dm_width), static_cast<int>(dm_height), NULL, NULL, hInstance, NULL); if (!hwnd) { MessageBox(NULL, "窗口创建失败", "error", MB_OK); return false; } //显示 ShowWindow(hwnd, nCmdShow); //消息循环 MSG msg; while (GetMessage(&msg, hwnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } //过程函数 LRESULT CALLBACK myProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CLOSE: if (MessageBox(hwnd, "确定退出游戏?", "msg", MB_OKCANCEL) == IDOK){ PostQuitMessage(0); break; } return 0; case WM_DESTROY: exit(0); return 0; default: break; } return DefWindowProc(hwnd,message,wParam,lParam); }