Window Management Functions
The Win32 API provides a rich set of functions for managing windows, user interface elements, and handling user input. This section covers core functionalities for creating, manipulating, and interacting with windows.
Core Window Functions
Function | Description |
---|---|
CreateWindowEx | Creates an overlapped, pop-up, or child window with a wide style. |
DestroyWindow | Destroys the specified window. The DestroyWindow function posts a WM_DESTROY message to the window to which the specified handle identifies. |
ShowWindow | Sets the show state of a window. |
UpdateWindow | Updates the client area of a window that has been interrupted. |
GetMessage | Retrieves messages from the calling thread's message queue. |
DispatchMessage | Dispatches a message to a window procedure. |
CreateWindowEx
Syntax
HWND CreateWindowExA(
DWORD dwExStyle,
LPCSTR lpClassName,
LPCSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
Creates an overlapped, pop-up, or child window with a wide style.
Parameters
dwExStyle
: Extended window styles.lpClassName
: The registered class name.lpWindowName
: The window name.dwStyle
: Window styles.X
: The initial position of the window.Y
: The initial position of the window.nWidth
: The width of the window.nHeight
: The height of the window.hWndParent
: Handle to the parent window.hMenu
: Handle to a menu, or a child-window identifier.hInstance
: Handle to the application instance.lpParam
: Pointer to values for object creation.
Return Value
- If the function succeeds, the return value is a handle to the newly created window.
- If the function fails, the return value is NULL.
DestroyWindow
Syntax
BOOL DestroyWindow(
HWND hWnd
);
Destroys the specified window. The DestroyWindow function posts a WM_DESTROY message to the window to which the specified handle identifies.
Parameters
hWnd
: Handle to the window to be destroyed.
Return Value
- If the function succeeds, the return value is nonzero.
- If the function fails, the return value is zero.
ShowWindow
Syntax
BOOL ShowWindow(
HWND hWnd,
int nCmdShow
);
Sets the show state of a window.
Parameters
hWnd
: Handle to the window.nCmdShow
: Controls the way the window is to be shown.
Return Value
- If the window was previously visible, the return value is nonzero.
- If the window was previously invisible, the return value is zero.
UpdateWindow
Syntax
BOOL UpdateWindow(
HWND hWnd
);
Updates the client area of a window that has been interrupted.
Parameters
hWnd
: Handle to the window to be updated.
Return Value
- If the function succeeds, the return value is nonzero.
- If the function fails, the return value is zero.
GetMessage
Syntax
BOOL GetMessageA(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax
);
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
: Minimum message value.wMsgFilterMax
: Maximum message value.
Return Value
- If the function retrieves a message other than WM_QUIT, the return value is nonzero.
- If the function retrieves the WM_QUIT message, the return value is zero.
- If there is an error, the return value is -1.
DispatchMessage
Syntax
LRESULT DispatchMessageA(
const MSG *lpMsg
);
Dispatches a message to a window procedure.
Parameters
lpMsg
: Pointer to a structure that contains the message to be dispatched.
Return Value
- The return value is the result of the message processing and depends on the message sent.