Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Combo Box Controls

Hello experts...

I am about to use a combo box in a dialog box by first time...

I guess I have to initialize this control in the WM_INITDIALOG message....

But can anyone tell the combo box works?

I mean.... Adding items... find out what item is selected... etc...


  • 2
  • 2
1 Solution

    // Add the string to the combo box
    SendMessage( hCombo, CB_ADDSTRING,  0, (LPARAM) (LPCTSTR) strDesc );

    // Select the first device in the combo box
    SendMessage( hCombo, CB_SETCURSEL, 0, 0 );
    // Get the index of the currently selected devices
    INT nIndex = (INT)SendMessage( hCombo, CB_GETCURSEL, 0, 0 );

    // retrieve the number of items in the list box of a combo box.
    INT numItem = (INT)SendMessage( hCombo, CB_GETCOUNT, 0, 0 );

Here is the way to add an items to a CComboBox:

first build the control using the "window controls",by add the control to your dialog.

now when you have a CComboBox control on your CDialog you should press the right mouse on the combo control-->Properties-->Data-->(Add a text)-->press CTRL+RETURN

this is the easiest to add a text to your CComboBox.

MarscAuthor Commented:

Thank you for your answer.... But I need to add items in run time.
In "design" times I have no way to know wich the items are...

MarscAuthor Commented:
Thank you very much.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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