NO

Author Topic: WIN32 ComboBox control  (Read 4658 times)

Offline John Z

  • Member
  • *
  • Posts: 811
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: 2095
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: 177
    • 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.
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline DMac

  • Member
  • *
  • Posts: 272
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: 811
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: 177
    • 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.

Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Grincheux

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

Offline John Z

  • Member
  • *
  • Posts: 811
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: 811
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: 811
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

Offline CandCPlusPlus

  • Member
  • *
  • Posts: 57
Re: WIN32 ComboBox control
« Reply #10 on: December 03, 2022, 11:43:14 PM »
I ran into this problem with the ComboBox in the Windows API. The only way to change the size of the drop-down arrow of the ComboBox is oddly by changing the font size. I don't know what possessed Microsoft to design the ComboBox like this back in the 90s.
« Last Edit: December 03, 2022, 11:49:41 PM by CandCPlusPlus »

Offline WiiLF23

  • Member
  • *
  • Posts: 73
Re: WIN32 ComboBox control
« Reply #11 on: May 16, 2024, 10:09:53 PM »
The combobox control has a buggy history, and often developers will attempt to alter the controls appearance but will find that the win32 shell team implemented a group of pixels to draw the glyph, but it is all tied together so you have to either draw it all yourself or leave it alone in respect to its default style.

There are also undocumented API messages, which stump many. Not my favourite control to work with, and often I just use a Edit control and I draw a non-client area region and paint my own dropdown with highlight events (WM_PAINT, WM_MOUSEMOVE) with a Hittest on the rects region, and I go from there in respect to the label items.

I probably won’t ever use a traditional combobox anytime soon lol