是否有 API 调用来确定窗口标题按钮的大小和位置?我正在尝试将 vista 风格的标题按钮绘制到所有者绘制的窗口上。我正在处理c/c++/mfc。

编辑:有人有绘制关闭按钮的代码示例吗?

有帮助吗?

解决方案

我找到了获取 vista 中按钮位置所需的函数: WM_GETTITLEBAINFOEX

此链接还显示了使所有间距正确所需的系统指标(遗憾的是它不是完整的对话框图片)。这在 Vista 中完美运行,并且大多数在 XP 中(在 XP 中按钮之间的间隙稍微太大)。

From http://shellrevealed.com/photos/blog_images/images/4538/original.aspx

其他提示

GetSystemMetrics的给出了所有这些信息。到窗口装饰画中,使用 GetWindowDC

下面的代码适于从所述“全局标题栏挂钩”例如我发现在的http:// WWW .catch22.net /内容/段的。我修改的例子,使其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();
 }
}

GetSystemMetrics的功能来帮助你完成一个尺寸(SM_CYSIZE和SM_CXSIZE参数)。

修改

我不知道你能找到这个功能位置,但你可能会看一看的激流源代码时,他们已经成功地将按钮添加到窗口标题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top