NO

Author Topic: WIN32 ComboBox control  (Read 854 times)

Offline John Z

  • Member
  • *
  • Posts: 433
WIN32 ComboBox control
« on: December 14, 2021, 12:55:26 pm »
Does anyone know of a way to control the height of the edit box section in the ComboBox list control?  The control 'height' setting is for the entire drop down list.  The height of the top edit box portion seems to be solely set by the font size being used, however I would like to control it independently from the font.

Of course I can simulate a ComboBox with an edit box and a list box and overcome the ComboBox limitation but just checking to see if I've overlooked something.

Thanks,
John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1974
Re: WIN32 ComboBox control
« Reply #1 on: December 14, 2021, 04:20:35 pm »
As it's autosize, an empty bitmap might keep fixed size.
Couldn't find working example of that.
May the source be with you

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 96
    • Bcx Basic to C/C++ Translator
Re: WIN32 ComboBox control
« Reply #2 on: December 15, 2021, 04:51:44 am »
https://stackoverflow.com/questions/46272931/how-to-get-comboxs-edit-control-handle-from-subclassed-comboxs-listbox

Code: [Select]
Bottom line is that they are using a code snippet like this to obtain the edit control:

//  Get the edit window handle to each combo box.
pt.x = 1;
pt.y = 1;
hwndEdit1 = ChildWindowFromPoint(hwndCombo1, pt);

When trying, I had to use pt.x= 5 pt.y= 5 but I then get a control of window class "Edit" that receives the keystrokes.

Seems if you can get the "Edit" hwnd then resizing it could be accomplished several different ways.

Offline DMac

  • Member
  • *
  • Posts: 269
Re: WIN32 ComboBox control
« Reply #3 on: December 15, 2021, 07:14:31 am »
The simplest way to get the edit handle from a dropdown combobox.

HWND hEdit = FindWindowEx(hCombo, NULL, WC_EDIT, NULL);

Unfortunately you cannot resize the edit control though.

No one cares how much you know,
until they know how much you care.

Offline John Z

  • Member
  • *
  • Posts: 433
Re: WIN32 ComboBox control
« Reply #4 on: December 15, 2021, 10:44:44 am »
Thanks everyone!

I appreciate the ideas and inputs.  I'm going to try the empty bitmap idea from TimoVJL first, seems promising, then MrBCX which is (much) more involved, at least to me.  If it comes down to DMac thoughts I guess I'll drop back to simulating a combo box with a edit and a dropdown list.


Thanks All,

John Z

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 96
    • Bcx Basic to C/C++ Translator
Re: WIN32 ComboBox control
« Reply #5 on: December 15, 2021, 02:13:20 pm »
Using David's suggestion, I captured the "edit" hwnd and I can resize it but it fails to do anything useful, as I expect you want to resize the entire dropdown portion of the combobox - that is, the window that contains the edit control.  You might be able to use ownerdraw but that would be a lot more work and still might not give you what you want. 

Rolling your own would be much easier.


Grincheux

  • Guest
« Last Edit: December 15, 2021, 07:58:49 pm by Grincheux »

Offline John Z

  • Member
  • *
  • Posts: 433
Re: WIN32 ComboBox control
« Reply #7 on: December 16, 2021, 11:39:53 am »
Yes setting the ComboBox font size affects the vertical size of the edit box portion of the ComboBox automatically.  However this is not true with the standard edit box.  Therefore the ComboBox, edit part, size is out of synch with the rest of the sizing of the form controls.  Or if I set the font separately for the ComboBox that font is out of synch with the font in the other controls.  It may seem that this should not be an issue generally, but my program gives the user total control over the font and font size used within the limits of the current control height, and lets the user also control the window size separately (unless 'Auto Font Size' is enabled) which affects the size (height and width) of all embedded controls too.   

Thanks for the reference!  I'll check out to see if there is a usable solution.

John Z

Offline John Z

  • Member
  • *
  • Posts: 433
Re: WIN32 ComboBox control
« Reply #8 on: December 16, 2021, 01:29:39 pm »
I expect you want to resize the entire dropdown portion of the combobox - that is, the window that contains the edit control. 

Actually resizing the entire dropdown is not a problem, easy to do.   I actually want to resize the Edit box  portion independent of the font used.  That is the area between the arrows in your image, the 'border' of the Edit portion of the dropdown control.

Thanks,

John Z

Offline John Z

  • Member
  • *
  • Posts: 433
Re: WIN32 ComboBox control
« Reply #9 on: December 16, 2021, 02:52:15 pm »
Thanks All,

It looks like it is possible if I use an 'OwnerDraw' Combo box then use WM_MEASUREITEM on a 'standard' edit box to get the height into a LPMEASUREITEMSTRUCT, then you can use the lpmis->itemHeight value from the std edit box to set the ownerdraw control lpmis->itemHeight to the same value.   This is actually the method to ensure the height is adequate for setting the height of the ComboBox control to accommodate a bitmap.

https://docs.microsoft.com/en-us/windows/win32/controls/create-an-owner-drawn-combo-box

Probably easier to go the other way and make my own emulated combo box with a standard edit box and a dropdown standard list box.

John Z