c++ - Win32中的窗口边框宽度和高度 - 我如何获得它?

标签 c++ winapi

      ::GetSystemMetrics (SM_CYBORDER)

...返回 1,我知道标题栏比 ONE 像素高:/

我也试过了:

     RECT r;
      r.left = r.top = 0;   r.right = r.bottom = 400;
      ::AdjustWindowRect (& r, WS_OVERLAPPED, FALSE);
      _bdW = (uword)(r.right - r.left - 400);
      _bdH = (uword)(r.bottom - r.top - 400);

但是边框 w,h 回来为 0。

在我的 WM_SIZE 处理程序中,我需要确保窗口的高度在 “步骤”,例如,一个全新的文本行可以适合窗口 底部没有“垃圾部分行空间”。

但是::MoveWindow 需要添加边框空间的尺寸。

之前一定有人这样做过... 感谢您的帮助:)

最佳答案

GetWindowRectGetClientRect函数可用于计算所有窗口边框的大小。

Suite101 有一篇关于 resizing a window and the keeping client area at a know size 的文章.

这是他们的示例代码:

void ClientResize(HWND hWnd, int nWidth, int nHeight)
{
  RECT rcClient, rcWind;
  POINT ptDiff;
  GetClientRect(hWnd, &rcClient);
  GetWindowRect(hWnd, &rcWind);
  ptDiff.x = (rcWind.right - rcWind.left) - rcClient.right;
  ptDiff.y = (rcWind.bottom - rcWind.top) - rcClient.bottom;
  MoveWindow(hWnd,rcWind.left, rcWind.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
}

关于c++ - Win32中的窗口边框宽度和高度 - 我如何获得它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/431470/

相关文章:

visual-studio-2008 - Windows 是否在应用程序中预加载 ComCtrl32.dll?

delphi - 将 WinAPI 回调封装在类中的最优雅的方法

c++ - 不同线程间的互斥锁同步

c++ - 逗号作为分隔符和运算符

c++ - 更好地提升 asio deadline_timer 示例

c# - 如何使用 C# 拦截 Win32 API 调用?

c++ - 获取 Windows 监视器的唯一标识符

c++ - 从结构启动 Cuda Call

c++ - 签名EXE是否解决安全警告

c++ - -读取字符串字符时出错