封装window窗口
#define WIN32_LEAN_AND_MEAN#include<windows.h>#include<windowsx.h>#include<tchar.h>LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam);int t=0;const TCHAR *g_pWindowsClassName = _T("GameUserInterface");const TCHAR *g_pWindowsTitle = _T("GameUserInterface");int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS; wndClass.lpfnWndProc = WNDPROC(WindowProc); wndClass.cbWndExtra = 0; wndClass.cbClsExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = g_pWindowsClassName; wndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);if(!RegisterClassEx(&wndClass)) { MessageBox(NULL,_T("注册窗口类失败!"), _T("错误信息"),MB_OK); return 0; } HWND handleWindow; if(!(handleWindow = CreateWindowEx(NULL, g_pWindowsClassName, g_pWindowsTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1050, 400, NULL, NULL, hInstance, NULL))) { MessageBox(NULL, _T("注册窗口失败!"), _T("错误信息"),MB_OK); return 0; } ShowWindow(handleWindow, nCmdShow); UpdateWindow(handleWindow); MSG msg; ZeroMemory(&msg, sizeof(msg)); while(msg.message != WM_QUIT) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { } } return static_cast<int>(msg.wParam);}LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam){ PAINTSTRUCT paintStruct; HDC hdc; switch(msg) { case WM_CREATE: { }break; case WM_PAINT: { hdc = BeginPaint(hWnd, &paintStruct); EndPaint(hWnd, &paintStruct); }break; case WM_DESTROY: { PostQuitMessage(0); }break; default: { return DefWindowProc(hWnd, msg, lParam, wParam); } } return 0;}