The MFC Professional

Newbie Tip #10

Have a tip? Send it to us, and we'll post your name, email address and URL.



Where is the handle to the CListBox object?

This tip comes from a post in comp.os.ms-windows.programmer.tools.mfc...



Hello,

I'm new to MFC/Windows, done a fair amount of reading, but... How does one insert anything into a list box (that is in a CDialog window) if the list box is created with the resource editor (with the control toolbox window with the combo box. list box, buttons, etc...)? Where is the handle to the CLisBox object? Any help appreciated.

Thanks,

-- Mark Crosland


When you create a control with the resource editor, you or the IDE assign an ID to the control (IDC_LIST1). GetDlgItem(IDC_LIST1) returns a CWnd * to the object which you can cast to a CListBox*:

CListBox *pListBox = (CListBox *) GetDlgItem(IDC_LIST1);

--OR--

You can use the ClassWizard to create a class member that corresponds to the listbox. Select the "member variables" tab from ClassWizard select the listbox id from the list and press the "add variable" button. Specify a member name and select "control" from the category combobox.

-- Rick Murtagh



| Past Tips | Future Tips | Home |


Comments on this Tip? Send us mail.
(Be sure to put the Tip # in the subject.)

Got an idea for a Tip you'd like us to write? Let us know.

Solved a problem lately that would make a good Tip? PLEASE tell us about it!!!
We'll give you prominent credit, and we'll even buy you a beer next time you're in town.