Overview of Windows Common Controls-Windows Programming-Lecture Notes, Study notes of Windows Programming

This lecture handout is for Windows Programming course. It was provided by Prof. Jaimini Chinmay at Ambedkar University, Delhi. It includes: Overview, Animation, Button, Combo, Box, Header, Image, Address, Edit, Drag, Control, Combination

Typology: Study notes

2011/2012

Uploaded on 08/07/2012

anishay
anishay 🇮🇳

4.2

(25)

118 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Common Controls 2
23.1 Overview of Windows Common Controls
A control is a child window an application uses in conjunction with another window to
perform simple input and output (I/O) tasks. Controls are most often used within dialog
boxes, but they can also be used in other windows. Controls within dialog boxes provide the
user with the means to type text, choose options, and direct a dialog box to complete its
action. Controls in other windows provide a variety of services, such as letting the user
choose commands, view status, and view and edit text. The user control overviews discuss
how to use these controls.
The following table lists the Windows controls.
Control Description
Animation An animation control is a window that displays an Audio-Video Interleaved
(AVI) clip.
Button Button controls typically notify the parent window when the user chooses
the control.
Combo Box Combo box controls are a combination of list boxes and edit controls,
letting the user choose and edit items.
ComboBoxEx ComboBoxEx Controls are an extension of the combo box control that
provides native support for item images.
Date and Time
Picker
A date and time picker (DTP) control provides a simple and intuitive
interface through which to exchange date and time information with a user.
Drag List Box Drag List Boxes are a special type of list box that enables the user to drag
items from one position to another.
Edit Edit controls let the user view and edit text.
Flat Scroll Bar Flat scroll bars behave just like standard scroll bars except that you can
customize their appearance to a greater extent than standard scroll bars.
Header
A header control is a window that is usually positioned above columns of
text or numbers. It contains a title for each column, and it can be divided
into parts.
Hot Key A hot key control is a window that enables the user to enter a combination
of keystrokes to be used as a hot key.
Image Lists An image list is a collection of images of the same size, each of which can
be referred to by its index.
IP Address
Controls
An Internet Protocol (IP) address control allows the user to enter an IP
address in an easily understood format.
List Box List box controls display a list from which the user can select one or more
items.
List-View A list-view control is a window that displays a collection of items. The
control provides several ways to arrange and display the items.
Month Calendar A month calendar control implements a calendar-like user interface.
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Overview of Windows Common Controls-Windows Programming-Lecture Notes and more Study notes Windows Programming in PDF only on Docsity!

23.1 Overview of Windows Common Controls

A control is a child window an application uses in conjunction with another window to perform simple input and output (I/O) tasks. Controls are most often used within dialog boxes, but they can also be used in other windows. Controls within dialog boxes provide the user with the means to type text, choose options, and direct a dialog box to complete its action. Controls in other windows provide a variety of services, such as letting the user choose commands, view status, and view and edit text. The user control overviews discuss how to use these controls.

The following table lists the Windows controls.

Control Description

Animation An animation control is a window that displays an Audio-Video Interleaved (AVI) clip.

Button Button controls typically notify the parent window when the user chooses the control.

Combo Box Combo box controls are a combination of list boxes and edit controls, letting the user choose and edit items.

ComboBoxEx ComboBoxEx Controls are an extension of the combo box control that provides native support for item images.

Date and Time Picker

A date and time picker (DTP) control provides a simple and intuitive interface through which to exchange date and time information with a user.

Drag List Box Drag List Boxes are a special type of list box that enables the user to drag items from one position to another.

Edit Edit controls let the user view and edit text.

Flat Scroll Bar Flat scroll bars behave just like standard scroll bars except that you can customize their appearance to a greater extent than standard scroll bars.

Header

A header control is a window that is usually positioned above columns of text or numbers. It contains a title for each column, and it can be divided into parts.

Hot Key A hot key control is a window that enables the user to enter a combination of keystrokes to be used as a hot key.

Image Lists An image list is a collection of images of the same size, each of which can be referred to by its index.

IP Address Controls

An Internet Protocol (IP) address control allows the user to enter an IP address in an easily understood format.

List Box List box controls display a list from which the user can select one or more items.

List-View A list-view control is a window that displays a collection of items. The control provides several ways to arrange and display the items.

Month Calendar A month calendar control implements a calendar-like user interface.

Pager A pager control is a window container that is used with a window that does not have enough display area to show all of its content.

Progress Bar A progress bar is a window that an application can use to indicate the progress of a lengthy operation.

Property Sheets A property sheet is a window that allows the user to view and edit the properties of an item.

ReBar Rebar controls act as containers for child windows. An application assigns child windows, which are often other controls, to a rebar control band.

Rich Edit Rich Edit controls let the user view and edit text with character and paragraph formatting, and can include embedded COM objects.

Scroll Bars Scroll bars let the user choose the direction and distance to scroll information in a related window.

Static Static controls often act as labels for other controls.

Status Bars A status bar is a horizontal window at the bottom of a parent window in which an application can display various kinds of status information.

