From f4261c0f8bb7d6696f741c33afb30639d1b67f97 Mon Sep 17 00:00:00 2001 From: Chen Peng Date: Fri, 31 Jul 2026 19:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GUITest/SysInfo.t.c | 165 +++++++++++++++++++++++++++++++++++++++++++ GUITest/WinStyle.t.c | 11 +-- 2 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 GUITest/SysInfo.t.c diff --git a/GUITest/SysInfo.t.c b/GUITest/SysInfo.t.c new file mode 100644 index 0000000..51cdddd --- /dev/null +++ b/GUITest/SysInfo.t.c @@ -0,0 +1,165 @@ +#include "c_WinApp.h" +#include +#include +#include + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +#define WINDOW_CLASS_NAME "SysInfo.Main" + +#define KB 1024 +#define MB ((size_t)((size_t)KB*1024)) +#define GB ((size_t)((size_t)MB*1024)) +#define TB ((size_t)((size_t)GB*1024)) + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +static HWND EditWin; + +static LPSTR GetSysInfo(LPSTR s) { + SYSTEM_INFO SystemInfo; + MEMORYSTATUS MStatus; + char Temp1[500]; + char Temp2[500]; + char CR[3]={13, 10, 0}; + GetSystemInfo(&SystemInfo); + snprintf(Temp1, sizeof(Temp1), "%sOEM ID:%ld %s" + "Page Size %ld %s" + "MinAppAddress: %"PRIu64" %s" + "MaxAppAddress: %"PRIu64" %s" + "Active Processor Mask: %"PRIX64" %s" + "Number of Processors: %ld %s" + "Processor Type: %ld %s" + "Allocation Granularity: %ld %s %s", + CR, SystemInfo.dwOemId, CR, + SystemInfo.dwPageSize, CR, + SystemInfo.lpMinimumApplicationAddress, CR, + SystemInfo.lpMaximumApplicationAddress, CR, + SystemInfo.dwActiveProcessorMask, CR, + SystemInfo.dwNumberOfProcessors, CR, + SystemInfo.dwProcessorType, CR, + SystemInfo.dwAllocationGranularity, CR, CR + ); + MStatus.dwLength = sizeof(MStatus); + GlobalMemoryStatus(&MStatus); + snprintf(Temp2, sizeof(Temp2), "%sMemory Load: %ld %s" + "Total Physical: %"PRIu64"GB %s" + "Available Physical: %"PRIu64"GB %s" + "Total Page File: %"PRIu64" %s" + "Available Page File: %"PRIu64" %s" + "Total Virtual: %"PRIu64"TB %s" + "Available Virtual: %"PRIu64"TB", + CR, MStatus.dwMemoryLoad, CR, + MStatus.dwTotalPhys/GB, CR, + MStatus.dwAvailPhys/GB, CR, + MStatus.dwTotalPageFile, CR, + MStatus.dwAvailPageFile, CR, + MStatus.dwTotalVirtual/TB, CR, + MStatus.dwAvailVirtual/TB + ); + strcpy(s, "SYSTEM INFO"); + strcat(s, Temp1); + strcat(s, "MEMORY STATUS"); + strcat(s, Temp2); + return s; +} + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + + +c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) { + PostQuitMessage(0); +} + +c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) { + char s[1000]; + EditWin = CreateWindow("edit", "Original Text", + WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|ES_READONLY|ES_LEFT|ES_AUTOVSCROLL|ES_MULTILINE, + 0, 0, 0, 0, + hwnd, (HMENU)0, lpCreateStruct->hInstance, NULL); + GetSysInfo(s); + SetWindowText(EditWin, s); + return TRUE; +} + +c_WinGUI_EventHandlerDef(WM_SIZE, Main_Size) { + if (EditWin) { + SetWindowPos(EditWin, NULL, 0, 0, cx, cy, SWP_NOZORDER); + } +} + +c_WinGUI_EventMapBegin(WndProc) + c_WinGUI_EventMap(WM_DESTROY, Main_Destroy); + c_WinGUI_EventMap(WM_CREATE, Main_Create); + c_WinGUI_EventMap(WM_SIZE, Main_Size); +c_WinGUI_EventMapEnd() + + +static +BOOL Register(HINSTANCE hInstance) { + WNDCLASS WndClass; + WndClass.style = CS_HREDRAW | CS_VREDRAW; + WndClass.lpfnWndProc = WndProc; + WndClass.cbClsExtra = 0; + WndClass.cbWndExtra = 0; + WndClass.hInstance = hInstance; + WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); + WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + WndClass.lpszMenuName = NULL; + WndClass.lpszClassName = WINDOW_CLASS_NAME; + return RegisterClass(&WndClass); +} + +static +HWND Create(HINSTANCE hInstance, int nCmdShow) { + HWND hwnd = CreateWindow(WINDOW_CLASS_NAME, WINDOW_CLASS_NAME, + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, hInstance, NULL + ); + + if (hwnd == NULL) { + return NULL; + } + + ShowWindow(hwnd, nCmdShow); + UpdateWindow(hwnd); + return hwnd; +} + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +c_WinGUI_Main(){ + MSG msg; + + if (!hPrevInstance) { + if (!Register(hInstance)) { + return FALSE; + } + } + + WinApp.hInstance = hInstance; + + + HWND MainHwnd = Create(hInstance, nShowCmd); + if (!MainHwnd) { + return FALSE; + } + + WinApp.hwnd = MainHwnd; + + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + + return (int)msg.wParam; +} + diff --git a/GUITest/WinStyle.t.c b/GUITest/WinStyle.t.c index 70de396..560abe0 100644 --- a/GUITest/WinStyle.t.c +++ b/GUITest/WinStyle.t.c @@ -52,17 +52,18 @@ static void ArrangeWinds(HWND hwnd) { int i; int j = 0; for (i=0; i<9; i++) { - MoveWindow(ChildWindows[i], 10 + (j* 100), 10, 100, 100, TRUE); + MoveWindow(ChildWindows[i], 10 + (j * 100), 10, 100, 100, TRUE); if (i==4) { j=0; }else { j++; } - GetWindowRect(hwnd, &R); - MoveWindow(ChildWindows[i], R.left + 10 + GetSystemMetrics(SM_CXFRAME) + (j*100), - R.top + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) + 10, - 100, 100, TRUE); } + GetWindowRect(hwnd, &R); + MoveWindow(ChildWindows[i], + R.left + 10 + GetSystemMetrics(SM_CXFRAME) + (j*100), + R.top + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) + 10, + 100, 100, TRUE); } static void HandleBrush(HWND hwnd, int id) {