Last active
January 9, 2023 17:00
-
-
Save FireBanana/4b3319dd5292a09061ec7c66be6e4a84 to your computer and use it in GitHub Desktop.
Create a Win32 Window from console
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 <iostream> | |
#include <windows.h> | |
LRESULT __stdcall WindowProcedure(HWND window, UINT msg, WPARAM wp, LPARAM lp) | |
{ | |
switch (msg) | |
{ | |
case WM_DESTROY: | |
std::cout << "\ndestroying window\n"; | |
PostQuitMessage(0); | |
return 0L; | |
case WM_LBUTTONDOWN: | |
// fall thru | |
default: | |
return DefWindowProc(window, msg, wp, lp); | |
} | |
} | |
int main() | |
{ | |
const auto myclass = L"myclass"; | |
WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, WindowProcedure, | |
0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION), | |
LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW + 1), | |
0, myclass, LoadIcon(0,IDI_APPLICATION) }; | |
if (RegisterClassEx(&wndclass)) | |
{ | |
HWND window = CreateWindowEx(0, myclass, L"title", | |
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, | |
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0); | |
if (window) | |
{ | |
ShowWindow(window, SW_SHOWDEFAULT); | |
MSG msg; | |
while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment