Re: COMBOBOX woes
"John Carson" <email@example.com> wrote in message
"Jim Langston" <firstname.lastname@example.org> 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.
Yeah, I found that out when digging up the switches for COMBO boxes. I'll
simply remove the 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.
The wrong one is shown. It always shows the last one in the list, 1024x768
even though they selected 640x480. I select 640x480 which shows in the
little edit box. I close the window (which simply does a ShowWindow( hwnd,
SW_HIDE ); which is on the "Abyssal Settings" window.
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
It is either that or make the window handles global, and I would rather make
extra calls than make unneccesary variables global. I didn't mislay it,
it's simply owned by WinMain() and not WindowProcedure(). I know of no way
to make the handle visible to WindowProcedure() (Windows callback) without
making it global, which I don't want to do.
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.
SettingsWindow IS hwndSettings.
I have 3 windows in question here.
My main window: "Abyssal Auto Update"
A child of this window is: "Abyssal Settings" which is simply a window with
the settings controls.
and a child of that window is my combobox.