First Window

This commit is contained in:
2025-11-06 00:19:19 +08:00
commit 6878d0d0de
5 changed files with 204 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
#include "c_WinGuiApp.h"
/* -------------------------------------------------------------------------------------------------------------- */
/* */
#define MAIN_WINDOW_CLASSNAME "c_WinGuiApp_Main"
/* -------------------------------------------------------------------------------------------------------------- */
/* */
static void MainWindow_OnDestroy(HWND hwnd){
PostQuitMessage(0);
}
static void MainWindow_OnPaint(HWND hwnd){
PAINTSTRUCT PaintStruct;
HDC hdc = BeginPaint(hwnd, &PaintStruct);
TextOutA(hdc, 10, 10, "Hello", 5);
EndPaint(hwnd, &PaintStruct);
}
/* -------------------------------------------------------------------------------------------------------------- */
/* */
c_WinGuiApp_EventBegin(WndProc)
c_WinGuiApp_OnEvent(WM_DESTROY, MainWindow_OnDestroy)
c_WinGuiApp_OnEvent(WM_PAINT, MainWindow_OnPaint)
c_WinGuiApp_EventEnd
/* -------------------------------------------------------------------------------------------------------------- */
/* */
static bool Register(HINSTANCE hInstance){
WNDCLASS WndClass;
WndClass.lpszClassName = MAIN_WINDOW_CLASSNAME;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.cbWndExtra = 0;
WndClass.cbClsExtra = 0;
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = NULL;
return (RegisterClass(&WndClass)!=0);
}
static HWND Create(HINSTANCE hInstance, int nCmdShow){
HWND hWindow = CreateWindowEx(0, MAIN_WINDOW_CLASSNAME, MAIN_WINDOW_CLASSNAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if(!hWindow) return NULL;
c_WinGuiApp.hMainWindow = hWindow;
ShowWindow(hWindow, nCmdShow);
UpdateWindow(hWindow);
return hWindow;
}
/* -------------------------------------------------------------------------------------------------------------- */
/* */
c_WinGuiApp_Main(Register, Create)