• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

C++ Combo Box

I am using Microsoft Visual C++ version 6 and  have added a Combo box (with data : item1, item2) in my dialog based application, when I try to run the application the data "item1" and "item2" was not displayed in the combo box, why?
1 Solution
I assume you are using resource editor to add the item1 and item2. If that's the case, you may perform the following check:
1. in resource editor, click on the combo box's drop down arrow. (rather than its white text area!)

2. you will see a selection area appear. drag it to increase it's height.

maybe this is the reason.
Hi wosee,

But Ur ComboBox has Owner draw style sets to "No" or something else?

Hi wosee,

I assume your application doesn't use MFC (coz this question is not in MFC topic area).

As far as I know the items added to a combo box via resource editor are only set in MFC applications. MFC's functions CDialog::CreateIndirect() and CDialog::InitModalIndirect() gets a pointer passed which can point to a DLGINIT resource. Pure Win32 API does not use this resource! You can take a look at function COccManager::CreateDlgControls() in OCCMGR.CPP which loads that data and try to make a similar function, but I think it's much easier to simply store the strings you need in string table and add them at runtime.

hope that helps,

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

woseeAuthor Commented:
The answer proposed by suni did solve my problem.  Thanks to suni.

Suni, how can I accept you answer?
you are welcome, wosee. guess you might have to reject Zoppo's answer, and then accept my comment as the answer :)
nils pipenbrinckCommented:

I know this.. it's not an error. you just made your dialog with a dialog editor, and in the test mode each combo box will be filled with some dummy items (so you can test it).

When you initialize the dialog windows will not fill your combobox with default items. it's your job to do this.

basically you have to do this in the WM_INITDIALOG Message handler.. This handler is called once when the controls of the dialog have been created. You can fill them with default values here.

Here is a short example DialogProc callback function that fills 3 items into a combo box... directly cut'n'pasted from a program I wrote some weeks ago:

#define ID_MYCOMBOBOX 101

BOOL CALLBACK MyDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
  switch (uMsg)
    case WM_CLOSE:
      EndDialog (hwndDlg, 0);
      return 1;
    } break;

     case WM_INITDIALOG:
       HWND control;
       control = GetDlgItem (hwndDlg, ID_MYCOMBOBOX);
       SendMessage (control, CB_ADDSTRING, 0, (LPARAM) "16 Bit");
       SendMessage (control, CB_ADDSTRING, 0, (LPARAM) "8 Bit");
       SendMessage (control, CB_ADDSTRING, 0, (LPARAM) "4 Bit");
       SendMessage (control, CB_SETCURSEL, 0, 0);
     } break;
   return 0;

Why don't you ask such stuff in MFC topic area?

My answer is correct for none-MFC applications...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now