【问题标题】:FillRect doesn't work in some caseFillRect 在某些情况下不起作用
【发布时间】:2015-01-11 15:28:08
【问题描述】:

在我的代码中:

void Surface::paintBorders(const Color& color, int borderWidth){
HBRUSH colorBrush = CreateSolidBrush(color.getRGB());
RECT border;

//Top Border:
border.top = 0;
border.bottom = borderWidth;
border.left = 0;
border.right = mRect.right - mRect.left;
FillRect(mHDC, &border, colorBrush);

//Bottom border
border.top = mRect.bottom - mRect.top - borderWidth;
border.bottom = mRect.bottom - mRect.top;
border.left = 0;
border.right = mRect.right - mRect.left;
FillRect(mHDC, &border, colorBrush);

//Right border
border.top = 0;
border.bottom = mRect.bottom - mRect.top;
border.left = mRect.right - mRect.left - borderWidth;
border.right = mRect.right - mRect.left;
FillRect(mHDC, &border, colorBrush);

//Left border
border.top = 0;
border.bottom = mRect.bottom - mRect.top;
border.left = 0;
border.right = borderWidth;
FillRect(mHDC, &border, colorBrush);

DeleteObject(colorBrush);

}

只有顶部和左侧边框被绘制,底部和右侧不被绘制。 我引用 MSDN:

此函数包含矩形的左边框和上边框,但不包括矩形的右边框和下边框。

不知道有没有关系。 我确信所有的协调都正常,还有 HDC 和 HBRUSH 参数。 有什么想法吗?

【问题讨论】:

  • 很明显你的计算有点不对劲。尝试将右下边框向左和上移。
  • 您只展示了部分代码。我们只能猜测具体情况。为什么不展示一个完整的程序?

标签: c++ c winapi user-interface window


【解决方案1】:

好的,伙计们,我得到了答案,显然 rect 是由 GetWindowRect 而不是 GetClientRect 检索到的,这弄乱了所有的协调

【讨论】:

  • 你应该删除这个问题。对未来的访问者没有任何价值,问题中没有任何内容涉及 GetWindowRect 或 GetClientRect。
猜你喜欢
  • 2018-11-28
  • 2011-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-17
  • 2017-06-29
  • 1970-01-01
  • 2019-07-11
相关资源
最近更新 更多