News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Combox Scrolling

Started by Hunk, March 15, 2012, 05:20:01 AM

Previous topic - Next topic

Hunk

Hi, I have just added 25 items to my combobox and I want to display only 10 items in drop down list and want to add scroll to it.  Scrolling is working fine but is showing more than 20 items in a list on drop down.  any suggestions how to limit it to just 10 items only?

hutch--

The only thing that comes to mind is to restrict the size of the combo drop down list. Normally a combo box stores all of the data you put into it and it will display all of that data when the drop down list is activated. You could load an array with the number of items you need then select the number you want to display and load them into a combo box when it is activated but I know of no automatic way to do this, you would have to code it yourself.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

#2
The total height of your combobox includes the edit and dropdown portions, if you limit the size of the dropdown portion you can limit the number of items it displays (others will have to be scrolled in). In order to calculate the height necessary you need to know a couple of things, first what is the total height of the edit with borders and second what is the height of a single item in the dropdown portion. Once you know the item height and the total size of the edit portion its easy to set the number of items visible:

Depending on the combobox style etc.. this might need a bit of tweaking

Locals used:
cbi:COMBOBOXINFO
rc:RECT

invoke GetWindowRect,[hCombobox],offset rc
mov eax,[rc.left]
sub [rc.right],eax
mov D[cbi.cbSize],SIZEOF COMBOBOXINFO
invoke GetComboBoxInfo,[hCombobox],offset cbi
invoke SendMessage,[hCombobox],CB_GETITEMHEIGHT,0,0
mov ecx,10 // Number of items to display
mul ecx
add eax,[cbi.rcItem.bottom] // Item height
add eax,[cbi.rcItem.top] // Top border
add eax,[cbi.rcItem.top] // Bottom border
invoke SetWindowPos,[hCombobox],NULL,0,0,[rc.right],eax,SWP_NOMOVE + SWP_NOZORDER


Edit: A slight change to make the number of items more reliable across a wider range of styles, particularly CBS_NOINTEGRALHEIGHT
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Hunk

thanks to both of you, i will try them

dedndave

i am playing with a combobox at the moment and have the same issue
one thing i am seeing is that you cannot set the size during WM_INITDIALOG
it behaves as though the combobox has not yet been fully created (or at least the listbox part)
maybe it needs to have an item in it   :P

also, it seems that the height in the resource file is totally ignored - lol

needs more playing...

dedndave

ok - let me correct that...

the height in the resource file is ignored if UxThemes are enabled
if i disable the themes, it does work

at least, that's how it is under XP SP3
with UxThemes, it seems that the list box is another one of those "SHELLDLL_DefView" windows   :P

i was playing with that stuff recently in another thread...
http://www.masm32.com/board/index.php?topic=16931.msg154917#msg154917

dedndave

the more i play with UxTheme, the more i hate it - lol
the idiots that wrote that stuff should be shot
anyways - not a SHELLDLL_DefView window   :P

if i want to set the size of the list box with UxThemes, it would take a half-mile of code

the long list-box is starting to look pretty good   :lol