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...


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


    // 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 );


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.