Window Management API
The Window Management API provides functions for creating, managing, and interacting with windows, dialog boxes, and other UI elements within the Windows operating system.
Core Window Functions
These functions are fundamental for establishing and manipulating windows.
CreateWindowEx
Creates an extended window with a specified class, name, and style.
Parameters:
- dwExStyle: Extended window styles.
- lpClassName: Pointer to a null-terminated string that specifies the window class name.
- lpWindowName: Pointer to a null-terminated string that specifies the name of the window.
- dwStyle: Window styles.
- x: The initial horizontal position of the window.
- y: The initial vertical position of the window.
- nWidth: The width, in device units, of the window.
- nHeight: The height, in device units, of the window.
- hWndParent: Handle to the parent window or owner window of the window being created.
- hMenu: Handle to a menu, or specifies a child-window identifier.
- hInstance: Handle to the instance of the module associated with the window.
- lpParam: Pointer to a value to be passed to the window creation function; the onCreate parameter of the window.
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.
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
);
DestroyWindow
Destroys the specified window. In addition to removing the window from the screen, this function sends WM_DESTROY and WM_NCDESTROY messages to the window to disable it and remove it from the active window and selection user interfaces.
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.
BOOL DestroyWindow(
HWND hWnd
);
ShowWindow
Sets the visibility state of the specified window.
Parameters:
- hWnd: Handle to the window.
- nCmdShow: Controls the way the window is to be shown. This parameter is ignored the first time an application calls
ShowWindow for a window. In this case, the value is the value that was specified by the pCmdLine parameter in the wmain function or the main function called to launch the application. Otherwise, this parameter can be one of the following values:
SW_FORCEMINIMUM
SW_HIDE
SW_INVALIDATE
SW_MAXIMIZE
SW_MINIMIZE
SW_RESTORE
SW_SHOW
SW_SHOWDEFAULT
SW_SHOWMAXIMIZED
SW_SHOWMINIMIZED
SW_SHOWMINNOACTIVE
SW_SHOWNA
SW_SHOWNOACTIVATE
SW_SHOWNORMAL
Return Value:
- If the window was previously visible, the return value is nonzero.
- If the window was previously invisible, the return value is zero.
BOOL ShowWindow(
HWND hWnd,
int nCmdShow
);
Window Properties and Attributes
Functions to query and modify window properties.
GetWindowText
Copies the text of the specified window's title bar (if it has one) into a buffer.
Parameters:
- hWnd: Handle to the window or control.
- lpString: Pointer to the buffer that will receive the text.
- nMaxCount: Maximum number of characters to copy to the buffer, including the null terminator.
Return Value:
- If the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating null character.
- If the window or control has no title bar or text, the return value is zero.
int GetWindowText(
HWND hWnd,
LPSTR lpString,
int nMaxCount
);
SetWindowText
Sets the text of the specified window's title bar (if it has one).
Parameters:
- hWnd: Handle to the window or control with the text to be changed.
- lpString: Pointer to a null-terminated string that contains the new title.
Return Value:
- If the function succeeds, the return value is nonzero.
- If the function fails, the return value is zero.
BOOL SetWindowText(
HWND hWnd,
LPCTSTR lpString
);
Window Hierarchy and Navigation
Functions for managing parent-child relationships and sibling windows.
GetParent
Retrieves a handle to the specified window's parent window, if any.
Parameters:
- hWnd: Handle to the window whose parent window is to be retrieved.
Return Value:
- If the function succeeds, the return value is a handle to the parent window. If the given window is a child window, the return value is a handle to the parent window. If the given window is an edit control, the return value is a handle to the associated dialog box.
- If the function fails, the return value is NULL.
HWND GetParent(
HWND hWnd
);