port: MSWindow/MSApplication verbatim over a winuser.h shim (Win32User.cpp)

Host-side window records + message queue; WM_SIZE/WM_MOVE/WM_DESTROY sent
synchronously as Win32 does; PostQuitMessage also queues WM_QUIT. 64-bit
pointer casts ADAPTED. port.ms_window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 13:19:36 +09:00
co-authored by Claude Opus 5.5
parent 80c5a1e39f
commit 5d64311a4d
13 changed files with 1186 additions and 170 deletions
+3
View File
@@ -202,6 +202,9 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
add_executable(port_process_crc_test ${PROJECT_SOURCE_DIR}/tests/port/port_process_crc_test.cpp)
target_link_libraries(port_process_crc_test PRIVATE port_platform)
add_test(NAME port.process_crc COMMAND $<TARGET_FILE:port_process_crc_test>)
add_executable(port_ms_window_test ${PROJECT_SOURCE_DIR}/tests/port/port_ms_window_test.cpp)
target_link_libraries(port_ms_window_test PRIVATE port_platform)
add_test(NAME port.ms_window COMMAND $<TARGET_FILE:port_ms_window_test>)
# MilesLib: the 40250 sound managers over the Miles emulation (platform/MilesLib/MilesAil.cpp).
add_executable(port_miles_test ${PROJECT_SOURCE_DIR}/tests/port/port_miles_test.cpp)
+3 -5
View File
@@ -8,6 +8,7 @@
#include "../../Win32Types.h"
#include "../../Win32Crt.h"
#include "wingdi.h"
#include "winuser.h"
// winuser.h / wingdi.h constants named in 40250 declarations (default arguments).
#define WS_OVERLAPPED 0x00000000L
@@ -39,10 +40,7 @@
inline int GetSystemMetrics(int nIndex)
{
if (nIndex == SM_CXFULLSCREEN) return 1920;
if (nIndex == SM_CYFULLSCREEN) return 1080;
if (nIndex == SM_CXSCREEN || nIndex == SM_CXFULLSCREEN) return 1920;
if (nIndex == SM_CYSCREEN || nIndex == SM_CYFULLSCREEN) return 1080;
return 0;
}
// winuser.h functions the platform layer implements (platform/ScriptLib/PythonBoot.cpp).
void PostQuitMessage(int nExitCode);
+3
View File
@@ -1,2 +1,5 @@
#pragma once
#include <windows.h>
#define GetWindowStyle(hwnd) ((DWORD)GetWindowLong(hwnd, GWL_STYLE))
#define GetWindowExStyle(hwnd) ((DWORD)GetWindowLong(hwnd, GWL_EXSTYLE))
+1
View File
@@ -54,6 +54,7 @@ int SetDIBitsToDevice(HDC hdc, int xDest, int yDest, DWORD w, DWORD h, int xSrc,
HFONT CreateFontIndirect(const LOGFONT* lplf);
BOOL DeleteObject(HGDIOBJ ho);
HGDIOBJ SelectObject(HDC hdc, HGDIOBJ h);
HGDIOBJ GetStockObject(int i); // platform/Win32User.cpp (the window background brush)
COLORREF SetTextColor(HDC hdc, COLORREF color);
COLORREF SetBkColor(HDC hdc, COLORREF color);
int SetBkMode(HDC hdc, int mode);
+107
View File
@@ -0,0 +1,107 @@
#pragma once
// The <winuser.h> window and message-queue subset 40250 EterLib/MSWindow.cpp and MSApplication.cpp call,
// implemented by platform/Win32User.cpp over host-side window records (the host owns the real surface).
// The A/W pairs are declared under their plain names: no 40250 caller spells the A or W form.
#include "../../Win32Types.h"
#include "wingdi.h"
struct HMENU__;
typedef HMENU__* HMENU;
typedef WORD ATOM;
#define WM_CREATE 0x0001
#define WM_DESTROY 0x0002
#define WM_MOVE 0x0003
#define WM_SIZE 0x0005
#define WM_CLOSE 0x0010
#define WM_QUIT 0x0012
#define WM_ACTIVATEAPP 0x001C
#define WA_INACTIVE 0
#define WA_ACTIVE 1
#define WA_CLICKACTIVE 2
#define SIZE_RESTORED 0
#define SIZE_MINIMIZED 1
#define SW_HIDE 0
#define SW_SHOW 5
#define SWP_NOSIZE 0x0001
#define SWP_NOMOVE 0x0002
#define SWP_NOZORDER 0x0004
#define PM_NOREMOVE 0x0000
#define PM_REMOVE 0x0001
#define GWL_STYLE (-16)
#define GWL_EXSTYLE (-20)
#define GWL_USERDATA (-21)
#define GWLP_USERDATA (-21)
#define SM_CXSCREEN 0
#define SM_CYSCREEN 1
#define MAKELPARAM(l, h) ((LPARAM)(DWORD)MAKELONG(l, h))
#define MAKEINTRESOURCE(i) ((LPCSTR)((ULONG_PTR)((WORD)(i))))
#define IDI_APPLICATION MAKEINTRESOURCE(32512)
typedef struct tagMSG
{
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG, *PMSG, *LPMSG;
typedef struct tagWNDCLASS
{
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCSTR lpszMenuName;
LPCSTR lpszClassName;
} WNDCLASS, *PWNDCLASS, *LPWNDCLASS;
ATOM RegisterClass(const WNDCLASS* lpWndClass);
HWND CreateWindow(LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
BOOL DestroyWindow(HWND hWnd);
BOOL IsWindow(HWND hWnd);
LRESULT DefWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
LONG GetWindowLong(HWND hWnd, int nIndex);
LONG SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong);
LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
LONG_PTR SetWindowLongPtr(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
BOOL ShowWindow(HWND hWnd, int nCmdShow);
BOOL SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
BOOL MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint);
BOOL AdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
BOOL GetWindowRect(HWND hWnd, LPRECT lpRect);
BOOL GetClientRect(HWND hWnd, LPRECT lpRect);
BOOL SetWindowText(HWND hWnd, LPCSTR lpString);
BOOL InvalidateRect(HWND hWnd, const RECT* lpRect, BOOL bErase);
HMENU GetMenu(HWND hWnd);
BOOL SetRect(LPRECT lprc, int xLeft, int yTop, int xRight, int yBottom);
BOOL GetCursorPos(LPPOINT lpPoint);
BOOL ScreenToClient(HWND hWnd, LPPOINT lpPoint);
HCURSOR LoadCursor(HINSTANCE hInstance, LPCSTR lpCursorName);
HICON LoadIcon(HINSTANCE hInstance, LPCSTR lpIconName);
BOOL PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
BOOL PeekMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
BOOL GetMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);
BOOL TranslateMessage(const MSG* lpMsg);
LRESULT DispatchMessage(const MSG* lpMsg);
void PostQuitMessage(int nExitCode);