Home | API | MFC | C++ | C | Previous | Next

Programming Windows API

Common Controls

In addition to standard controls, Windows offer an extended set of child controls known as common controls. Like standard controls, a common control is a child window that an application uses to enable interaction with the user. In order to use these common controls, an application must include the header file commctrl.h and call the function InitCommonControlsEx() function to ensure that the appropriate components are loaded and initialised. This is necessary because common controls are not referenced in the standard windows header files.

The prototype for the InitCommonControlsEx() API function is

BOOL InitCommonControlsEx (INITCOMMONCONTROLSEX const *picce);

Where *picce is a pointer to an INITCOMMONCONTROLSEX structure that determines which control classes will be registered.

The function will return TRUE if successful, or FALSE otherwise.

The prototype of theINITCOMMONCONTROLSEX structure is

typedef struct tagINITCOMMONCONTROLSEX {DWORD dwSize;DWORD dwICC;} INITCOMMONCONTROLSEX, *LPINITCOMMONCONTROLSEX;

where
dwSize indicates the size of the structure, in bytes
wICC indicates which common control classes will be loaded from the DLL.

Common Controls List

Animation Control

The Animation control allows the creation of a window that displays AVI clips. Animation controls can only display AVI clips that do not contain audio. One common use for animation control is to indicate system activity during a lengthy operation. An example of this type of operation is the “flying folders” file copy progress bar in Windows XP when pieces of paper “fly” from one folder to another while the copy operation executes. An application can send messages to an animation control to open, play, stop, and close the AVI clip.

To create an Animation control specify ANIMATE_CLASS as the window class or use the API function Animate_Create. To register the class set the ICC_ANIMATE_CLASS flag for the dwICC member of the INITCOMMONCONTROLSEX structure.

For further reading – https://docs.microsoft.com/en-us/windows/win32/controls/animation-control-reference

The following example demonstrates the flying folder avi animation

Display Code
Download Code


ComboBoxEx Control

A ComboBoxEx control is an extension of the combobox control and provides native support for list item images. To use item images, an image list is created and assigned to the control using the CBEM_SETIMAGELIST message. ComboBoxEx controls support up to three images for an item: one for its selected state, one for its nonselected state, and one for an overlay image.

To create a ComboBoxEx control specify WC_COMBOBOXEX as the window class and to register the class set the ICC_USEREX_CLASSES flag for the dwICC member of the INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/comboboxex-control-reference

The following example creates a comboboxex control with 5 items. Each item has an associated bitmap image. Changing the selected item copies the text and icon to a static control.

Display Code
Download Code


Date and Time Picker

A date and time picker (DTP) control provides a graphical interface through which to exchange date and time information with a user. The date can be selected from a calendar, or by using up-down keys; the time can be changed by typing in fields that are defined by the control’s Format Strings.

Date and time picker (DTP) controls have several styles that determine a control’s appearance and behavior using the CreateWindowEx dwStyle parameter.  A date and time picker (DTP) control sends notification messages when it receives user input  .The parent of the control receives these notification messages in the form of WM_NOTIFY messages. The lParam contains a pointer to an NMHDR structure that contains the notification code and additional information.

To create a DTP control call specify DATETIMEPICK_CLASS as the window class and register the class by specifying the ICC_DATE_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/date-and-time-picker-control-reference

The following short program demonstrates the date-picker control. Changing either the date or time causes the static box to be updated with the selected date and time.

Display Code
Download Code


Header Control

A header control is a horizontal window used to provide resizable column headings for columns of data. It can be divided into title sections that correspond to each column below it. The header control is extremely useful for listboxes, views, and user-defined list-type windows. By default the header control contains only a label and dividers however including the HDS_BUTTON parameter will make the header a push button.

To create a header control call specify WC_HEADER as the window class and register the class by specifying the ICC_LISTVIEW_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

If an event occurs in the header control, the WM_NOTIFY message is sent to the parent window. The lParam contains a pointer to an NMHDR structure that contains the notification code and additional information.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/header-control-reference

The following short program creates a simple window with a 2 header controls . CLicking either will trigger a message box.

Display Code
Download Code


Listview

A list-view control is a window that displays a collection of items. Listviews can display items in several modes with additional information displayed in columns to the right of the item. The ListView control is similar to the ListBox control except that it can display its items in many different forms, along with any number of sub items for each item.

To create a Listview control specify WC_LISTVIEW as the window class and register the class by specifying the WC_LISTVIEW bit flag in the accompanying INITCOMMONCONTROLSEX structure.

To create and manipulate columns use the LVCOLUMN structure and to specify the item attributes use the LVITEM structure. The Listview details view describes the way in which an item and its sub items are displayed in a grid with column headers. To display items in a details view, first set up the appropriate columns. The first column corresponds to the item’s caption, and the following columns correspond to its sub items. Without the first column, no items will be displayed in the remaining columns.

