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,

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 73
C++ mouse_event mouse look 7 97
How to Correctly derive class from CWinThread in MFC 4 67
Gaming Software 1 19
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

831 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