Win32 User Interface API Reference
This section provides documentation for the Windows API functions related to creating and managing the graphical user interface (GUI) for Windows applications.
The Win32 User Interface API encompasses a wide range of functionalities, including window management, message handling, control manipulation, menus, dialog boxes, and more. These APIs are fundamental for developing desktop applications with a rich and interactive user experience.
Key Concepts
- Windows: The basic building blocks of the GUI. Applications create windows to display content and receive user input.
- Messages: A communication mechanism between the operating system and applications, and between different parts of an application.
- Device Context (DC): An information structure that describes drawing attributes, such as the drawing mode, text alignment, background color, and mapping mode.
- GDI (Graphics Device Interface): The subsystem responsible for drawing text and graphics on the screen.
Commonly Used Functions
| Function Name | Description |
|---|---|
CreateWindowEx |
Creates an overlapped, pop-up, or child window. |
DefWindowProc |
Dispatches a message to the default window procedure. |
GetMessage |
Retrieves messages from the calling thread's message queue. |
TranslateMessage |
Translates virtual-key messages into character messages. |
DispatchMessage |
Dispatches a message to a window procedure. |
MessageBox |
Displays a message box with specified text and buttons. |
DialogBox |
Creates a modal dialog box. |
InvalidateRect |
Adds a rectangle to a window's update region. |
UpdateWindow |
Updates a window's client area. |
SetFocus |
Sets the keyboard focus to a specified window. |
CreateWindowEx
Creates an overlapped, pop-up, or child window. This is one of the most fundamental functions for creating windows.
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 text.dwStyle: Window styles.x, y, nWidth, nHeight: Position and dimensions.hWndParent: Handle to the parent window.hMenu: Handle to a menu or child-window identifier.hInstance: Handle to the application instance.lpParam: Application-defined data.
DefWindowProc
Dispatches a message to the default window procedure. This function is typically called by an application's main message loop when it does not handle a particular message.
LRESULT DefWindowProc(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
Parameters:
hWnd: Handle to the window.uMsg: The message to be processed.wParam: Additional message information.lParam: Additional message information.
GetMessage
Retrieves messages from the calling thread's message queue. This is a core part of the message loop.
BOOL GetMessage(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax
);
Parameters:
lpMsg: Pointer to an MSG structure that receives message information.hWnd: Handle to the window whose messages are to be retrieved.wMsgFilterMin, wMsgFilterMax: Values that restrict the range of messages to be retrieved.
MessageBox
Displays a message box that can contain an application-defined icon, set of buttons, and descriptive text. It's a simple way to communicate with the user.
int MessageBox(
HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);
Parameters:
hWnd: Handle to the owner window.lpText: The message to be displayed.lpCaption: The title of the message box.uType: The contents and behavior of the message box.
Refer to the full Win32 API documentation for a comprehensive list of functions and their detailed descriptions.