Windows Common Controls - Computer Programming - Lecture Notes, Study notes of Computer Engineering and Programming

Windows Common Controls, Common control Library, DLL Versions, Common control Styles, Initialize Common Controls, List View, Image List, Screen Shot of an Example Application. As you can see in this file, how descriptive above mentioned points are explained in this lecture of computer programming. VU is one of best university for computer science in our country.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen 🇵🇰

4.6

(88)

84 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 23
23.1 OVERVIEW OF WINDOWS COMMON CONTROLS 2
23.2 COMMON CONTROL LIBRARY 3
DLL VERSIONS 4
23.3 COMMON CONTROL STYLES 4
23.4 INITIALIZE COMMON CONTROLS 5
23.4.1 INITCOMMONCONTROLS FUNCTION 5
23.4.2 INITCOMMONCONTROLSEX FUNCTION 5
23.4.2.1 INITCOMMONCONTROLSEX STRUCTURE 6
23.5 LIST VIEW 7
23.6 TODAYS GOAL 7
23.7 IMAGE LIST 7
23.8 IMAGELIST_CREATE FUNCTION 7
23.9 IMAGELIST_ADDICON FUNCTION 9
23.10 IMAGELIST_REPLACEICON FUNCTION 9
23.11 SCREEN SHOT OF AN EXAMPLE APPLICATION 10
23.12 CREATING LIST VIEW CONTROL 10
CREATING IMAGE LIST 10
23.13 WINDOWS DEFAULT FOLDER ICON 11
23.14 ADD IMAGE LIST 11
23.15 ADD COLUMN TO LIST VIEW 11
23.16 ADD AN ITEM 12
23.17 ADD SUB ITEM FOR THIS ITEM 12
23.18 FIND FIRST FILE 12
23.19 ADD COLUMN TO LIST VIEW 13
23.20 LAST MODIFIED DATE OF FILE 13
23.21 MODIFIED LIST VIEW CONTROL 13
SUMMARY 14
EXERCISES 14
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

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

  • Chapter
  • 23.1 OVERVIEW OF W INDOWS COMMON CONTROLS
  • 23.2 COMMON CONTROL LIBRARY
  • DLL VERSIONS
  • 23.3 COMMON CONTROL S TYLES
  • 23.4 INITIALIZE COMMON CONTROLS
  • 23.4.1 INIT COMMONCONTROLS F UNCTION
  • 23.4.2 INIT COMMONCONTROLS EX F UNCTION
  • 23.4.2.1 INITCOMMONCONTROLSEX S TRUCTURE
  • 23.5 LIST VIEW
  • 23.6 TODAY’ S GOAL
  • 23.7 IMAGE LIST
  • 23.8 IMAGELIST _CREATE F UNCTION
  • 23.9 IMAGELIST _ADDI CON F UNCTION
  • 23.10 IMAGELIST _REPLACE ICON F UNCTION
  • 23.11 S CREEN S HOT OF AN EXAMPLE APPLICATION
  • 23.12 CREATING LIST VIEW CONTROL
  • CREATING IMAGE LIST
  • 23.13 WINDOWS D EFAULT F OLDER ICON
  • 23.14 ADD IMAGE LIST
  • 23.15 ADD COLUMN TO LIST VIEW
  • 23.16 ADD AN ITEM
  • 23.17 ADD S UB ITEM FOR THIS ITEM
  • 23.18 F IND F IRST F ILE
  • 23.19 ADD COLUMN TO LIST VIEW
  • 23.20 LAST M ODIFIED DATE OF F ILE
  • 23.21 M ODIFIED L IST VIEW CONTROL
  • S UMMARY
  • EXERCISES

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.

DLL Versions

All 32-bit versions of Windows include common controls DLL, Comctl32.dll. However, this DLL has been updated several times since it was first introduced. Each successive version supports the features and application programming interface (API) of earlier versions. However, each new version also contains a number of new features and a correspondingly larger API. Applications must be aware of which version of Comctl32.dll is installed on a system, and only use the features and API that the DLL supports.

Because new versions of the common controls were distributed with Microsoft Internet Explorer, the version of Commctl32.dll that is present is commonly different from the version that was shipped with the operating system. It may actually be several versions more recent. It is thus not enough for your application to know which operating system it is running on. It must directly determine which version of Comctl32.dll is present.

23.3 Common control Styles

CCS_ADJUSTABLE:

This style enables a toolbar's built-in customization features, which enable the user to drag a button to a new position or to remove a button by dragging it off the toolbar. In addition, the user can double-click the toolbar to display the Customize Toolbar dialog box, which enables the user to add, delete, and rearrange toolbar buttons. CCS_BOTTOM: Causes the control to position itself at the bottom of the parent window's client area and sets the width to be the same as the parent window's width. Status windows have this style by default. CCS_LEFT: This style causes the control to be displayed vertically on the left side of the parent window. CCS_NODIVIDER: This style prevents a two-pixel highlight from being drawn at the top of the control. CCS_NOMOVEX: This style causes the control to resize and move itself vertically, but not horizontally, in response to a WM_SIZE message. If CCS_NORESIZE is used, this style does not apply. CCS_NOMOVEY: This style causes the control to resize and move itself horizontally, but not vertically, in response to a WM_SIZE message. If CCS_NORESIZE is used, this style does not apply. Header windows have this style by default. CCS_NOPARENTALIGN: This style prevents the control from automatically moving to the top or bottom of the parent window. Instead, the control keeps its position within the parent window despite changes to the size of the parent. If CCS_TOP or CCS_BOTTOM is also used, the height is adjusted to the default, but the position and width remain unchanged.

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.

23.5 List View

23.6 Today’s Goal

Today we are going to create a List Box. This list box will be explorer style list box. In this list box you can see large, small, list, report styles.

23.7 Image List

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

23.8 ImageList_Create Function

HIMAGELIST ImageList_Create( int cx , int cy , UINT flags , int cInitial , int cGrow );

cx: Width, in pixels, of each image.

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.11 Screen Shot of an Example Application

23.12 Creating List View Control

#define ID_LISTVIEW 5

hWndListView = CreateWindow(WC_LISTVIEW, "Window Name", WS_TABSTOP | WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_AUTOARRANGE | LVS_REPORT, 10, 10, 350, 280, hWndMain, (HMENU)ID_LISTVIEW, hInstance, NULL );

if(!hWndListView) { return 0; }

Creating Image List

hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), ILC_MASK, 1, 1); hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);

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.19 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 0; }

23.20 Last Modified Date of File

FileTimeToLocalFileTime(&findFileData.ftLastWriteTime, &fileTime); FileTimeToSystemTime(&fileTime, &systemTime);

strcpy(strAMPM, systemTime.wHour>=12? "PM" : "AM"); if(systemTime.wHour>=12) systemTime.wHour -= 12; if(!systemTime.wHour) systemTime.wHour = 12;

wsprintf(buf, "%d/%d/%d %2d:%02d %s", systemTime.wMonth, systemTime.wDay, systemTime.wYear, systemTime.wHour, systemTime.wMinute, strAMPM); lvi.iSubItem = 2; lvi.pszText = buf; if(ListView_SetItem(hWndListView, &lvi) == -1) return 1;

23.21 Modified List View control

VOID SetView(HWND hwndListView, DWORD dwStyle) { DWORD dwCurrentStyle;

dwCurrentStyle = GetWindowLong(hwndListView, GWL_STYLE); SetWindowLong(hwndListView, GWL_STYLE, (dwCurrentStyle & ~LVS_TYPEMASK) | dwStyle); }

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.