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:

Common Control Categories

The Win32 API organizes controls into several categories:

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.