Re: COMBOBOX woes
"Jim Langston" <email@example.com> wrote in message
I'm trying to create a combo box. This is how I want it to behave.
It is a drop down box that lists the current selection when the window
becomes visible. When the down arrow is pressed the list of sections
comes up where the user can select one, which becomes the item
It seems simple enough, but for some reason I can't do it. The
problem seems to be I can only get the list to show up if one of the
options for the combo box is WS_CHILD. If I don't select WS_CHILD
when the user presses down arrow they only see their current
selection which is highlighted. The user can press the up or down
arrow which selects a different item. This works the way I want to
except that the other items they can select are not visible.
From MSDN: "A control is a child window an application uses in conjunction
with another window to perform simple input and output (I/O) tasks." i.e.,
combo boxes, like all controls, are meant to be children. You are asking for
trouble to not make them that way.
This is my attempt:
// Resolution Dropdown Listbox //
HWND hwndSettingsResolution = CreateWindow(
WS_VISIBLE | CBS_DROPDOWNLIST, // | WS_TABSTOP, //| WS_CHILD,
20, 30, 100, 150,
hwndSettings, //parent window
ShowWindow is redundant if you use WS_VISIBLE.
SendMessage(hwndSettingsResolution, CB_ADDSTRING, 0, (LPARAM)
"640x480"); SendMessage(hwndSettingsResolution, CB_ADDSTRING, 0,
(LPARAM) "1024x786"); SendMessage(hwndSettingsResolution,
CB_SETCURSEL, Options.ScreenRez ? 1 : 0, 0);
This method will do as shown above, when the window is becomes
visible their selected item is shown in the combo box, but the full
dropdown isn't there. If I add the WS_CHILD then the full list is
shown, but the selected item isn't shown when the window becomes
Do you mean it is not shown at all or it is not shown selected? To be shown
selected, the combo box must have the focus.
So what I try then is to manually select what the selected item is
when the window is displayed. I change the options to WS_VISIBLE |
This is what I'm trying when I display the window:
ShowWindow( FindWindowEx( NULL, NULL, ClassName, "Abyssal Settings" ),
HWND SettingsWindow = FindWindowEx( NULL, NULL, ClassName, "Abyssal
I must say that making two FindWindow calls to retrieve a window handle you
should not have mislaid in the first place offends my programmer's
if ( SettingsWindow != NULL )
HWND ResWindow = GetDlgItem( SettingsWindow, CONTROL_SETTINGS_RES);
if ( ResWindow != NULL )
SendMessage(ResWindow, CB_SETCURSEL, Options.ScreenRez ? 1 :
0, 0); }
But this fails becomes ResWindow is NULL. The SettingsWindow is not
NULL however, which is the parent of the window seen as hwndSettings.
Using windows handles as window names for brevity, do you mean
SettingsWindow is the parent of hwndSettings or that SettingsWindow IS
hwndSettings? If the former, then the failure of GetDlgItem is
understandable. GetDlgItem doesn't work with grandchildren.
If the foregoing doesn't help you resolve the problem, then I suggest you
tell us exactly what the structure of your windows is --- what is the child
of what and whether you are using dialog boxes or regular windows.