-
July 5th, 2015, 07:33 AM
#1
width of combo box
I have small space on Sheet page and lots of controls. I have combo boxes, which take place, and I need to make them slim, so if I click on it the items should expand. I need to auto-change the width of the items which expand to fit the width of the longest item. Is there some style for this or way how to do it?
These styles I have applied:
CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
Last edited by crazy boy; July 5th, 2015 at 07:40 AM.
-
July 5th, 2015, 01:42 PM
#2
Re: width of combo box
You want to change the size of the combo-box list box so that it fits the width of the longest item?
This is possible. First you need to determine the required width of the list box. Then you process CBN_DROPDOWN notification (https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx) which happens when the list box of a combo control is about to become visible. Then use CB_GETCOMBOBOXINFO message (https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx) to obtain the HWND of the list box, then use GetWindowRect() and MoveWIndow() to resize the list box.
This is an extract from some code (so won't compile but will give the general idea)
Code:
COMBOBOXINFO cbinfo;
RECT rdraw;
//Get handles to combo windows
cbinfo.cbSize = sizeof(COMBOBOXINFO);
SendMessage(hwndItem, CB_GETCOMBOBOXINFO, 0, (LPARAM) (COMBOBOXINFO*) &cbinfo);
//Get position of current list box so new one starts at same position
GetWindowRect(cbinfo.hwndList, &rdraw);
//Make list window new required size
MoveWindow(cbinfo.hwndList, rdraw.left, rdraw.top, comwidth, rdraw.bottom - rdraw.top, TRUE);
//Set font for new list window
SendMessage(cbinfo.hwndList, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), TRUE);
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 5th, 2015, 02:54 PM
#3
Re: width of combo box
There is a CB_SETDROPPEDWIDTH message that can be used.
Before sending it, it is necessary to obtain the max width of all the combo items. you could use GetTextExtentPoint32 or similat function...
Victor Nijegorodov
-
July 5th, 2015, 03:57 PM
#4
Re: width of combo box
Originally Posted by VictorN
There is a CB_SETDROPPEDWIDTH message that can be used.
Note that this requires Vista or higher.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 6th, 2015, 01:20 AM
#5
Re: width of combo box
Originally Posted by 2kaud
Originally Posted by VictorN
There is a CB_SETDROPPEDWIDTH message that can be used.
Note that this requires Vista or higher.
Interesting!
I didn't know such a requirement and used MFC CComboBox::SetDroppedWidth() which internally sends CB_SETDROPPEDWIDTH message) under Window98/NT more than a decade back...
Victor Nijegorodov
-
July 6th, 2015, 02:36 AM
#6
Re: width of combo box
From my MSDN of October 2000:
CB_SETDROPPEDWIDTH
An application sends the CB_SETDROPPEDWIDTH message to set the maximum allowable width, in pixels, of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style.
...
Requirements
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Victor Nijegorodov
-
July 6th, 2015, 04:04 AM
#7
Re: width of combo box
Well that's just Microsoft! The current documentation states the minimum requirement is Vista. https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx Doh!!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 6th, 2015, 04:20 AM
#8
Re: width of combo box
I guess there was the "work" of some young MSFT employee that never heard about any system preceding Vista.
Sure he/she does not know about punch cards either!
PS: I have now "updated" this site:
https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Last edited by VictorN; July 6th, 2015 at 07:06 AM.
Victor Nijegorodov
-
July 6th, 2015, 06:15 AM
#9
Re: width of combo box
Originally Posted by VictorN
The employee has been busy! eg CreateFile() is stated as minimum Windows XP and CreateWindow() as Windows 2000! Doh!!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|