Skip to content

Update cchecklistbox-class.md #5426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
24 changes: 21 additions & 3 deletions docs/mfc/reference/cchecklistbox-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,21 @@ 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`.
The basic steps to create your own checklist box are as follows:

First design an ordinary listbox control using the resource editor (because that's what the checklist box is based upon).
The listbox must have 'Owner Draw' set to `Fixed` and `Has Strings` to `True`.
That's because the checklist box needs to draw the checkboxes.

Next, instantiate `CCheckListBox` in your code, call `Create`.
Alternatively and in case you are using DDX then `DDX_Control` will do this for you.
Call `SetCheckStyle` to choose one of the checkbox modes.

At this point you should have checkboxes show up next to your listbox strings, but unless you are using DDX you'll find the checkboxes don't respond to mouse clicks.
To get it fully working without DDX you'll need to subclass the checklist box.

Some versions of the control show artifacts when the control is initially showing.
One workaround is to call `SetFont(GetFont())` on the checklist box instance after initially having added your data.

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.

Expand Down Expand Up @@ -92,7 +106,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.
You construct a `CCheckListBox` object in two steps. First instantiate `CCheckListBox`, then call `Create`, which initializes the Windows checklist box and attaches it to the `CCheckListBox` object.

The control also needs to be subclassed. When DDX is used to create the control this happens automatically, otherwise `SubclassDlgItem` needs to be called.

### Example

Expand Down Expand Up @@ -130,7 +146,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.
You construct a `CCheckListBox` object in two steps. First instantiate `CCheckListBox` and then call `Create`, which initializes the Windows checklist box and attaches it to the `CCheckListBox`.
The control also needs to be subclassed. When DDX is used to create the control this happens automatically, otherwise `SubclassDlgItem` needs to be called.
See [`CCheckListBox::CCheckListBox`](#cchecklistbox) for a sample.

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 Down