Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions docs/mfc/reference/cchecklistbox-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,26 @@ A "checklist box" displays a list of items, such as filenames. Each item in the

`CCheckListBox` is only for owner-drawn controls because the list contains more than text strings. At its simplest, a checklist box contains text strings and check boxes, but you don't need to have text at all. For example, you could have a list of small bitmaps with a check box next to each item.

To create your own checklist box, you must derive your own class from `CCheckListBox`. To derive your own class, write a constructor for the derived class, then call `Create`.
To create your own checklist box:

If you want to handle Windows notification messages sent by a list box to its parent (usually a class derived from [`CDialog`](../../mfc/reference/cdialog-class.md)), add a message-map entry and message-handler member function to the parent class for each message.
1. In the resource editor, create a listbox control to contain the checkboxes. In the listbox's properties, set **Owner Draw** to **Fixed** and **Has Strings** to **True** so the checklist control can draw the checkboxes.
1. Instantiate `CCheckListBox` in your code and call `Create`. If you're using [Dialog Data Exchange](../dialog-data-exchange.md) (DDX) then `DDX_Control` does this for you.
1. Call `SetCheckStyle` to choose a checkbox mode.

Each message-map entry takes the following form:
At this point checkboxes should appear next to the listbox items. Checkboxes don't respond to mouse clicks unless you use DDX. If you aren't using DDX, subclass the checklist box.

**ON\_**_Notification_ **(** _`id`_, _`memberFxn`_ **)**
If screen artifacts appear in the control, try calling `SetFont(GetFont())` on the checklist box instance after adding your data.

where `id` specifies the child window ID of the control sending the notification and `memberFxn` is the name of the parent member function you've written to handle the notification.
To handle Windows notification messages sent between a list box annd its parent (usually a class derived from [`CDialog`](../../mfc/reference/cdialog-class.md)), add a message-map entry and message-handler member function to the parent class for each message with the following form:

The parent's function prototype is as follows:
**ON\_**_Notification_ **(** _`id`_, _`memberFxn`_ **)**

`afx_msg void memberFxn();`
`id` specifies the child window ID of the control sending the notification.\
`memberFxn` is the name of the parent member function you wrote to handle the notification.

There's only one message-map entry that pertains specifically to `CCheckListBox` (but see also the message-map entries for [`CListBox`](../../mfc/reference/clistbox-class.md)):
The parent's function prototype is: `afx_msg void memberFxn();`

- `ON_CLBN_CHKCHANGE` The user has changed the state of an item's checkbox.
There's only one message-map entry that pertains specifically to `CCheckListBox`: `ON_CLBN_CHKCHANGE`-The user has changed the state of an item's checkbox. For information about list box message-map entries, see [`CListBox`](../../mfc/reference/clistbox-class.md))

If your checklist box is a default checklist box (a list of strings with the default-sized checkboxes to the left of each), you can use the default [`CCheckListBox::DrawItem`](#drawitem) to draw the checklist box. Otherwise, you must override the [`CListBox::CompareItem`](../../mfc/reference/clistbox-class.md#compareitem) function and the [`CCheckListBox::DrawItem`](#drawitem) and [`CCheckListBox::MeasureItem`](#measureitem) functions.

Expand Down Expand Up @@ -92,7 +95,9 @@ CCheckListBox();

### Remarks

You construct a `CCheckListBox` object in two steps. First define a class derived from `CCheckListBox`, then call `Create`, which initializes the Windows checklist box and attaches it to the `CCheckListBox` object.
Construct a `CCheckListBox` object in two steps. First, instantiate `CCheckListBox`, then call `Create` to initialize the Windows checklist box and attach it to the `CCheckListBox` object.

The control also needs to be subclassed. When [Dialog Data Exchange](../dialog-data-exchange.md) (DDX) is used to create the control this happens automatically; otherwise call `SubclassDlgItem`.

### Example

Expand Down Expand Up @@ -130,7 +135,9 @@ Nonzero if successful; otherwise 0.

### Remarks

You construct a `CCheckListBox` object in two steps. First, define a class derived from `CcheckListBox` and then call `Create`, which initializes the Windows checklist box and attaches it to the `CCheckListBox`. See [`CCheckListBox::CCheckListBox`](#cchecklistbox) for a sample.
Construct a `CCheckListBox` object in two steps:
- Instantiate `CCheckListBox`
- Call `Create` to initialize the Windows checklist box and attach it to the `CCheckListBox` object. The control also needs to be subclassed. When [Dialog Data Exchange](../dialog-data-exchange.md) (DDX) is used to create the control, this happens automatically. Otherwise, call `SubclassDlgItem`. See [`CCheckListBox::CCheckListBox`](#cchecklistbox) for an example.

When `Create` executes, Windows sends the [`WM_NCCREATE`](../../mfc/reference/cwnd-class.md#onnccreate), [`WM_CREATE`](../../mfc/reference/cwnd-class.md#oncreate), [`WM_NCCALCSIZE`](../../mfc/reference/cwnd-class.md#onnccalcsize), and [`WM_GETMINMAXINFO`](../../mfc/reference/cwnd-class.md#ongetminmaxinfo) messages to the checklist-box control.

Expand All @@ -139,17 +146,11 @@ These messages are handled by default by the [`OnNcCreate`](../../mfc/reference/
Apply the following [window styles](../../mfc/reference/styles-used-by-mfc.md#window-styles) to a checklist-box control:

- `WS_CHILD` Always

- `WS_VISIBLE` Usually

- `WS_DISABLED` Rarely

- `WS_VSCROLL` To add a vertical scroll bar

- `WS_HSCROLL` To add a horizontal scroll bar

- `WS_GROUP` To group controls

- `WS_TABSTOP` To allow tabbing to this control

## <a name="drawitem"></a> `CCheckListBox::DrawItem`
Expand Down Expand Up @@ -338,17 +339,13 @@ Determines the style of check boxes in the checklist box.
Valid styles are:

- `BS_CHECKBOX`

- `BS_AUTOCHECKBOX`

- `BS_AUTO3STATE`

- `BS_3STATE`

For information on these styles, see [Button Styles](../../mfc/reference/styles-used-by-mfc.md#button-styles).

## See also

[MFC Sample `TSTCON`](../../overview/visual-cpp-samples.md)\
[`CListBox` Class](../../mfc/reference/clistbox-class.md)\
[Hierarchy Chart](../../mfc/hierarchy-chart.md)