C++ Combo Box

Posted on 2000-03-27
Last Modified: 2008-03-06
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?
Question by:wosee

Accepted Solution

sunj earned 200 total points
ID: 2662632
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.

Expert Comment

ID: 2663259
Hi wosee,

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

LVL 31

Expert Comment

ID: 2663361
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,

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.


Author Comment

ID: 2663467
The answer proposed by suni did solve my problem.  Thanks to suni.

Suni, how can I accept you answer?

Expert Comment

ID: 2663573
you are welcome, wosee. guess you might have to reject Zoppo's answer, and then accept my comment as the answer :)

Expert Comment

by:nils pipenbrinck
ID: 2663601

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;

LVL 31

Expert Comment

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

My answer is correct for none-MFC applications...

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question