User Interface Core APIs
This section provides comprehensive documentation for the core Windows API functions used to create and manage the graphical user interface (GUI) of Windows applications. It covers fundamental concepts like windows, controls, messages, and graphics rendering.
Window Management
Functions for creating, managing, and manipulating windows.
CreateWindowEx
Creates an overlapped, pop-up, or child window. It can specify the extended window style, class, window name, size, position, and parent window.
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 parent or owner window.hMenu: Handle to menu or child-window identifier.hInstance: Handle to application instance.lpParam: Pointer to window creation data.
Return Value:
- If the function succeeds, the return value is a handle to the new window.
- If the function fails, the return value is
NULL.
DestroyWindow
Destroys the specified window. The function sends a WM_DESTROY message to the window to be destroyed after it is removed from the screen.
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.
Controls
APIs for common UI elements like buttons, text boxes, and lists.
Button_ClickEdit_SetTextListView_InsertItemComboBox_AddString
Graphics and Drawing
Functions for rendering graphics, drawing shapes, and managing device contexts.
GetDC
Retrieves a handle to a Device Context (DC) for the client area of a specified window.
Parameters:
hWnd: Handle to the window with a client area that the specified device context will represent.
Return Value:
- A handle to the device context.
NULLif the request fails.
ReleaseDC
Releases a device context (DC), freeing it for use by other applications.
Parameters:
hWnd: Handle to the window whose DC is to be released.hDC: Handle to the device context to be released.
Return Value:
1if the DC was released.0if the DC was not released.
Input Handling
APIs for processing keyboard and mouse input.
GetMessageTranslateMessageDispatchMessageSetFocus
Menus and Dialogs
Functions for creating and managing application menus and dialog boxes.
DialogBoxParam
Creates a modal dialog box from a dialog box template defined in a resource file.
Parameters:
hInstance: Handle to the module that contains the dialog box template.lpTemplateName: Pointer to a null-terminated string that specifies the resource name of the dialog box template.hWndParent: Handle to the owner window.lpDialogFunc: Pointer to the dialog box procedure.dwInitParam: Value the dialog box procedure can use to initialize the dialog box.
Return Value:
- The return value is the value passed to
SetWindowLongPtrusing theDWLP_MSGRESULTindex to set the dialog box's message-processing result. - If the template specified is not found, or if there is not enough memory to create the dialog box, or if the template is invalid, the return value is -1.
Window Messages
Understanding and handling Windows messages.
The core of Windows GUI programming involves message loops and message handling. Applications receive messages from the system and other applications, which are then dispatched to the appropriate windows.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// Paint content here
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}