开发者

CComboBoxEx problems with different DPI, height calculation

I want to add a CComboBoxEx on my form, but I have to align it with other controls and make it the same height.

The problem is that I can't find which is the correct way to get the height of this control.

If I set the window rectangle, that affects the drop down listbox. If I force it to be some fixed size, and the content inside the combo is higher, the control gets clipped at the bottom.

Is there a way to calculate how big the ComboBoxEx will be, based on image and current DPI settings? So that I coul开发者_开发百科d at least expand the other controls if I cannot adjust the internal padding of the control. MSDN doesn't touch the sizing issues at all as far as I've looked.


ComboBoxes set the height of the control automatically, and as you've discovered, trying to set your own height actually affects the height of the drop-down list.

To get the real height of the control (so you can resize your other controls) you can use GetWindowRect:

RECT rc;
GetWindowRect(hWndCombo, &rc);
int iComboHeight = rc.bottom - rc.top;

I don't know of a good way to change the height of the Combo control itself, and frankly I don't believe it's possible at least without lots of subclassing. I have implemented my own combo-style control because of this.

Although it probably won't help, you may also like to have a look at the GetComboBoxInfo() function to see if that provides any useful information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