Windows User Interface API Reference

This section details the Application Programming Interfaces (APIs) for developing and managing the Windows user interface. These APIs enable you to create windows, controls, menus, and handle user interactions.

Core UI Components

Understand the fundamental elements that make up the Windows graphical user interface.

Window Management

CreateWindowExW
Creates an overlapping, top-level window with extended styles.
Parameters:
  • dwExStyle: Extended window styles.
  • lpClassName: Registered class name.
  • lpWindowName: Window title.
  • dwStyle: Window styles.
  • x, y, nWidth, nHeight: Window dimensions and position.
  • hWndParent: Handle to the parent window.
  • hMenu: Handle to a menu.
  • hInstance: Handle to the application instance.
  • lpParam: Creation parameters.
Returns:
  • Handle to the new window, or NULL on failure.
This is a crucial function for creating any window in Windows.

Message Handling

DefWindowProcW
Defers control of message processing to the default window procedure.
Parameters:
  • hWnd: Handle to the window.
  • uMsg: The message to be processed.
  • wParam: Additional message information.
  • lParam: Additional message information.
Returns:
  • The result of the default message processing.

Control Creation

CreateWindowExW (for controls)
Used to create various standard Windows controls like buttons, edit boxes, and list boxes.
Parameters:
  • dwExStyle: Extended window styles for the control.
  • lpClassName: Predefined control class names (e.g., "BUTTON", "EDIT").
  • lpWindowName: Text for the control (e.g., button label).
  • dwStyle: Control styles.
  • x, y, nWidth, nHeight: Control dimensions and position relative to parent.
  • hWndParent: Handle to the parent window.
  • hMenu: Control identifier.
  • hInstance: Handle to the application instance.
  • lpParam: Creation parameters.
Returns:
  • Handle to the created control, or NULL on failure.

Graphics and Drawing

APIs for rendering graphics, text, and images within your application's windows.

Device Contexts

GetDC
Retrieves a handle to a device context (DC) for a client area of a window.
Parameters:
  • hWnd: Handle to the window with the client area.
Returns:
  • Handle to the device context.
Always release the DC using ReleaseDC when you are finished with it.

Drawing Primitives

Rectangle
Draws a rectangle using the specified coordinates and the current pen.
Parameters:
  • hdc: Handle to the device context.
  • X1, Y1: Coordinates of the upper-left corner.
  • X2, Y2: Coordinates of the lower-right corner.
Returns:
  • Nonzero if successful, zero otherwise.

Text Rendering

TextOutW
Writes a string of text at the specified location.
Parameters:
  • hdc: Handle to the device context.
  • X, Y: Coordinates for the start of the string.
  • lpString: Pointer to the string to be drawn.
  • cchString: Number of characters in the string.
Returns:
  • Nonzero if successful, zero otherwise.

User Input and Events

APIs for processing keyboard, mouse, and other input events.

Message Loop

GetMessageW
Retrieves messages from the calling thread's message queue.
Parameters:
  • lpMsg: Pointer to a MSG structure that receives message information.
  • hWnd: Handle to the window whose messages are to be retrieved.
  • wMsgFilterMin, wMsgFilterMax: Values that specify the range of messages to be retrieved.
Returns:
  • If the function retrieves a posted message, the return value is TRUE.
  • If the function retrieves a WM_QUIT message, the return value is FALSE.
  • If any other error occurs, the return value is -1.
A typical application's message loop continuously calls GetMessage until FALSE is returned.

Mouse Input

GetCursorPos
Retrieves the current position of the mouse cursor, in screen coordinates.
Parameters:
  • lpPoint: Pointer to a POINT structure that receives the screen coordinates of the cursor.
Returns:
  • Nonzero if successful, zero otherwise.

Common Controls

APIs for using the rich set of modern Windows common controls.

Button Control

Button_SetCheck
Sets the check state of a button (checked or not checked).
Parameters:
  • hwndButton: Handle to the button.
  • check: The new check state. BST_CHECKED to check, BST_UNCHECKED to uncheck.
Returns:
  • The previous check state.

Edit Control

Edit_GetText
Copies the current text from the specified edit control into a buffer.
Parameters:
  • hwndEdit: Handle to the edit control.
  • lpszString: Pointer to the buffer that will receive the text.
  • cchMax: The maximum number of characters to copy, including the null terminator.
Returns:
  • The number of characters copied, not including the null terminator.