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.
我有一个CToolbar,在其中我有一个样式为BTNS_BUTTON | BTNS_DROPDOWN的按钮。我想把它作为一个分割按钮,所以按钮的左侧是一个按钮,右侧有一个下拉菜单。
To complete this, I create the button then I call ::SendMessage like so:
为了完成这个,我创建了按钮,然后我调用:: SendMessage,如下所示:
::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.
如果我将按钮的样式更改为BTNS_BUTTON | BTNS_WHOLEDROPDOWN,那么我没有问题,虽然我也没有分割按钮。
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.
关于这里可能出现什么问题的任何线索?我认为有一个边距应用于BNTS_DROPDOWN,它导致工具栏向下移动。
2 个解决方案
#1
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):
那么这个问题确实非常陈旧,但由于它出现在谷歌搜索主题的最顶端以及将来的参考浏览中,似乎有一个解决方法(引自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."
“不知道为什么,但是当我从头开始设置BTNS_DROPDOWN样式时问题就出现了。如果没有任何设置的按钮添加到BTNS_DROPWN,我会在下一行使用TB_SETBUTTONINFO来改变样式,一切工作良好。”
#2
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%.
我们在CToolBar扩展上设置BTNS_DROPDOWN样式时遇到了同样的问题,当DPI缩放超过100%时,这个问题变得更加明显。
floyd73's link seems to be broken, but having tried to set the dropdown style separately through setbuttoninfo didn't work.
floyd73的链接似乎被打破,但试图通过setbuttoninfo分别设置下拉样式不起作用。
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():
我们找到的解决方案是在设置样式后使用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.
我们将它放入一个NormalSize()函数中,以便在任何自定义工具栏设置结束时使用,这应该允许我们使用按钮样式捕获任何其他有趣的调整大小业务。
Hope this helps anyone still facing the same issue.
希望这有助于任何人仍面临同样的问题。
#1
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):
那么这个问题确实非常陈旧,但由于它出现在谷歌搜索主题的最顶端以及将来的参考浏览中,似乎有一个解决方法(引自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."
“不知道为什么,但是当我从头开始设置BTNS_DROPDOWN样式时问题就出现了。如果没有任何设置的按钮添加到BTNS_DROPWN,我会在下一行使用TB_SETBUTTONINFO来改变样式,一切工作良好。”
#2
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%.
我们在CToolBar扩展上设置BTNS_DROPDOWN样式时遇到了同样的问题,当DPI缩放超过100%时,这个问题变得更加明显。
floyd73's link seems to be broken, but having tried to set the dropdown style separately through setbuttoninfo didn't work.
floyd73的链接似乎被打破,但试图通过setbuttoninfo分别设置下拉样式不起作用。
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():
我们找到的解决方案是在设置样式后使用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.
我们将它放入一个NormalSize()函数中,以便在任何自定义工具栏设置结束时使用,这应该允许我们使用按钮样式捕获任何其他有趣的调整大小业务。
Hope this helps anyone still facing the same issue.
希望这有助于任何人仍面临同样的问题。