一个win32窗口应用的程序代码框架
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
// Initialize the window.
SetWindowTextW(hWnd, L"HelloWorld");
return 0;
case WM_PAINT:
// Paint the window's client area.
return 0;
case WM_SIZE:
// Set the size and position of the window.
return 0;
case WM_DESTROY:
// Clean up window-specific data objects.
PostQuitMessage(NULL);
return 0;
//
// Process other messages.
//
default:
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
const LPCWSTR className = L"啊吧啊吧";
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(wc);
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = nullptr;
wc.hCursor = nullptr;
wc.hbrBackground = nullptr;
wc.lpszMenuName = nullptr;
wc.lpszClassName = className;
wc.hIconSm = nullptr;
RegisterClassEx(&wc);
HWND hWnd = CreateWindowEx(0, className, L"乌拉乌拉", WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, 200, 200, 600, 500, nullptr, nullptr, hInstance, nullptr);
ShowWindow(hWnd, SW_SHOW);
MSG msg = { 0 };
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}