为什么 BTNS_DROPDOWN 样式会导致整个工具栏向下移动几个像素?

发布于 2024-07-13 15:16:22 字数 479 浏览 5 评论 0原文

我有一个 CToolbar,其中有一个样式为 BTNS_BUTTON|BTNS_DROPDOWN 的按钮。 我想把它做成一个分割按钮,所以按钮的左侧是一个按钮,右侧有一个下拉菜单。

为了完成此操作,我创建按钮,然后调用 ::SendMessage,如下所示:

::SendMessage( hwndForButton, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS );

这非常有效并创建了分割按钮,但也会产生将工具栏向下移动几个像素的不良影响。 如果我不发送消息,那么问题仍然存在(并且我不再有拆分按钮)。

如果我将按钮的样式更改为 BTNS_BUTTON|BTNS_WHOLEDROPDOWN 那么​​我就没有问题,尽管我也没有拆分按钮。

关于这里可能出什么问题的任何线索吗? 我认为 BNTS_DROPDOWN 上有一个边距,它导致工具栏向下移动。

I have a CToolbar and within it I have a button with style BTNS_BUTTON|BTNS_DROPDOWN. I would like to make it a split button, so the left side of the button is a button, and the right side has a drop down menu.

To complete this, I create the button then I call ::SendMessage like so:

::SendMessage( hwndForButton, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS );

This works great and creates the split button, but also has the ill-effect of moving down the toolbar a couple pixels. If I don't send the message, then I still have the issue (and I don't have the split button anymore).

If I change the style of the button to BTNS_BUTTON|BTNS_WHOLEDROPDOWN then I don't have an issue, although I also don't have the split button.

Any clue as to what could be going wrong here? I figure there is a margin that is applied to a BNTS_DROPDOWN and it is causing the toolbar to move down.

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

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

发布评论

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

评论(2

叹倦 2024-07-20 15:16:22

嗯,这个问题确实非常,但由于它出现在有关该主题的谷歌结果的最顶部,并且为了将来进一步浏览参考,似乎有一种解决方法(引用自 http://www.ureader.com/msg/1484852.aspx):

"不知道为什么,但是当
我从一开始就设置了BTNS_DROPDOWN样式。 我如果添加
没有任何设置为 BTNS_DROPWN 的按钮,在下一行中我
使用 TB_SETBUTTONINFO 更改样式,一切正常。”

Well this question is very old indeed but since it appears at the very top of google results on the topic and for future reference browsing a little further it seems that there is one workaround (quoted from http://www.ureader.com/msg/1484852.aspx):

"Don't know why, but the problem rise when
I set the the BTNS_DROPDOWN style from the beginning. I've if add the
buttons without any of the set to BTNS_DROPWN and in the next line I
use TB_SETBUTTONINFO to change the style, everything works fine."

雪化雨蝶 2024-07-20 15:16:22

我们在 CToolBar 扩展上设置 BTNS_DROPDOWN 样式时遇到了同样的问题,当 DPI 缩放高于 100% 时,该问题变得更加明显。

floyd73 的链接似乎已损坏,但尝试通过 setbuttoninfo 单独设置下拉样式没有成功。

我们找到的解决方案是在设置样式后重新缩放工具栏,以使用 SetSizes() 考虑新的按钮大小:

auto imgList = GetToolBarCtrl().GetImageList();
if (imgList)
{
    //Scale toolbar buttons to fit the correct scaled icons
    CSize buttonSize(GetToolBarCtrl().GetButtonSize());
    CSize imageSize;
    ImageList_GetIconSize(imageList, &imageSize.cx, &imageSize.cy);

    SetSizes(buttonSize, imageSize);
}

我们将其插入到 NormalSize() 函数中,以便在任何自定义工具栏设置结束时使用,这应该允许我们捕捉任何其他有趣的按钮样式调整大小业务。

希望这可以帮助任何仍然面临同样问题的人。

We had the same issue with setting the BTNS_DROPDOWN style, on a CToolBar extension, which was being made more apparent when DPI scaling was above 100%.

floyd73's link seems to be broken, but having tried to set the dropdown style separately through setbuttoninfo didn't work.

The solution we found was to re-scale the toolbar after the styles have been set to take into account the new button sizes using SetSizes():

auto imgList = GetToolBarCtrl().GetImageList();
if (imgList)
{
    //Scale toolbar buttons to fit the correct scaled icons
    CSize buttonSize(GetToolBarCtrl().GetButtonSize());
    CSize imageSize;
    ImageList_GetIconSize(imageList, &imageSize.cx, &imageSize.cy);

    SetSizes(buttonSize, imageSize);
}

We stuck this into a NormalSize() function to use at the end of any custom toolbar setup, which should allow us to catch any other funny resizing business with button styles.

Hope this helps anyone still facing the same issue.

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