# combo boxes

## Recommended Posts

I seem to be having a problem with the combo box i created in the dialog editor using the toolbox The combo box when running doesn't seem to show any of the strings i added. Ive double checked the ID's are correct, and count always seems to be 0, and @err,hr doesn't show anything other than OK, any ideas?

static const char* NotUsed = "**";

switch( msg )
{
case WM_INITDIALOG:

//lights
handle = GetDlgItem(hwnd,IDC_COMBOBOX_LIGHTS);
count = SendMessage(handle, CB_GETCOUNT, 0, 0);

return 0;
}



##### Share on other sites
check if its returning an error first:

switch(SendMessage(handle, CB_ADDSTRING, 0, (LPARAM) "Light1")){   case CB_ERRSPACE:     // not enough space to store string     break;    case CB_ERR:       // error        break;   default:      // something else{

##### Share on other sites

• Are you sure the IDC_COMBOBOX_LIGHTS is correct?

• Is this on the correct dialog?

• Try adding unicode strings instead (prefix the literals with L and cast to LPTSTR).

• What are the styles (owner-drawn? has strings?) for the combobox (post the line from the .rc file)?

• Try printing the return values of the SendMessages to check for errors.

• If this is a drop-down combobox, make sure the height of the control is enough to fit several lines of text (otherwise they're clipped).

##### Share on other sites
I tried all of that still no luck :(

Are you sure the IDC_COMBOBOX_LIGHT is correct? - Yes,

 CONTROL         "",IDC_COMBOBOX_LIGHT,"ComboBoxEx32",CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP,12,202,120,50

Is this on the correct dialog? - yes

Try adding unicode strings instead (prefix the literals with L and cast to LPTSTR) - no luck

//lights		handle = GetDlgItem(hwnd,IDC_COMBOBOX_LIGHT);		SendMessage(handle, CB_ADDSTRING, 0, (LPARAM) "Lig");		SendMessage(handle, CB_ADDSTRING, 0, (LPARAM) "Li");		SendMessage(handle, CB_ADDSTRING, 0, (LPARAM)(LPTSTR) L"Li");		SendMessage(handle, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) NotUsed2);		count = SendMessage(handle, CB_GETCOUNT, 0, 0);

What are the styles (owner-drawn? has strings?) for the combobox (post the line from the .rc file)?

 CONTROL         "",IDC_COMBOBOX_LIGHT,"ComboBoxEx32",CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP,12,202,120,50

Try printing the return values of the SendMessages to check for errors - always OK

If this is a drop-down combobox, make sure the height of the control is enough to fit several lines of text (otherwise they're clipped) - changed height

##### Share on other sites
You're creating a extended combo box, not a regular combo box. You have to insert items, rather than simply adding strings. See CBEM_INSERTITEM.

##### Share on other sites
ah yes, thankyou

I shall try to look at the .rc a lot more often, dont know how it became extended though, as i only created a standard combo box, anyway i remade a standard combo and all is good.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627636
• Total Posts
2978331

• 10
• 12
• 22
• 13
• 33