Win32窗口
<pre><code class="language-cpp">#include &lt;Windows.h&gt;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE: {
break; }
case WM_PAINT: {
break; }
case WM_LBUTTONDOWN: {
break; }
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
int main()
{
// 注册窗口类
WNDCLASSEXW wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEXW);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = [](HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -&gt; LRESULT {
SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)WndProc); // 指向新的窗口过程
return WndProc(hWnd, uMsg, wParam, lParam);
};
wcex.hInstance = GetModuleHandleW(nullptr);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
wcex.lpszClassName = L&quot;Window.ClassName&quot;;
RegisterClassExW(&amp;wcex);
// 创建窗口
HWND hWnd = CreateWindowExW(
0, L&quot;Window.ClassName&quot;, L&quot;Window.Test&quot;,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
200, 200, 800, 600,
nullptr, nullptr, GetModuleHandleW(nullptr), nullptr);
UpdateWindow(hWnd);
// 建立消息循环
MSG msg = { 0 };
while (GetMessageW(&amp;msg, nullptr, 0, 0) &gt; 0) {
TranslateMessage(&amp;msg);
DispatchMessageW(&amp;msg);
}
return (int)msg.wParam;
}
</code></pre>