Creating a List View Control

A list view is a common control that displays a collection of items, such as files or folders. Each item has an icon and a label. A user can choose whether to have the items displayed as large icons, small icons, a list, or a detailed list. You can design list views so that a user can drag an item to a new location within the list view or sort the collection by tapping a column header. The following screen shot shows an image list in list view.

    To create a list view control

  1. Specify the WC_LISTVIEW class in the lpClassName parameter of the CreateWindowEx function.

    This class is registered when the common control DLL is loaded. Use the InitCommonControls function to ensure that this DLL is loaded. To register the list view class using the InitCommonControlsEx function, specify the ICC_LISTVIEW_CLASSES flag as the dwICC member of the INITCOMMONCONTROLSEX structure you pass in the lpInitCtrls parameter.

  2. Specify a list view style in the dwStyle parameter of the CreateWindowEx function.

You can speed up the creation of large list views by disabling the painting of the list view before adding the items. You do this by sending a WM_SETREDRAW message with the redraw flag in wParam set to FALSE. When finished adding items, re-enable painting by sending a WM_SETREDRAW message with the redraw flag wParam set to TRUE. Before inserting items, send the LVM_SETITEMCOUNT message with the cItems parameter set to the number of items in question. When you do this, the list view will allocate the memory it needs all at once, instead of having to reallocate more memory incrementally as the internal data structures grow.

You can change the view type after a list view control is created. To retrieve and change the window style, use the GetWindowLong and SetWindowLong functions. To determine the window styles that correspond to the current view, use the LVS_TYPEMASK value.

You can control the way items are arranged in icon view or small icon view by specifying either the LVS_ALIGNTOP windows style, which is the default, or the LVS_ALIGNLEFT window style. You can change the alignment after a list view control is created. To isolate the window styles that specify the alignment of items, use the LVS_ALIGNMASK value.

Windows CE does not support hot tracking, hover selection, background images, or list view ToolTips.