Windows User32 declarations for windows, classes, messages, monitors, placement, cursor and capture control, device contexts, and pointer-sized values.
Known issue: with -32bits, importing windows/user32 fails to compile at the GetWindowLongPtrW and SetWindowLongPtrW aliases, so this module and windows/gdi32, windows/opengl32, and windows/shell32, which import it, are unavailable for 32-bit targets.
Schemas
WNDPROC
(-- WNDPROC) Defines a window-procedure callback schema.codeRef schema
| Field | Schema | Role |
|---|---|---|
hwnd | HWND | target window handle |
uMsg | Nat32 | message identifier |
wParam | Natx | pointer-sized message parameter |
lParam | Intx | pointer-sized message parameter |
- Callback stack effect:
(lParam wParam uMsg hwnd -- result);result:Intxmessage-processing result.
HGLRC
(-- HGLRC) Defines a typed OpenGL rendering-context handle.Cref schema for a Dict-shaped opaque handle
Dict schema
MSG
(-- MSG) Defines a queued window message.Dict schema
| Field | Schema | Role |
|---|---|---|
hwnd | HWND | window associated with the message |
message | Nat32 | message identifier |
wParam | Natx | pointer-sized message parameter |
lParam | Intx | pointer-sized message parameter |
time | Nat32 | posting time in milliseconds since the system started |
pt | POINT | cursor position in screen coordinates when the message was posted |
POINT
(-- POINT) Defines a two-dimensional coordinate.Dict schema
RECT
(-- RECT) Defines a rectangular coordinate range.Dict schema
WINDOWPLACEMENT
(-- WINDOWPLACEMENT) Defines a window placement record.Dict schema
| Field | Schema | Role |
|---|---|---|
length | Nat32 | native structure size in bytes |
flags | Nat32 | placement flags |
showCmd | Nat32 | show-state command |
ptMinPosition | POINT | minimized position |
ptMaxPosition | POINT | maximized position |
rcNormalPosition | RECT | normal window rectangle |
rcDevice | RECT | device rectangle |
ptMinPosition,ptMaxPosition, andrcNormalPositionare in workspace coordinates for a top-level window without theWS_EX_TOOLWINDOWextended style, and in screen coordinates otherwise.
Known issue: this binding includes rcDevice, which the Windows layout lacks, so the record occupies 60 bytes instead of the native 44; GetWindowPlacement and SetWindowPlacement fail unless length is set to 44n32.
WNDCLASSW
(-- WNDCLASSW) Defines a wide-character window-class description.Dict schema
| Field | Schema | Role |
|---|---|---|
style | Nat32 | class style flags |
lpfnWndProc | WNDPROC | window-procedure callback |
cbClsExtra | Int32 | extra class bytes |
cbWndExtra | Int32 | extra window bytes |
hInstance | HINSTANCE | module instance handle |
hIcon | HICON | class icon handle |
hCursor | HCURSOR | class cursor handle |
hbrBackground | HBRUSH | class background brush handle |
lpszMenuName | Natx | zero-terminated UTF-16 menu-resource-name address, encoded menu identifier, or 0nx |
lpszClassName | Natx | zero-terminated UTF-16 class-name address or registered-class atom |
Imported functions
Stack effects list a C function's parameters with the first parameter on top; see importFunction.
ClientToScreen
(lpPoint hWnd -- result) Converts a client-area point to screen coordinates.Inputs
lpPoint:POINTRefcaller-owned writable point storage; the call updates it.hWnd:HWNDwindow whose client area contains the point.
Outputs
result:Int32nonzeroon success,0on failure.
CreateWindowExW
(lpParam hInstance hMenu hWndParent nHeight nWidth Y X dwStyle lpWindowName lpClassName dwExStyle -- result) Creates an overlapped, pop-up, or child window.Inputs
lpParam:Natxaddress of creation data, or0nxfor none.hInstance:HINSTANCEmodule instance associated with the window class.hMenu:HMENUmenu handle or child-window identifier.hWndParent:HWNDparent or owner window handle.nHeight:Int32window height.nWidth:Int32window width.Y:Int32initial vertical position.X:Int32initial horizontal position.dwStyle:Nat32window style flags.lpWindowName:Natxaddress of the zero-terminated UTF-16 window-name string.lpClassName:Natxaddress of a zero-terminated UTF-16 class-name string, or a registered-class atom in the low-order 16 bits with all other bits zero.dwExStyle:Nat32extended window style flags.
Outputs
result:HWNDcreated window handle, orNILon failure.
DefWindowProcW
(lParam wParam Msg hWnd -- result) Provides default processing for a window message.Inputs
lParam:Intxpointer-sized message parameter.wParam:Natxpointer-sized message parameter.Msg:Nat32message identifier.hWnd:HWNDwindow handle receiving the message.
Outputs
result:Intxdefault message-processing result.
DestroyWindow
(hWnd -- result) Destroys a window.Inputs
hWnd:HWNDwindow handle to destroy.
Outputs
result:Int32nonzeroon success,0on failure.
DispatchMessageW
(lpMsg -- result) Dispatches a message to its window procedure.Inputs
Outputs
result:Intxvalue returned by the window procedure.
GetDC
(hWnd -- result) Retrieves a device context for a window.Inputs
Outputs
result:HDCdevice-context handle, orNILon failure.
Remarks
- A common device context requires the Windows ReleaseDC function on the acquiring thread; this module provides no ReleaseDC binding.
GetMonitorInfoW
(lpmi hMonitor -- result) Retrieves information about a display monitor.Inputs
lpmi:MONITORINFORefcaller-owned writable monitor-information storage withcbSizeset to its size; the call fills it.hMonitor:HMONITORmonitor handle.
Outputs
result:Int32nonzeroon success,0on failure.
GetWindowLongPtrW
(nIndex hWnd -- result) Retrieves a pointer-sized value from a window.Inputs
Outputs
result:Intxrequested window value, or0ixon failure;0ixcan also be a valid value.
Remarks
- When the
Natxdoes not occupy 8 bytes,GetWindowLongPtrWaliasesGetWindowLongW.
GetWindowLongW
(nIndex hWnd -- result) Retrieves a value from a window.Inputs
Outputs
result:Intxrequested window value, or0ixon failure;0ixcan also be a valid value.
Remarks
GetWindowLongWis available only when theNatxdoes not occupy 8 bytes;GetWindowLongPtrWaliases it.
GetWindowPlacement
(lpwndpl hWnd -- result) Retrieves a window placement record.Inputs
lpwndpl:WINDOWPLACEMENTRefcaller-owned writable placement storage withlengthset to44n32; the call fills it.hWnd:HWNDwindow handle.
Outputs
result:Int32nonzeroon success,0on failure.
LoadCursorW
(lpCursorName hInstance -- result) Loads a cursor.Inputs
lpCursorName:Natxaddress of a zero-terminated UTF-16 cursor-name string, or a cursor resource identifier in the low-order 16 bits with all other bits zero.hInstance:HINSTANCEmodule instance handle, or aNILHINSTANCEfor a system cursor.
Outputs
result:HCURSORcursor handle, orNILon failure.
MonitorFromWindow
(dwFlags hwnd -- result) Retrieves the display monitor associated with a window.Inputs
Outputs
result:HMONITORmonitor handle, orNILonly when the window intersects no monitor anddwFlagsis0n32.
PeekMessageW
(wRemoveMsg wMsgFilterMax wMsgFilterMin hWnd lpMsg -- result) Retrieves a message without waiting for one.Inputs
wRemoveMsg:Nat32message-removal flags.wMsgFilterMax:Nat32maximum message value in the filter range.wMsgFilterMin:Nat32minimum message value in the filter range.hWnd:HWNDwindow filter handle, or aNILHWNDfor no window filter.lpMsg:MSGRefcaller-owned writable message storage; the call fills it.
Outputs
result:Int32nonzerowhen a message is retrieved,0when none is available.
RegisterClassW
(lpWndClass -- result) Registers a window class.Inputs
Outputs
result:Nat16atom identifying the registered class, or0n16on failure.
ReleaseCapture
(-- result) Releases mouse capture from the current window.Inputs
- None.
Outputs
result:Int32nonzeroon success,0on failure.
SetCapture
(hWnd -- result) Sets mouse capture to a window.Inputs
hWnd:HWNDwindow handle to receive mouse input.
Outputs
result:HWNDprevious capture window handle, orNILif none.
SetCursorPos
(Y X -- result) Moves the cursor to a screen coordinate.Inputs
Outputs
result:Int32nonzeroon success,0on failure.
SetWindowLongPtrW
(dwNewLong nIndex hWnd -- result) Sets a pointer-sized value in a window.Inputs
dwNewLong:Intxnew pointer-sized window value.nIndex:Int32window-value index.hWnd:HWNDwindow handle.
Outputs
result:Intxprevious window value, or0ixon failure;0ixcan also be a valid previous value.
Remarks
- When the
Natxdoes not occupy 8 bytes,SetWindowLongPtrWaliasesSetWindowLongW. - Clear the thread's last-error code with the Windows SetLastError function before the call; a zero result indicates failure only if
GetLastErrorthen returns a nonzero code.
SetWindowLongW
(dwNewLong nIndex hWnd -- result) Sets a value in a window.Inputs
Outputs
result:Intxprevious window value, or0ixon failure;0ixcan also be a valid previous value.
Remarks
SetWindowLongWis available only when theNatxdoes not occupy 8 bytes;SetWindowLongPtrWaliases it.
SetWindowPlacement
(lpwndpl hWnd -- result) Sets a window placement record.Inputs
lpwndpl:WINDOWPLACEMENTCrefborrowed placement record withlengthset to44n32.hWnd:HWNDwindow handle.
Outputs
result:Int32nonzeroon success,0on failure.
SetWindowPos
(uFlags cy cx Y X hWndInsertAfter hWnd -- result) Changes a window position, size, or z-order.Inputs
uFlags:Nat32positioning flags.cy:Int32new window height.cx:Int32new window width.Y:Int32new vertical position.X:Int32new horizontal position.hWndInsertAfter:HWNDz-order placement window handle.hWnd:HWNDwindow handle to position.
Outputs
result:Int32nonzeroon success,0on failure.
ShowCursor
(bShow -- result) Changes the cursor display counter.Inputs
bShow:Int32nonzero to increment the display counter, or0to decrement it.
Outputs
result:Int32new cursor display-counter value.
Remarks
- The cursor is displayed only when the counter is nonnegative.
ShowWindow
(nCmdShow hWnd -- result) Sets a window show state.Inputs
Outputs
result:Int32nonzeroif the window was previously visible,0if it was previously hidden.
TranslateMessage
(lpMsg -- result) Translates a virtual-key message.Inputs
Outputs
result:Int32nonzeroforWM_KEYDOWN,WM_KEYUP,WM_SYSKEYDOWN, orWM_SYSKEYUP, regardless of whether a character message is posted;0otherwise.
Signature examples
Printing imported names during compilation shows the exact imported signatures.
"control" use
"windows/user32" use
{} Int32 {} [
@CreateWindowExW printStack _:;
@GetWindowLongPtrW printStack _:;
@GetDC printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
{dwExStyle: Nat32; lpClassName: Natx; lpWindowName: Natx; dwStyle: Nat32; X: Int32; Y: Int32; nWidth: Int32; nHeight: Int32; hWndParent: {WND: (); unused: Int32;} Cref; hMenu: {MENU: (); unused: Int32;} Cref; hInstance: {INSTANCE: (); unused: Int32;} Cref; lpParam: Natx;} {WND: (); unused: Int32;} Cref {convention: "";} codeRef
{hWnd: {WND: (); unused: Int32;} Cref; nIndex: Int32;} Intx {convention: "";} codeRef
{hWnd: {WND: (); unused: Int32;} Cref;} {DC: (); unused: Int32;} Cref {convention: "";} codeRef
See also
- windows/kernel32: Kernel32 declarations for synchronization, process, thread, file, and timing helpers.
- windows/gdi32: GDI32 pixel-format and buffer-swap declarations.
- windows/opengl32: OpenGL32 WGL context declarations.
- windows/shell32: Shell folder path declarations.
- windows/unicode: UTF-8 to zero-terminated UTF-16 conversion helper.