如何获取窗口标题按钮的大小和位置(最小化,恢复,关闭)

问题描述 投票:5回答:4

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

编辑:有没有人有一个代码示例来绘制关闭按钮?

c++ winapi mfc windows-vista uxtheme
4个回答
6
投票

我已经找到了在vista中获取按钮位置所需的功能:WM_GETTITLEBARINFOEX

此链接还显示了使所有间距正确所需的系统指标(尽管它不是完整的对话框图片)。这在Vista中完美地运行,并且主要在XP中(在XP中,按钮之间的间隙略微过大)。

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


3
投票

GetSystemMetrics提供了所有这些信息。要在窗口装饰内绘制,请使用GetWindowDC


1
投票

以下代码改编自我在http://www.catch22.net/content/snippets发现的“Global Titlebar Hook”示例。我修改了示例以使其对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();
 }
}

0
投票

GetSystemMetrics函数应该帮助你一个大小(SM_CYSIZE和SM_CXSIZE参数)。

编辑

我不确定你能找到这个功能的位置,但是你可以看看emule source code,他们设法在窗口标题上添加了一个按钮。

© www.soinside.com 2019 - 2024. All rights reserved.