Win32 GDI and USER32 Desktop API
What is it?
This roadmap plans the first Win32 drawing and windowing APIs: GDI device contexts and bitmaps, drawing and text calls, CreateWindowExA and friends, a message loop with GetMessageA, cursors, icons and system metrics, and the standard dialogs, all built as thin wrappers over the kernel's existing graphics and window manager. Each export is tracked in the USER32 export master table. None of its eight sections has shipped, and no GDI or USER32 function exists yet.
How does it work?
Today. Nothing of the GDI or USER32 layer exists, but everything it plans to wrap does:
- Drawing.
gfx.hprovides surfaces, rectangles, rounded rectangles, circles, lines, blits and alpha blits, described in 2D Graphics and Visual Assets. Text comes from the TrueType font manager. - Windows.
wm.hcreates, moves, resizes, raises, focuses and destroys windows. A window has no message queue or window procedure; input reaches it through the window manager's own callbacks. Minimize and maximize are planned in the window manager roadmap. - Cursors and icons.
cursor.hhas the arrow, hand, text, move, resize, wait, crosshair and forbidden shapes, andicon_store.hhas 70 system icons (ICON_TOTAL_COUNT) plusicon_for_extension(). - Loading Win32 programs. The PE loader in
pe.cresolves imports only fromkernel32.dll(14 exports) andntdll.dll; a program that importsuser32.dllorgdi32.dllcannot load. The user-modewin32.his a small test shim, not GDI or USER32.
Planned design.
- Shell icon map: Windows shell and
IDI_*icon indexes mapped onto the system icons. - Device contexts:
HDCandHBITMAPhandles in a 256-slot table,GetDC,CreateCompatibleDC,SelectObject. - Drawing:
BitBlt,Rectangle,Ellipse,LineToand friends overgfx_*. - Text:
TextOutA,DrawTextAandCreateFontAover the font manager. - Windows:
CreateWindowExA,ShowWindow,DestroyWindowoverwm_*. - Message loop: a per-window kernel queue with blocking
GetMessageA,DispatchMessageAandDefWindowProcA. - Cursors, icons, metrics:
LoadCursorA,LoadIconA,GetSystemMetrics. - Dialogs:
MessageBoxA,GetOpenFileNameAandChooseColorAforwarded to the dialog library.
flowchart LR
APP[Win32 program] --> U32[USER32: windows, messages]
APP --> GDI[GDI: DC, drawing, text]
U32 --> WM[wm_* window manager]
GDI --> GFX[gfx_* + font manager]
U32 --> DLG[dialog library]
U32 -.syscalls, later.-> SH[Win32k shadow SSDT]
What are its interfaces?
| Interface | Status |
|---|---|
gfx_fill_rect(), gfx_draw_line(), gfx_blit(), gfx_blit_alpha(), ttf_draw_string() |
Shipped (wrapped primitives) |
wm_create_window(), wm_move_window(), wm_resize_window(), wm_focus_window(), wm_get_focused_window() |
Shipped (wrapped primitives) |
cursor_set_shape(), icon_get(), icon_for_extension() |
Shipped (wrapped primitives) |
GetDC(), CreateCompatibleDC(), SelectObject(), BitBlt(), TextOutA(), CreateFontA() |
Planned, sections 2 to 4 |
CreateWindowExA(), ShowWindow(), GetMessageA(), DispatchMessageA(), RegisterClassA() |
Planned, sections 5 and 6 |
LoadCursorA(), GetSystemMetrics(), MessageBoxA(), GetOpenFileNameA() |
Planned, sections 7 and 8 |
How do I use it?
Nothing is callable yet. The primitives these calls will wrap are covered by bash scripts/test.sh SUITE=desktop.
What is not implemented yet?
- Win32 Shell Icon Index Map.
- GDI Device Context Stubs, GDI Drawing Functions and GDI Text Functions.
- USER32 Window Functions and USER32 Message Loop.
- USER32 Cursor, Icon & System Metrics and USER32 Dialogs.
- The kernel side of these calls, the
NtGdiandNtUsersystem calls, is the Win32k Shadow SSDT.
How does it compare with Windows 11 and Linux?
Windows 11 implements GDI, USER32 and the common dialogs in user-mode DLLs that call into win32k.sys, with one message queue per thread. Linux has no Win32 layer of its own: native programs draw with Xlib, Cairo or GTK, and Win32 programs run through Wine's reimplementation. The plan wraps the kernel's own graphics and window manager, and gives each window its own queue instead of each thread.