Windows UI Controls API Reference
This section provides comprehensive documentation for the Windows API functions, structures, and constants used for creating and managing user interface controls in Windows applications.
Introduction to Win32 Controls
Win32 controls are fundamental building blocks of the graphical user interface (GUI) in Windows. They are reusable components that allow users to interact with an application. Common examples include buttons, edit boxes, list boxes, scroll bars, and more.
The Win32 API offers a rich set of functions to:
- Create and display controls.
- Handle user input and messages from controls.
- Modify control properties.
- Manage the layout and appearance of controls.
Common Control Categories
The Win32 API organizes controls into several categories:
-
Standard Controls: Basic controls available in all versions of Windows.
- Buttons (
Button) - Edit Controls (
Edit) - Static Controls (
Static) - List Boxes (
ListBox) - Combo Boxes (
ComboBox) - Scroll Bars (
ScrollBar)
- Buttons (
-
Common Controls: More advanced controls introduced in Windows 95 and later, often requiring the Common Control Libraries to be initialized.
- Command Links (
SysCommandLink) - Date and Time Pickers (
DateTimePicker) - Hot Key Controls (
HotKey) - Header Controls (
Header) - IP Address Controls (
IPAddress) - List View Controls (
ListView) - Month Calendar Controls (
MonthCal) - Progress Bars (
ProgressBar) - Rebar Controls (
Rebar) - Status Bars (
StatusBar) - Tab Controls (
TabControl) - Tooltips (
ToolTip) - Trackbar Controls (
TrackBar) - Tree View Controls (
TreeView) - Windows Explorer Controls (
ExplorerBar)
- Command Links (
Key API Functions for Controls
Creating Controls
Most controls are created using the CreateWindowEx function, specifying a unique window class name for each control type.
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
);
Example for creating a button:
HWND hButton = CreateWindowEx(
0,
TEXT("BUTTON"),
TEXT("Click Me"),
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10, 10, 100, 30,
hwndParent,
(HMENU)101,
hInstance,
NULL
);
Sending Messages to Controls
Interaction with controls is primarily done through Windows messages sent using the SendMessage or PostMessage functions. Each control type responds to a specific set of messages.
LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
Example for setting text in an edit control:
SendMessage(hEditControl, WM_SETTEXT, 0, (LPARAM)TEXT("Initial Text"));
Example for getting selection from a combo box:
int selectedIndex = SendMessage(hComboBox, CB_GETCURSEL, 0, 0);
Control Styles
Controls support various styles that modify their appearance and behavior. These are specified using bitwise OR operations as part of the dwStyle parameter in CreateWindowEx.
Common styles include:
WS_CHILD: Creates a child window.WS_VISIBLE: Makes the window visible.WS_DISABLED: Disables the window.WS_TABSTOP: Allows the control to receive focus via the TAB key.BS_PUSHBUTTON: A standard push button.ES_MULTILINE: Enables multiline text input for edit controls.CBS_DROPDOWN: Creates a drop-down combo box.
Reference Links
Further Reading
Explore the specific API documentation for each control type to understand its unique messages, styles, and functionalities.