Do you get any idea ?
My combo box has about 26 items so I have to declare its height with a quite big value. When it shows its content, the whole list of items appears. It is too long ! I'd like to know whether or not I can limit the number of visible items at a time by using a scrollbar. Thanks !
Posted on 2003-09-25 02:46:36 by hcm2k3
1. Create a combobox with WS_VSCROLL Style
2. Set font to it
3. Get item height - SendMessage(...,CB_GETITEMHEIGHT,..)
4. GetWindowRect(yourcombohandle,RECT)
5. Calculate target combobox height: RECT.bottom - RECT.top + 2 + limit_display_to * item_height
6. SetWindowPos

This "+2" in the size is for the dropdownlist border size (1 at the top + 1 at the bottom)

limit_display_to is, for example, 8. If you put more items to your combobox, the scrollbar will appear

HTH
Posted on 2003-09-25 03:11:57 by Morris

5. Calculate target combobox height: RECT.bottom - RECT.top + 2 + limit_display_to * item_height

Thanks ! BTW, how can I compute item_height ? It is the height of the font used in the combo box, the height of the combo box when closed or anything else ?
Posted on 2003-09-25 23:25:43 by hcm2k3
BTW, how can I compute item_height ? It is the height of the font used in the combo box


After you set the font to the combobox, do:
SendMessage(hCombo,CB_GETITEMHEIGHT,0,0)

And yes, the item height is the height of the combobox font.
Posted on 2003-09-26 01:52:47 by Morris