
Add a combo box in a dialog box...
I need more information. I assume that you want to load the "list" portion
of the combo box with names. When a user selects one of these names, then
you want to display the telephone number for this person. Where will the
telephone number be displayed? In a separate control, such as an edit
control?
I will assume for this explanation that your dialog resource contains a
combo box and an edit control. I am also assuming that this is an MFC
application, since you posted to the MFC newsgroup. Here are the steps...
(These are not the ONLY steps by which this can be done, just one possibly
list of steps to accomplish the task.)
1. Open the dialog resource in the dialog editor. With this resource open
for editing, start ClassWizard.
1a. If you do not already have an MFC class which represents this dialog
resource, you will be prompted to create one at this time. Do it.
2. In ClassWizard select the class which represents this dialog resource and
switch to the "member variables" page. You should se a list of the controls
on the page, specifically the combo box and the edit control.
3. Select the combo box from the list and click on the 'Add variable"
button.
4. From the "Add variable" dialog, type in a unique name for the variable
and change the "Category" field from "value" to "control." This will add a
variable which represents the control object rather than the current value
of the control.
5. Select the edit control from the ClassWizard list and add a variable for
it. This time leave the "Categoy" field set to "value" so that you create a
variable which represents the current value of the edit control.
6. Select the combo box again and add another variable. Give this variable a
unique name and leave it as a "value" category variable.
You now have three variables in the dialog class, two of which are
associated with the current value of the edit and combo box controls andthe
third of which is associated with the combo box object.
7. In ClassWizard change to the "Message Maps" tab.
8. In the "Object IDs" list select the first entry, which will be the name
of the class. In the "Messages" select find the entry for WM_INITDIALOG.
8a. If WM_INITDIALOG is *NOT* in bold type, click on the Add Function
button.
9. Click on the Edit Code button.
10. In the OnInitDialog function use your combo box control variable (add in
step 4 above) to call the AddString method of CComboBox repeatedly. With
each call you will add a name into the list portion of the combo box.
11. Start ClassWizard again, and select the "Message Maps" tab. Select your
dialog class. In the Object IDs list select the combo box control. In the
Messages list select CBN_SELCHANGE. Click on Add Function, then Edit Code.
12. In the function OnSelchangeXXX you first need to call UpdateData(TRUE).
This updates the values of the two "value" variables to the current values
of thes controls. You now have the currently selected name in your combo box
value variable. Us it to look up the desired telephone number and assign it
to the edit control variable. Finally, call UpdateData(FALSE) to write the
new value of the edit control variable into the actual edit control on the
dialog window.
That should do it.
Dave Smith
Quote:
> "After this, you can use ClassWizard to associate a
> variable with the combo box control."
> This is the main problem of me. Would u pls be more specify about this
part?
> For example, if I wanna make a list of people names, when I choose the
name
> from the combo box, it will shows the telephone number of him. How can I
do so?
> Thx~