Solved

C++ Combo Box

Posted on 2000-03-27
7
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 31

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 31

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

717 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