I have button on toolbar that can have image or/and drop down menu and I have the following code
int text_width = CalcTextWidth(); // this function use GetTextExtentPoint32
int image_width = CalcImageWidth();
then I set set button width as text_width + image_width, but in such formula the spaces between text/image and border are missed and also missed the size of dropdown arrow element.
What is the right way to calculate button width on toolbar
P.S. Button_GetIdealSize()
gives me more width than I need, because it use the max width of elements in drop down menu
Update: seems to me that there is no way 开发者_运维技巧to calc buttons correctly, but the BTNS_AUTOSIZE flag for button make most of what I need
Default button size?
may be this is the answer, I didn't check
HTHEME hTheme = NULL;
if(_ThemeHelper::IsAppThemed())
hTheme = _ThemeHelper::OpenThemeData(pInfo->hdr.hwndFrom, L"TOOLBAR");
if (hTheme)
{
CSize size(0, 0);
int state1 = (bHot && bSelected) ? TS_PRESSED : TS_HOT;
_ThemeHelper::GetThemePartSize(hTheme, dc, TP_SPLITBUTTONDROPDOWN, state1, 0, TS_TRUE, &size);
There are intersting answers
Since you mentioned it, what is the correct way to get the dropdown width in Windows 7? So far we’ve just had to swap out the TP_SPLITBUTTONDROPDOWN code with a constant.
Comment by Craig Peterson — Wednesday, 11 November 2009 @ 0:42
We use the ExpressBars library from Developer Express for the toolbars in RegexBuddy and RegexMagic. They fixed the issue in build 47. The fix is that they’re now using GetSystemMetrics(SM_CYHSCROLL) to get the drop-down button width when the operating system is Windows 7. I don’t know if this is going to be relevant to your code because they weren’t using TP_SPLITBUTTONDROPDOWN in the first place. Note that I’m talking about an actual combo box on a toolbar, not about a tool button with a drop-down menu.
Comment by Jan Goyvaerts — Wednesday, 11 November 2009 @ 9:59
from http://www.micro-isv.asia/2009/11/windows-7-is-to-vista-what-xp-was-to-2000/
精彩评论