Freigeben über


Creating the List Control

How the list control (CListCtrl) is created depends on whether you're using the control directly or using class CListView instead. If you use CListView, the framework constructs the view as part of its document/view creation sequence. Creating the list view creates the list control as well (the two are the same thing). The control is created in the view's OnCreate handler function. In this case, the control is ready for you to add items, via a call to GetListCtrl.

To use CListCtrl directly in a dialog box

  1. In the dialog editor, add a List Control to your dialog template resource. Specify its control ID.

  2. Use the Add Member Variable Wizard to add a member variable of type CListCtrl with the Control property. You can use this member to call CListCtrl member functions.

  3. Use the Properties window to map handler functions in the dialog class for any list control notification messages you need to handle (see Mapping Messages to Functions).

  4. In OnInitDialog, set the styles for the CListCtrl. See Changing List Control Styles. This determines the kind of "view" you get in the control, although you can change the view later.

To use CListCtrl in a nondialog window

  1. Define the control in the view or window class.

  2. Call the control's Create member function, possibly in OnInitialUpdate, possibly as early as the parent window's OnCreate handler function (if you're subclassing the control). Set the styles for the control.

See Also

Concepts

Using CListCtrl

Controls (MFC)