SysLink A SysLink control provides a convenient way to embed hypertext links in a window.

Tab

A tab control is analogous to the dividers in a notebook or the labels in a file cabinet. By using a tab control, an application can define multiple pages for the same area of a window or dialog box.

Toolbar

A toolbar is a control window that contains one or more buttons. Each button, when clicked by a user, sends a command message to the parent window.

ToolTip ToolTips are hidden most of the time. They appear automatically, or pop up, when the user pauses the mouse pointer over a tool.

Trackbar

A trackbar is a window that contains a slider and optional tick marks. When the user moves the slider, using either the mouse or the direction keys, the trackbar sends notification messages to indicate the change.

Tree-View

A tree-view control is a window that displays a hierarchical list of items, such as the headings in a document, the entries in an index, or the files and directories on a disk.

Up-Down

An up-down control is a pair of arrow buttons that the user can click to increment or decrement a value, such as a scroll position or a number displayed in a companion control.

23.2 Common control Library

Most common controls belong to a window class defined in the common control DLL. The window class and the corresponding window procedure define the properties, appearance, and behavior of the control. To ensure that the common control DLL is loaded, include the InitCommonControlsEx function in your application. You create a common control by specifying the name of the window class when calling the CreateWindowEx function or by specifying the appropriate class name in a dialog box template.

CCS_NORESIZE:

This style prevents the control from using the default width and height when setting its initial size or a new size. Instead, the control uses the width and height specified in the request for creation or sizing. CCS_RIGHT: This style causes the control to be displayed vertically on the right side of the parent window. CCS_TOP: This style causes the control to position itself at the top of the parent window's client area and sets the width to be the same as the parent window's width. Toolbars have this style by default. CCS_VERT: This style causes the control to be displayed vertically.

23.4 Initialize Common Controls

For initialization common controls there are two function available:

  • InitCommonControls()
  • InitCommonControlsEx()

23.4.1 InitCommonControls Function

Registers and initializes the common control window classes.

According to the Microsoft documentation this little function is obsolete. New applications should use the InitCommonControlsEx function. So you should not use this function.

void InitCommonControls(VOID);

This little function does not return anything.

23.4.2 InitCommonControlsEx Function

Registers specific common control classes from the common control dynamic-link library (DLL).

BOOL InitCommonControlsEx( LPINITCOMMONCONTROLSEX lpInitCtrls );

lpInitCtrls: Pointer to an INITCOMMONCONTROLSEX structure that contains information specifying which control classes will be registered.

Return Value Returns TRUE if successful, or FALSE otherwise.

The effect of each call to InitCommonControlsEx is cumulative. For example, if InitCommonControlsEx is called with the ICC_UPDOWN_CLASS flag, then is later called with the ICC_HOTKEY_CLASS flag, the result is that both the up-down and hot key common control classes are registered and available to the application.

23.4.2.1 INITCOMMONCONTROLSEX Structure

This structure carries information used to load common control classes from the dynamic- link library (DLL). This structure is used with the InitCommonControlsEx function.

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

dwSize: Size of the structure, in bytes. dwICC: Set of bit flags that indicate which common control classes will be loaded from the DLL. This value can be a combination of the following: ICC_ANIMATE_CLASS: Load animate control class. ICC_BAR_CLASSES: Load toolbar, status bar, trackbar, and ToolTip control classes. ICC_COOL_CLASSES: Load rebar control class. ICC_DATE_CLASSES: Load date and time picker control class. ICC_HOTKEY_CLASS: Load hot key control class. ICC_INTERNET_CLASSES: Load IP address class. ICC_LINK_CLASS: Load a hyperlink control class. ICC_LISTVIEW_CLASSES: Load list-view and header control classes. ICC_NATIVEFNTCTL_CLASS: Load a native font control class. ICC_PAGESCROLLER_CLASS: Load pager control class. ICC_PROGRESS_CLASS: Load progress bar control class. ICC_STANDARD_CLASSES: Load one of the intrinsic User32 control classes. The user controls include button, edit, static, listbox, combobox, and scrollbar. ICC_TAB_CLASSES: Load tab and ToolTip control classes. ICC_TREEVIEW_CLASSES: Load tree-view and ToolTip control classes. ICC_UPDOWN_CLASS: Load up-down control class. ICC_USEREX_CLASSES: Load ComboBoxEx class. ICC_WIN95_CLASSES: Load animate control, header, hot key, list-view, progress bar, status bar, tab, ToolTip, toolbar, trackbar, tree-view, and up-down control classes.

