Win32 UI API Reference
This document provides a reference for the core Windows API functions related to User Interface (UI) development.
User Interface (UI) Functions
The Windows API offers a rich set of functions for creating and managing graphical user interfaces. This section covers key areas of UI development.
Window Management
Functions for creating, managing, and destroying windows.
CreateWindowEx
Creates an overlapping, top-level window. Overlapped windows have a title bar, a border, and usually a client area.
Syntax
HWND CreateWindowEx(
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
Parameters
dwExStyle
: Extended window styles.lpClassName
: Registered class name.lpWindowName
: Window title.dwStyle
: Window styles.x, y, nWidth, nHeight
: Window position and dimensions.hWndParent
: Handle to the parent window.hMenu
: Handle to a menu or child-window identifier.hInstance
: Application instance handle.lpParam
: Application-defined message data.
Returns: The handle to the new window, or NULL
if creation fails.
DestroyWindow
Destroys the specified window. The function sends a WM_DESTROY
message to the window to which it belongs before removing the window from the screen.
Syntax
BOOL DestroyWindow(
HWND hWnd
);
Parameters
hWnd
: Handle to the window to be destroyed.
Returns: TRUE
if successful, FALSE
otherwise.
ShowWindow
Sets the specified window's visual state (hiding or showing it).
Syntax
BOOL ShowWindow(
HWND hWnd,
int nCmdShow
);
Parameters
hWnd
: Handle to the window.nCmdShow
: Controls how the window is to be shown.
Returns: The return value is the value of the previous nCmdShow
member for the window.
Standard Controls
Functions for creating and managing common UI elements like buttons, edit boxes, and list boxes.
CreateWindow
(for controls)
Can be used to create various standard controls by specifying predefined class names.
Example Class Names
"BUTTON"
"EDIT"
"STATIC"
"LISTBOX"
"COMBOBOX"
Refer to CreateWindowEx
for detailed syntax and parameters.
SetDlgItemText
Sets the text of a specified control in a dialog box.
Syntax
BOOL SetDlgItemText(
HWND hDlg,
int nIDDlgItem,
LPCTSTR lpString
);
Parameters
hDlg
: Handle to the dialog box.nIDDlgItem
: Identifier of the control.lpString
: The new text.
Returns: TRUE
if successful, FALSE
otherwise.
GetDlgItemText
Retrieves the text of a specified control in a dialog box.
Syntax
UINT GetDlgItemText(
HWND hDlg,
int nIDDlgItem,
LPTSTR lpString,
int nMaxCount
);
Parameters
hDlg
: Handle to the dialog box.nIDDlgItem
: Identifier of the control.lpString
: Buffer to receive the text.nMaxCount
: Maximum characters to copy.
Returns: The number of characters copied, or 0 if an error occurs.
Graphics & Drawing
Functions for drawing shapes, text, and images on windows.
GetDC
Retrieves a handle to a device context (DC) for the client area of a specified window.
Syntax
HDC GetDC(
HWND hWnd
);
Parameters
hWnd
: Handle to the window.
Returns: A handle to the device context. It is important to call ReleaseDC
when finished.
ReleaseDC
Releases a device context, freeing it for use by other applications.
Syntax
int ReleaseDC(
HWND hWnd,
HDC hDC
);
Parameters
hWnd
: Handle to the window that owns the DC.hDC
: Handle to the DC to be released.
Returns: 1 if the DC was released, 0 otherwise.
TextOut
Writes a string of characters at the specified location on the specified device context.
Syntax
BOOL TextOut(
HDC hdc,
int x,
int y,
LPCTSTR lpString,
int cchString
);
Parameters
hdc
: Handle to the device context.x, y
: Coordinates for the text.lpString
: The string to write.cchString
: Number of characters in the string.
Returns: TRUE
if successful, FALSE
otherwise.
Input Handling
Functions for processing user input like keyboard and mouse events.
Message Loop
Input events are delivered to applications via a message loop. The typical structure involves:
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Specific input messages include WM_KEYDOWN
, WM_KEYUP
, WM_LBUTTONDOWN
, WM_MOUSEMOVE
, etc. These are processed in the window procedure.