CComboBoxEx 不同 DPI、高度计算的问题

发布于 2024-09-30 14:24:55 字数 240 浏览 2 评论 0原文

我想在窗体上添加 CComboBoxEx,但我必须将其与其他控件对齐并使其高度相同。

问题是我找不到获取此控件高度的正确方法。

如果我设置窗口矩形,则会影响下拉列表框。如果我强制它为某个固定大小,并且组合内的内容较高,则控件会被剪裁在底部。

有没有办法根据图像和当前 DPI 设置计算 ComboBoxEx 有多大?这样,如果我无法调整控件的内部填充,我至少可以扩展其他控件。据我所知,MSDN 根本没有涉及大小问题。

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 could 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2024-10-07 14:24:55

组合框自动设置控件的高度,正如您所发现的,尝试设置自己的高度实际上会影响下拉列表的高度。

要获取控件的真实高度(以便您可以调整其他控件的大小),可以使用 GetWindowRect:

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

我不知道更改 Combo 控件本身的高度的好方法,坦率地说,我不相信这是可能的至少没有大量的子类化。因此,我实现了自己的组合式控件。

尽管它可能没有帮助,但您可能还想查看 GetComboBoxInfo() 函数,看看它是否提供了任何有用的信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文