From 24cbbcccc4de7173db1dc4d9031e87766d5eaa00 Mon Sep 17 00:00:00 2001 From: Chen Peng Date: Thu, 6 Nov 2025 00:27:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E5=AD=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyText.t.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ c_WinGuiApp.h | 1 + 2 files changed, 89 insertions(+) create mode 100644 EasyText.t.c diff --git a/EasyText.t.c b/EasyText.t.c new file mode 100644 index 0000000..104f454 --- /dev/null +++ b/EasyText.t.c @@ -0,0 +1,88 @@ +#include "c_WinGuiApp.h" + +/* -------------------------------------------------------------------------------------------------------------- */ +/* */ + +#define MAIN_WINDOW_CLASSNAME "EasyText" + +/* -------------------------------------------------------------------------------------------------------------- */ +/* */ + +#define DIRECTION_SIZE 100 + +static char Directions[DIRECTION_SIZE]; + +/* -------------------------------------------------------------------------------------------------------------- */ +/* */ + +static BOOL MainWindow_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct){ + char* msg = "Try resizing this window."; + strcpy(Directions, msg); + return TRUE; +} + +static void MainWindow_OnDestroy(HWND hwnd){ + PostQuitMessage(0); +} + +static void MainWindow_OnPaint(HWND hwnd){ + PAINTSTRUCT PaintStruct; + RECT Rect; + HDC hdc = BeginPaint(hwnd, &PaintStruct); + SetBkMode(hdc, TRANSPARENT); + TextOut(hdc, 10, 10, Directions, lstrlen(Directions)); + GetClientRect(hwnd, &Rect); + DrawText(hdc, "The middle of the road", -1, &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + EndPaint(hwnd, &PaintStruct); +} + +/* -------------------------------------------------------------------------------------------------------------- */ +/* */ + +c_WinGuiApp_EventBegin(WndProc) + c_WinGuiApp_OnEvent(WM_CREATE, MainWindow_OnCreate) + 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) + + diff --git a/c_WinGuiApp.h b/c_WinGuiApp.h index 2dc23c6..4b1d7b6 100644 --- a/c_WinGuiApp.h +++ b/c_WinGuiApp.h @@ -73,6 +73,7 @@ extern c_WinGuiApp_t c_WinGuiApp; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow){ \ MSG Msg; \ if(!hPrevInstance){ \ + c_WinGuiApp.hInstance = hInstance; \ if(!fRegister(hInstance)){ \ return FALSE; \ } \