If an event occurs in the listview control, the WM_NOTIFY message is sent to the parent window. The lParam contains a pointer to an NMHDR structure that contains the notification code and additional information.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/list-view-control-reference

The following example creates a simple listview with 4 items. Changing the selected value will copy the contents of the first column into the static box

Display Code
Download Code


Month Calender Control

The month calendar control provides the user with an intuitive method of entering or selecting a date. The title bar of the control displays two buttons that allow the user to select the previous /next month.

To create a month calendar control specify MONTHCAL_CLASSW as the window class and register the class by specifying the ICC_DATE_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

If an event occurs in the month calendar control, the WM_NOTIFY message is sent to the parent window. The lParam contains a pointer to an NMHDR structure that contains the notification code and additional information.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/month-calendar-control-reference

The following example creates a simple calendar control. Changing the date updates the static box

Display Code
Download Code


Pager Control

A pager control is a window container used within a window that does not have enough display area to show all the child window content. The pager control allows the user to scroll to the area of the window that is not currently in view.

To create a pager control specify WC_PAGESCROLLER as the window class and register the class by specifying the ICC_PAGESCROLLER_CLASS bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/pager-control-reference

In the following example a page controller is used enclose the tool bar.

Display Code
Download Code


Progress Bar

A progress bar is a control that an application can use to indicate the progress of a lengthy operation. It consists of an animated rectangle indicating the operation progression.

To create a progress bar control specify PROGRESS_CLASS as the window class and register the class by specifying the ICC_PROGRESS_CLASS bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/create-progress-bar-controls

In the following example, a timer function is used to increment a progress bar control.

Display Code
Download Code


Property Sheets

A property sheet is a modeless dialog box used for displaying and editing the properties of an object. A property sheet will consist of one or more pages. Each page will be associated with a selectable tab. When a property sheet needs to communicate with a page it does so by sending a WM_NOTIFY message. The lParam parameter is the address of an NMHDR structure that includes the window handle to the property sheet dialog box.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/property-sheet-reference

The following short program displays a property sheet that contains 2 pages when the user right mouse clicks. The first page responds to a radio button click by displaying an associated message box. The 2nd page is for display purposes only. Although this simple demonstration does not set any real properties it does demonstrate the steps involved in creating a property page.

Display Code
Download Code

Creating a Wizard

A property sheet can also be used to create a wizard. A wizard consists of a set of dialog boxes and is used to guide a user through a set of selections in sequence. To create a wizard the PROPSHEETHEADER dwflas field must be set to one of the following values PSH_WIZARD97, PSH_WIZARD, PSH_WIZARD_LITE & PSH_WIZARD | PSH_AEROWIZARD. Setting one of these values means the dialog boxes will automatically form a first to last sequence.

The following short program displays a simple wizard that contains 3 property pages. Right clicking anywhere in the window initiates the wizard.

Display Code
Download Code


Rebar Control

A rebar control acts as a container for child windows. A rebar control contains one or more bands. Each band can contain one child window. The rebar control allows the resizing and repositioning of child windows assigned to its bands. Each rebar band can contain any combination of a gripper bar, a bitmap, a text label, and a child window.

To create a rebar bar control specify REBARCLASSNAME as the window class and register the class by specifying the ICC_COOL_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/rebar-controls

The following example demonstrates the rebar control acting as a container for both a button and a textbox.

Display Code
Download Code


Rich Edit Control

Rich edit controls provide a user interface for entering formatted text. This formatted text can display text with various character formats, show paragraphs with different alignments, and include embedded objects.

To create a rebar bar control specify STATUSCLASSNAME as the window class and register the class by specifying the ICC_COOL_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure. In addition the application will also need to include the header file richedit.h and link to the library Riched20.dll.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/rich-edit-controls

The following example is a simple rich text box offering italic bold and underline formatting options

Display Code
Download Code


Status Bar

Is a Horizontal window typically displayed at the bottom of an application window that is used to display information about the current application. Status bars are often divided into parts, called panes with each pane displaying different status information. Status bars can also contain objects of different types, including buttons and progress bars. The window class name for a status bar control is STATUSCLASSNAME.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/tab-control-reference

The following example demonstrates a simple status bar with 3 cells

Display Code
Download Code


SysLink Control

The control provides a convenient way to embed hypertext links in a window. To create a syslink control specify WC_LINK as the window class and register the class by specifying the ICC_LINK_CLASS bit flag in the accompanying INITCOMMONCONTROLSEX structure.For further reading https://docs.microsoft.com/en-us/windows/win32/controls/syslink-overview

The following example displays a simple window with clickable syslink.

Display Code
Download Code


Tab Control

