Last active
July 28, 2025 19:45
-
-
Save 8chan-co/6c5cf293626b47242e9c62c690fb4022 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// file: limsim/main.h | |
#pragma once | |
#include <sdkddkver.h> | |
#include <windows.h> | |
#define UNREFERENCED_PARAMETERS(...) (VOID)(__VA_ARGS__) | |
INT WINAPI wWinMain(_In_ HMODULE Application, _In_opt_ HMODULE _, | |
_In_ PWSTR Arguments, _In_ INT WindowState); | |
VOID RegisterWindowClass(HMODULE Application); | |
BOOL CreateMainWindow(HMODULE Application, INT WindowState); | |
LRESULT CALLBACK Main(HWND Window, UINT Message, WPARAM W, LPARAM L); | |
// end file | |
// file: limsim/main.c | |
#include "main.h" | |
WCHAR Title[] = L"limsim"; | |
WCHAR Class[] = L"limsim::window::class::main"; | |
INT WINAPI wWinMain(_In_ HMODULE Application, _In_opt_ HMODULE _, | |
_In_ PWSTR Arguments, _In_ INT WindowState) { | |
UNREFERENCED_PARAMETERS(_, Arguments); | |
RegisterWindowClass(Application); | |
if (FALSE == CreateMainWindow(Application, WindowState)) { | |
return FALSE; | |
} | |
MSG Message; | |
while (GetMessageW(&Message, HWND_DESKTOP, 0U, 0U) > 0) { | |
TranslateMessage(&Message); | |
DispatchMessageW(&Message); | |
} | |
return (INT)Message.wParam; | |
} | |
VOID RegisterWindowClass(HMODULE Application) { | |
HICON Icon = | |
(HICON)LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED); | |
HCURSOR Cursor = | |
(HCURSOR)LoadImageW(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED); | |
WNDCLASSEXW WindowClass = { | |
.cbSize = sizeof WindowClass, | |
.style = CS_HREDRAW | CS_VREDRAW, | |
.lpfnWndProc = Main, | |
.cbClsExtra = 0, | |
.cbWndExtra = 0, | |
.hInstance = Application, | |
.hIcon = Icon, | |
.hCursor = Cursor, | |
.hbrBackground = CreateSolidBrush(RGB(32, 32, 32)), | |
.lpszMenuName = NULL, | |
.lpszClassName = Class, | |
.hIconSm = Icon, | |
}; | |
RegisterClassExW(&WindowClass); | |
} | |
BOOL CreateMainWindow(HMODULE Application, INT WindowState) { | |
HWND Window = | |
CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, Class, Title, WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | |
CW_USEDEFAULT, NULL, NULL, Application, NULL); | |
if (NULL == Window) { | |
return FALSE; | |
} | |
ShowWindow(Window, WindowState); | |
return TRUE; | |
} | |
LRESULT CALLBACK Main(HWND Window, UINT Message, WPARAM W, LPARAM L) { | |
LRESULT Result = 0LL; | |
switch (Message) { | |
case WM_PAINT: { | |
PAINTSTRUCT Canvas; | |
BeginPaint(Window, &Canvas); | |
CONST UINT Format = DT_SINGLELINE | DT_VCENTER | DT_CENTER; | |
DrawTextW(Canvas.hdc, Title, INFINITE, &Canvas.rcPaint, Format); | |
EndPaint(Window, &Canvas); | |
} break; | |
case WM_DESTROY: { | |
PostQuitMessage(0); | |
} break; | |
default: { | |
Result = DefWindowProcW(Window, Message, W, L); | |
} break; | |
} | |
return Result; | |
} | |
// end file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment