有没有API调用可以确定窗口标题按钮的大小和位置?我正在尝试在自绘窗口上绘制Vista风格的标题按钮。我的问题涉及C/C++/MFC。
编辑:有没有人有绘制关闭按钮的代码示例?
有没有API调用可以确定窗口标题按钮的大小和位置?我正在尝试在自绘窗口上绘制Vista风格的标题按钮。我的问题涉及C/C++/MFC。
编辑:有没有人有绘制关闭按钮的代码示例?
我已找到获取Vista按钮位置所需的函数:WM_GETTITLEBARINFOEX
此链接还显示了获取所有间距正确的系统度量标准(可惜不是完整的对话框图片)。这在Vista中完美运作,在XP中大部分情况下也可以(但在XP中,按钮之间存在稍微过大的间隙)。
GetSystemMetrics 函数可以提供所有这些信息。如果要在窗口装饰内绘图,请使用 GetWindowDC 函数。
#define B_EDGE 2
int CMyWindow::CalcRightEdge()
{
if(GetStyle() & WS_THICKFRAME)
return GetSystemMetrics(SM_CXSIZEFRAME);
else
return GetSystemMetrics(SM_CXFIXEDFRAME);
}
int CMyWindow::findNewButtonPosition()
{
int nButSize = 0;
DWORD dwStyle = GetStyle();
DWORD dwExStyle = GetExStyle();
if(dwExStyle & WS_EX_TOOLWINDOW)
{
int nSysButSize = GetSystemMetrics(SM_CXSMSIZE) - B_EDGE;
if(GetStyle() & WS_SYSMENU)
nButSize += nSysButSize + B_EDGE;
return nButSize + CalcRightEdge();
}
else
{
int nSysButSize = GetSystemMetrics(SM_CXSIZE) - B_EDGE;
// Window has Close [X] button. This button has a 2-pixel
// border on either size
if(dwStyle & WS_SYSMENU)
nButSize += nSysButSize + B_EDGE;
// If either of the minimize or maximize buttons are shown,
// Then both will appear (but may be disabled)
// This button pair has a 2 pixel border on the left
if(dwStyle & (WS_MINIMIZEBOX | WS_MAXIMIZEBOX) )
nButSize += B_EDGE + nSysButSize * 2;
// A window can have a question-mark button, but only
// if it doesn't have any min/max buttons
else if(dwExStyle & WS_EX_CONTEXTHELP)
nButSize += B_EDGE + nSysButSize;
// Now calculate the size of the border...aggghh!
return nButSize + CalcRightEdge();
}
}
GetSystemMetrics函数应该可以帮助您确定大小(使用SM_CYSIZE和SM_CXSIZE参数)。
编辑
我不确定您是否可以使用此函数查找位置,但您可以查看emule源代码,他们已成功将按钮添加到窗口标题中。