How do I use a check list box?
David Stidolph -- stidolph@magnet.com
Tuesday, January 23, 1996
I am using VC 4.0 and Windows 95.
I want to have a check list box in a dialog. How do I add one using the =
resource editor? I know I can create one and add it through =
programming, but I would prefer to do it the "normal" way if possible.
Once I have the control - what mfc function(s) would I use to handle =
checking or unchecking elements within the list?
The point of the exercise is to allow a user to select options and show =
the memory usage for selected options (change a static text field).
Thanks in advance - I know this is a simple question, but I can't find =
much documentation on this control.
-------------------------------------------------------------------------=
-
David Stidolph
Gee that bastard smells. No wonder they call him Pooh. --Chris Robin.
-------------------------------------------------------------------------=
--
Mark Turner -- Mark.Turner@softcare.co.uk
Thursday, January 25, 1996
[Mini-digest: 4 responses]
I had trouble initially with CCheckListBox,=20
eventually I cracked it.....
1. Add a List Box in Resource editor, set its style to OWNERDRAW and =
HASSTRINGS
2. Add a Member variable in Classwizard of type Control & CListBox
3. Edit the Variable in the Header file and change its type to =
CCheckListBox
4. Insert strings into the listbox as normal then Use GetCheck & =
SetCheck to Check/Uncheck your listbox entries.
Hope this helps
//
// Mark.Turner@Softcare.co.uk
//
-----From: Niels Ull Jacobsen
As the "Checked list box" isn't a standard resource, you can't add it
in the resource editor. I think the easiest way would be to add a
CListBox member variable and then manually change it to be a
CCheckListBox.
>
> Once I have the control - what mfc function(s) would I use to handle =
> checking or unchecking elements within the list?
Use the source Luke!
If you search for CCheckListBox in the MFC source, you'll find it in
winctrl3.cpp. In CCheckListBox::OnLButtonDown (and several other places) you'll
find:
// Inform of check
pParent->SendMessage(WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(), CLBN_CHKCHANGE), (LPARAM)m_hWnd);
You can catch this in your dialog with a
ON_CONTROL(IDC_MYLISTBOX, CLBN_CHKCHANGE, OnMyListBoxChange)
in your message map.
You can use GetCaretIndex() to find out which item
were checked/unchecked.
--
Niels Ull Jacobsen, Kruger A/S
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
group and should be taken as legally binding in every respect. Pigs
will grow wings and fly.
-----From: LeRoy Baxter
Use a standard listbox in the RC (must be Owner-draw fixed, and Has =
Strings)
then subclass in the dialog's InitDialog()
m_myCCheckListBox.SubclassDlgItem(IDC_MYLISTBOX, this);
You can check all the items like this:
for (int i=3D0; i wrote:
>
>I want to have a check list box in a dialog. How do I add one
>using the resource editor? I know I can create one and
> add it through programming, but I would prefer to do it the
> "normal" way if possible.
The checked list box isn't a Windows control. There's no way to add it
through the dialog editor. A checked list box is a standard list box control
window which is owner-draw painted by code in the MFC-supplied CCheckListBox
class.
>Once I have the control - what mfc function(s) would I use to handle
checking or unchecking elements within the list?
>
Like the documentation says, you can use the CCheckListBox::GetCheck() and
CCheckListBox::SetCheck() functions.
>Thanks in advance - I know this is a simple question, but I can't find much
documentation on this control.
>
I don't understand that-- where did you try looking? CCheckListBox is right
there in the hierarchy (with everything else) under "Class Library Reference"
in online help.
.B ekiM
--
#ifdef JOHNELS_SAID_I_COULD_STEAL_HIS_SIG
//REVIEW: JohnEls changed his and now it's cooler than the one I stole
TCHAR szDisc[] = _T("These words are my own; I do not speak for Microsoft.");
#endif
| Вернуться в корень Архива
|