Last active
May 2, 2023 11:57
-
-
Save cos-public/c4a3ad7a3172ca37d9ab027d344e82d5 to your computer and use it in GitHub Desktop.
minimal classic win32 application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <cstdint> | |
inline LRESULT CALLBACK main_window_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { | |
if (message == WM_CREATE) { | |
::OutputDebugStringW(L"WM_CREATE\n"); | |
} | |
if (message == WM_PAINT) { | |
::OutputDebugStringW(L"WM_PAINT\n"); | |
} | |
if (message == WM_DESTROY) { | |
::OutputDebugStringW(L"WM_DESTROY\n"); | |
::PostQuitMessage(EXIT_SUCCESS); | |
} | |
/// DefWindowProcW calls DestroyWindow(), which sends WM_DESTROY by default | |
return ::DefWindowProcW(hWnd, message, wParam, lParam); | |
} | |
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd) try { | |
static const WNDCLASSEXW wnd_class { | |
.cbSize = sizeof(WNDCLASSEXW), | |
.style = CS_HREDRAW | CS_VREDRAW, | |
.lpfnWndProc = &main_window_proc, | |
.cbClsExtra = 0, | |
.cbWndExtra = sizeof(std::uintptr_t), | |
.hInstance = ::GetModuleHandle(NULL), | |
.hIcon = NULL, | |
.hCursor = ::LoadCursorW(NULL, IDC_ARROW), | |
.hbrBackground = NULL, | |
.lpszMenuName = NULL, | |
.lpszClassName = L"main_window", | |
.hIconSm = NULL | |
}; | |
const ATOM cls = ::RegisterClassExW(&wnd_class); | |
HWND hWnd = ::CreateWindowEx(0, MAKEINTRESOURCEW(cls), L"Main Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, | |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, nullptr); | |
MSG msg; | |
BOOL bRet; | |
while ((bRet = ::GetMessage(&msg, NULL, 0, 0)) != 0) { | |
::TranslateMessage(&msg); | |
::DispatchMessage(&msg); | |
} | |
return static_cast<int>(msg.wParam); | |
} catch (...) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment