Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill combobox in a Visual Studio C++ Win32 project

How can I fill a combobox in a Visual Studio C++ Win32 project. And how can check that which word was selected by the user.

I mean I want a comboxbox for example filled with these: One, Two, Three. And I want to do different events depends on which one was chosen by the user.

Edit: The windows was created as a dialogbox in the resource editor and the message thread runs like this:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    return DialogBox(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
}

Thank you in advance!

like image 882
Gaboros Avatar asked Aug 22 '11 16:08

Gaboros


1 Answers

In the WM_INITDIALOG handler for the dialog, you can initialize the combo box with the strings you wish to select with the CB_ADDSTRING message:

SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) L"one");

Now you can respond to the CBN_SELENDOK message to respond to user changes to the dropdown.

like image 141
Mark Ransom Avatar answered Nov 15 '22 07:11

Mark Ransom