A tab control is a window that allows an application to display multiple dialog tabs on a single form. By using a tab control, an application can fit multiple pages into the same area of a window or dialog box.

When a tab control is activated by a user, a WM_NOTIFY message is sent to the parent window. TCN_SELCHANGE is sent after a new tab is selected and TCN_SELCHANGING is sent when a tab is about to change. The lParam contains a pointer to an NMHDR structure that contains the notification code and additional information.

To create a Tab control specify WC_TABCONTROL as the window class and register the class by specifying the ICC_TAB_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/tab-control-reference

The following example displays a simple tab control window that allows the user to add delete and clear multiple tab controls.

Display Code
Download Code


Task Dialogs

Is a dialog box that can be used to display information and receive simple input from the user. A task dialog differs from a message box in that it offers far more features.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/task-dialogs-overview

The following short program demonstrates a simple task dialog

Display Code
Download Code


Toolbar Control

Is a control window usually displayed under the main menu that contains one or more buttons. Each button, when clicked by a user, sends a command message to the parent window. A toolbar can also contain other controls such as edit controls or combobox.

See creating toolbar page for a detailed description on how to create a toolbar.


Tooltip

Tooltips appear automatically pop up when the user pauses the mouse pointer over an application element and displays a brief message explaining the purpose of a particular feature. Tooltips are part of the help system of an application.

To create a Tab control specify TOOLTIPS_CLASS as the window class and register the class by specifying the ICC_TAB_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/tooltip-control-reference

The following short program demonstrates a simple tooltip window. Placing the map over the button causes the tooltip to appear

Display Code
Download Code


Trackbar Control

The trackbar controls allow the user to specify a value by scrolling a selector between its minimum and maximum points. The TrackBar control has two parts: an adjustable thumb or slider, and optional tick marks. When the user moves the slider, using either the mouse or the direction keys, the control sends notification messages to indicate the change.

To create a Tab control specify TRACKBAR_CLASS as the window class and register the class by specifying the ICC_LISTVIEW_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

The TBS_AUTOTICKS style creates a tick mark for each increment in its range of values. Setting other controls as buddy window for the trackbar, means descriptive labels can be placed at either end of the trackbar. When Trackbar slider is moved, the parent window receives the WM_HSCROLL message.

For further reading – https://docs.microsoft.com/en-us/windows/win32/controls/using-trackbar-controls

The following program demonstrates and simple trackbar control with value from 0-100. Changes in value will be reflected in the neighbouring buddy window.

Display Code
Download Code


Tree-View Control

A tree-view is a window that displays a hierarchical list of labelled items or nodes. Each item can have a number of sub items. The top item in the hierarchy is called the root. If an item has other items below it in the hierarchy, it is referred to as a parent. Items subordinate to parents are called children. The hierarchy may be expanded or collapsed at any level to display or hide child items.

To create a Tab control specify WC_TREEVIEW as the window class and register the class by specifying the ICC_LISTVIEW_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.

For further reading – https://docs.microsoft.com/en-us/windows/win32/controls/tree-view-control-reference

The following program demonstrates the Treeview control. Nodes can be added or deleted by clicking the appropriate button.

Display Code
Download Code


Updown Control

The Updown or spinner control consists of a pair of buttons displayed as arrows with an optional buddy control. The most common buddy control is an edit box and the combination of the two is called a spinner control. Clicking either of the arrows increments or decrements the value in the edit control.

To create a Tab control specify UPDOWN_CLASSW as the window class and register the class by specifying the ICC_UPDOWN_CLASS bit flag in the accompanying INITCOMMONCONTROLSEX structure.

When one of the up-down arrows is pressed the UDN_DELTAPOS message is sent in the form of a WM_NOTIFY message. The UDM_SETBUDDY message sets the edit control to be the buddy window for the UpDown control and The UDS_SETBUDDYINT flag causes the UpDown control to send a message (WM_SETTEXT) to its buddy when its position changes. The UDM_SETRANGE message sets the minimum and maximum positions for the UpDown control.

For further reading https://docs.microsoft.com/en-us/windows/win32/controls/up-down-control-reference

The following short program demonstrates a spinner control. Any changes in the control are reflected in the neighbouring static box.

Display Code
Download Code


Home | API | MFC | C++ | C | Previous | Next
Creating a Simple Window | Common Elements | Data Types and Character Sets | The Device Context | Graphics Device Interface | Displaying Text | Displaying Graphics | Mapping Modes | Keyboard Input | Working with the Mouse | Menus | Child Windows | ScrollBar Control | The Dialog Box | Windows Message Box | Common Dialog Box | Bitmaps | Common Controls | Creating a Toolbar | Multiple Document Interface | Timers | DLL’s | Creating Custom Controls | Owner Drawn Controls | API Hooking and DLL Injection | File Management Functions | String Manipulation | System Information Functions