是否有API调用来确定窗口标题按钮的大小和位置?我正在尝试将vista样式的标题按钮绘制到所有者绘制的窗口上。我正在处理c/c++/mfc。
编辑:有没有人有绘制关闭按钮的代码示例?
发布于 2009-01-26 11:42:52
我已经找到了在vista中获取按钮位置所需的函数:WM_GETTITLEBARINFOEX
此链接还显示了使所有间距正确所需的系统指标(遗憾的是,这不是完整的对话框图片)。这在Vista中工作得很好,尤其是在XP中(在XP中,按钮之间的间隙略大)。

发布于 2009-01-26 10:28:41
GetSystemMetrics提供了所有这些信息。要在窗口装饰内绘制,请使用GetWindowDC。
发布于 2009-09-15 07:19:41
下面的代码改编自我在http://www.catch22.net/content/snippets找到的“全局标题栏钩子”示例。我修改了这个示例,使其对MFC友好。它返回最左边标题栏按钮的X坐标,但是可以很容易地修改它来找到任何按钮的位置。
#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();
}
}https://stackoverflow.com/questions/479332
复制相似问题