Windows and Messages
This section provides detailed information about the core Windows messaging system, including window creation, message handling, and communication between windows. Understanding these concepts is fundamental to developing Windows applications.
Core Concepts
- Window Procedures (WndProc): The callback function that receives and processes messages sent to a window.
- Messages: Notifications sent by the system or other applications to windows, indicating events or requests.
- Message Loops: The mechanism by which an application retrieves and dispatches messages to appropriate windows.
- Window Styles: Attributes that define the appearance and behavior of a window.
Key Functions and Structures
| Name | Description |
|---|---|
CreateWindowEx |
Creates an overlapped, pop-up, or child window. |
DefWindowProc |
Processes Windows messages that the application does not explicitly process. |
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. |
MSG |
Contains message information from a thread's message queue. |
WNDCLASS |
Defines the window class attributes. |
Message Categories
Messages are broadly categorized into several types:
- Input Messages: For keyboard and mouse input (e.g.,
WM_KEYDOWN,WM_LBUTTONDOWN). - System Messages: For window management and system events (e.g.,
WM_CREATE,WM_DESTROY,WM_SIZE). - Command Messages: Sent by controls to their parent windows (e.g.,
WM_COMMAND). - Notification Messages: Used by child controls to notify parent windows of events.
- Paint Messages: For updating the window's display (e.g.,
WM_PAINT).