Solved

C++ Combo Box

Posted on 2000-03-27
7
399 Views
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?
0
Comment
Question by:wosee
7 Comments
 
LVL 1

Accepted Solution

by:
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.
0
 
LVL 1

Expert Comment

by:mahno
ID: 2663259
Hi wosee,

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

mahno
0
 
LVL 30

Expert Comment

by:Zoppo
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,

ZOPPO
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Suni, how can I accept you answer?
0
 
LVL 1

Expert Comment

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

Expert Comment

by:nils pipenbrinck
ID: 2663601
hehe..

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;
}



0
 
LVL 30

Expert Comment

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

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now