Cy: Height, in pixels, of each image. Flags: Set of bit flags that specify the type of image list to create. This parameter can be a combination of the following values, but it can include only one of the ILC_COLOR values. ILC_COLOR: Use the default behavior if none of the other ILC_COLOR* flags is specified. Typically, the default is ILC_COLOR4, but for older display drivers, the default is ILC_COLORDDB: ILC_COLOR4: Use a 4-bit (16-color) device-independent bitmap (DIB) section as the bitmap for the image list. ILC_COLOR8: Use an 8-bit DIB section. The colors used for the color table are the same colors as the halftone palette. ILC_COLOR16: Use a 16-bit (32/64k-color) DIB section. ILC_COLOR24: Use a 24-bit DIB section. ILC_COLOR32: Use a 32-bit DIB section. ILC_COLORDDB: Use a device-dependent bitmap. ILC_MASK: Use a mask. The image list contains two bitmaps, one of which is a monochrome bitmap used as a mask. If this value is not included, the image list contains only one bitmap. ILC_MIRROR: Microsoft® Windows® can be mirrored to display languages such as Hebrew or Arabic that read right-to-left. If the image list is created on a mirrored version of Windows, then the images in the lists are mirrored, that is, they are flipped so they display from right to left. Use this flag on a mirrored version of Windows to instruct the image list not to automatically mirror images. ILC_PERITEMMIRROR cInitial: This member is number of images that the image list initially contains. cGrow: This member is a number of images by which the image list can grow when the system needs to make room for new images. This parameter represents the number of new images that the resized image list can contain.

23.9 ImageList_AddIcon Function

int ImageList_AddIcon(

HIMAGELIST himl , HICON hicon );

himl: Handle to the image list. If this parameter identifies a masked image list, the macro copies both the image and mask bitmaps of the icon or cursor. If this parameter identifies a nonmasked image list, the macro copies only the image bitmap. Hicon: Handle to the icon or cursor that contains the bitmap and mask for the new image. Return Value: Returns the index of the new image if successful, or -1 otherwise.

Because the system does not save hicon , you can destroy it after the macro returns if the icon or cursor was created by the CreateIcon function. You do not need to destroy hicon if it was loaded by the LoadIcon function; the system automatically frees an icon resource when it is no longer needed.

23.10 ImageList_ReplaceIcon Function

int ImageList_ReplaceIcon( HIMAGELIST himl , int i , HICON hicon );

himl: Handle to the image list. i: Index of the image to replace. If i is -1, the function appends the image to the end of the list. Hicon: Handle to the icon or cursor that contains the bitmap and mask for the new image.

Return Value: Returns the index of the image if successful, or -1 otherwise.

hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_FOLDER)); ImageList_AddIcon(hLarge, hIcon); ImageList_AddIcon(hSmall, hIcon); hIcon = LoadIcon(.. MAKEINTRESOURCE(IDI_ICON_FILE))

23.13 Windows Default Folder Icon

23.14 Add Image List

ListView_SetImageList(hWndListView, hLarge, LVSIL_NORMAL); ListView_SetImageList(hWndListView, hSmall, LVSIL_SMALL);

HIMAGELIST ListView_SetImageList( HWND hwnd, HIMAGELIST himl, int iImageList type of IL: LVSIL_NORMAL | LVSIL_SMALL | LVSIL_STATE );

23.15 Add column to List View

lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.cx = COL_WIDTH;

for(i=0; i<3; ++i) { lvc.iSubItem = i; lvc.fmt = alignments[i]; lvc.pszText = columnHeadings[i]; if(ListView_InsertColumn(hWndListView, i, &lvc) == -1) return 1; }

Folder.ico

23.16 Add an Item

/* add an item with 3 subitems = 4 columns */

lvi.state = 0; // no state: cut, focussed, selected etc. lvi.stateMask = 0; // no state specified: cut, focussed, selected etc. lvi.lParam = (LPARAM)1234; // item specific data

do { lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE; lvi.iItem = itemNo++; // which item it refers to lvi.iSubItem = 0; // refers to an ITEM lvi.iImage = (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? 0 : 1; // proper image lvi.pszText = findFileData.cFileName;

// add the item if(ListView_InsertItem(hWndListView, &lvi) == -1) return 0;

23.17 Add Sub Item for this Item

lvi.mask = LVIF_TEXT; lvi.iSubItem = 1; (findFileData.nFileSizeHigh * (MAXDWORD+1)) + findFileData.nFileSizeLow; if(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) wsprintf(buf, ""); else wsprintf(buf, "%10lu", findFileData.nFileSizeLow);

lvi.pszText = buf; if(ListView_SetItem(hWndListView, &lvi) == -1) return 1;

23.18 Find First File

hFind= FindFirstFile(DEFAULT_PATH, &findFileData); if(hFind == INVALID_HANDLE_VALUE) { MessageBox(NULL, "Error calling FindFirstFile", "Error", MB_OK); return 0; }

Summary

Common Controls are the part of Microsoft Windows Graphics Operating System. Almost all the WYSIWYG application use Common Controls for their compatibility and user friendliness with windows. In this lecture, we studied about common controls, their styles and behavior. We also created an application which best demonstrates the List View control of common controls. Common controls include controls like page controls, tree controls, list view controls that is modified from windows original control, button control that is also modified from windows original controls, data and time picker control, status bar, progress bar, rebar controls. These all controls reside in common controls library and the library has shipped with many versions. Before using the library you must check the valid version of the library because different version of library contains different controls properties.

Exercises

  1. Create Tree control and show all the files hierarchy.