Skip to content

Instantly share code, notes, and snippets.

@nir9
Created January 8, 2024 20:54
Show Gist options
  • Save nir9/9c6d45d80e7b0e1b1650bbef30c0f81d to your computer and use it in GitHub Desktop.
Save nir9/9c6d45d80e7b0e1b1650bbef30c0f81d to your computer and use it in GitHub Desktop.
Simple GUI Window App for Windows - not for production, only for fun
#include <Windows.h>
LRESULT WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_PAINT:
HDC hDc = GetDC(hWnd);
RECT rect = {
75,
75,
250,
250
};
HBRUSH hBr = CreateSolidBrush(RGB(0,0,255));
FillRect(hDc, &rect, hBr);
DeleteObject(hBr);
ReleaseDC(hWnd, hDc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE a, PSTR b, int nCmdShow) {
WNDCLASSA class = {
0,
WinProc,
0,
0,
hInstance,
NULL,
NULL,
NULL,
NULL,
"NirsClass"
};
RegisterClassA(&class);
HWND windowHandle = CreateWindowA("NirsClass", "Hello", WS_CAPTION | WS_POPUP | WS_SYSMENU, 50, 50, 500, 500, NULL, NULL, hInstance, NULL);
ShowWindow(windowHandle, nCmdShow);
MSG msg;
for (;;) {
if (GetMessageA(&msg, NULL, 0, 0) == 0) {
break;
}
DispatchMessageA(&msg);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment