Board index » delphi » Help - Combobox 16bit app in Windows 95/NT

Help - Combobox 16bit app in Windows 95/NT

Hey all,

I have a problem with comboboxes in a Delphi 1.x app running in Windows
NT/95. The problem can be duplicated as follows:

a)Create a combobox at runtime (button action should be fine) parented
to a panel (panel is aligned top).
b)In the creation, set the alignment of the combobox to alClient, and
the style to csDropDownList.
c)Load some strings into the combobox.
d)Run the app.
e)Stretch the form until it is much wider than designed.
f)Open the combobox - it looks normal.
g)Decrease the size of the form.
h)Open the combobox - the listbox still extends out to the previously
long extent.

The problem is that when the combobox opens, Windows creates a new
window of class ComboLBox that is parented to the desktop. This window
will only get larger, not smaller. That is, if we open the combobox in
the smaller size, everything looks good. If we stretch, it still looks
good. But if it shrinks back down, it looks like {*word*99}.

I can't see any way to correlate the ComboLBox to the Combobox - I have
looked at all available information in WinSight, and I have searched the
API to no avail.

Ideally, I would like to subclass the combobox, trap the DropDown event,
and set the window width of the listbox window to the correct size. But
I don't know how to properly correlate an instance of the ComboLBox with
my instance of the Combobox.

Has anyone else solved this problem?

Thanks for any advice.

 

Re:Help - Combobox 16bit app in Windows 95/NT


Thanks to those who replied to my inquiry. I received C source from
Richard Drisko that returns the associated listbox. After I converted it
to Delphi, I found that Windows ignores attempts to change the width of
the window no matter where I placed the statement.

So, I looked in the Win32 API help and found a new message:
CB_SETDROPPEDWIDTH ($160). I found that this works perfectly if I
override the CNCommand event handler, or even send it from the
OnDropDown event.

If you want to subclass and forget about it, you can use the following:

type
        TC_Combobox = class(TCombobox)
        private
                procedure CNCommand(var Message: TWMCommand);
                        message CN_COMMAND;
        end;

        procedure TC_Combobox.CNCommand(var Message: TWMCommand);
        begin
                case Message.NotifyCode of
                CBN_DROPDOWN:
                begin
                        inherited;
                        SendMessage(handle, $160, width, 0);
                end;
                else
                        inherited;
                end;
        end;

Or, if you want the easy way out, you can set the OnDropDown event as
follows:

procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
        SendMessage(Combobox1.handle, $160, Combobox1.width, 0);
end;

Thanks again to those who responded.

Other Threads