Creating a List View Control

To create a list view control, use the CreateWindowEx function, specifying the WC_LISTVIEW window class. The list view window class is registered in the application's address space when the common controls dynamic-link library (DLL) is loaded. To ensure that the DLL is loaded, call the InitCommonControls function before creating the control.

When you call CreateWindowEx, you can specify a combination of list view window styles to control the appearance and attributes of the control. For a complete list of the list view window styles, see List View Window Styles.

The following example creates a list view control and then calls application-defined functions that add image lists, columns, and list view items. The window style specifies the list view control's initial view and other options. This example specifies report view, which enables the user to edit the labels of list view items.

// CreateListView - creates a list view control.

// Returns the handle of the new control if successful or NULL

// otherwise.

// hwndParent - handle of the control's parent window

// pfData - file containing list view items

HWND WINAPI CreateListView(HWND hwndParent, FILE *pfData)

{

HWND hwndLV;

// Force the common controls DLL to be loaded.

InitCommonControls();

// Create the list view window.

hwndLV = CreateWindow(WC_LISTVIEW, "",

WS_CHILD | LVS_REPORT | LVS_EDITLABELS,

0, 0, CW_USEDEFAULT, CW_USEDEFAULT,

hwndParent, NULL, g_hinst, NULL);

if (hwndLV == NULL)

return NULL;

// Call application-defined functions to initialize the

// image lists, add columns, and add some items.

if (!InitListViewImageLists(hwndLV) ||

!InitListViewColumns(hwndLV) ||

!InitListViewItems(hwndLV, pfData)) {

DestroyWindow(hwndLV);

return FALSE;

}

return hwndLV; // return the control's handle

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database