I'm using a popup listbox (not ownerdrawn, and using LBS_HASSTRINGS style)which should be created the right size first time. So far I have managed to avoid doing this sort of thing! The character and number of rows is easy to determine, but to get the correct dimensions in pixels seems a bit trickier. It looks as if the following steps are required:
1. Get the font used by the listbox control
2. Get the DC of the listbox window
3. Use drawtext with DT_CALCRECT to get the content width required
4. Add the margin dimensions from GETSYSTEMMETRICS to give the overall width
5. Use the LB_GETITEMHEIGHT message to get the item height, multiply by the number of items in the list
6. Add vertical margin widths from GETSYSTEMMETRICS to give the overall height
This gets the maximum width and height required - quite possibly, too large to display, so constraints are applied.
*** update*** - don't need the font - (step 1), as it is the default font in the DC (step 2)
The procedure seems rather longwinded - is there a simpler method?
1. Get the font used by the listbox control
2. Get the DC of the listbox window
3. Use drawtext with DT_CALCRECT to get the content width required
4. Add the margin dimensions from GETSYSTEMMETRICS to give the overall width
5. Use the LB_GETITEMHEIGHT message to get the item height, multiply by the number of items in the list
6. Add vertical margin widths from GETSYSTEMMETRICS to give the overall height
This gets the maximum width and height required - quite possibly, too large to display, so constraints are applied.
*** update*** - don't need the font - (step 1), as it is the default font in the DC (step 2)
The procedure seems rather longwinded - is there a simpler method?
Comment