WinApi 中的 GetClientRect 和 GetWindowRect 有什么区别?

发布于 2024-12-06 21:42:51 字数 44 浏览 6 评论 0原文

我应该在 InvalidateRect 中使用哪些来刷新我的窗口?为什么?

What of these should I use in InvalidateRect to refresh my window? And why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

两仪 2024-12-13 21:42:51

窗口矩形包括非客户区域,即窗口边框、标题栏等。客户矩形不包括。

GetWindowRect 返回屏幕坐标中的矩形,而 GetClientRect 返回客户端坐标中的矩形。

InvalidateRect 接收客户端坐标中的矩形。如果您想要使整个客户区无效,请将 NULL 传递给 InvalidateRect。您可以传入 GetClientRect 返回的矩形,但传递 NULL 更简单、更清晰。

The window rect includes the non-client area, i.e. the window borders, caption bar etc. The client rect does not.

GetWindowRect returns a rect in screen coordinates whereas GetClientRect returns a rect in client coordinates.

InvalidateRect receives a rect in client coordinates. If you want to invalidate your entire client area, then pass NULL to InvalidateRect. You could pass in the rect returned by GetClientRect, but it is far simpler and clearer to pass NULL.

清泪尽 2024-12-13 21:42:51

一个非常简单的解释是,GetWindowRect() 为您提供包含窗口边框的矩形。 GetClientRect() 为您提供不包括边框的矩形 - 分配给窗口特定绘图的区域。

请注意,GetWindowRect() 返回屏幕坐标中的矩形 - 相对于屏幕/监视器的坐标。 GetClientRect() 返回一个相对于自身的矩形。

A very simple explanation is that GetWindowRect() gives you the rectangle that includes the borders of the window. GetClientRect() gives you the rectangle that excludes the borders - the area that is allocated to the window specific drawing.

Please note that GetWindowRect() returns a rectangle in screen coordinates - coordinates that are relative to the screen/monitor. GetClientRect() returns a rectangle that is relative to itself.

执手闯天涯 2024-12-13 21:42:51

GetClientRect 获取窗口客户区的坐标。具体来说,这是窗口镶边内部区域,并且排除标题等。 MSDN 页面 总结得很好:

我想说这个函数返回我可以渲染到的区域的大小。

GetWindowsRect 获取整个窗口的坐标。这包括标题、状态栏等。但是根据MSDN 页面

Vista 下未与 WINVER=6 链接的应用程序将在此处收到一组误导性的值,这些值不考虑 Vista Aero 应用于窗口的“玻璃”像素的额外填充。

因此,除非 Windows 7 已修复此问题,否则请仔细检查您获得的结果并确保您拥有正确的 WINVER 值。

GetClientRect gets the coordinates of the window's client area. Specifically this is the area inside the window chrome and excludes the header etc. One of the comments on the MSDN page sums it up quite well:

I would say that this function return size of the area that I can render to.

GetWindowsRect gets the coordinates of the whole window. This includes the header, status bar etc. However according to a comment on the MSDN page

Apps under Vista that are not linked with WINVER=6 will receive a misleading set of values here, that do not account for the extra padding of "glass" pixels Vista Aero applies to the window.

So unless this have been fixed for Windows 7 double check the result you get and make sure you have the correct value of WINVER.

我很坚强 2024-12-13 21:42:51

来自 MSDN:
获取窗口矩形
检索指定窗口的边框的尺寸。尺寸以相对于屏幕左上角的屏幕坐标给出。

获取客户端矩形
检索窗口客户区的坐标。客户坐标指定客户区域的左上角和右下角。因为客户坐标是相对于窗口客户区域的左上角的,所以左上角的坐标是(0,0)。

更多:客户端矩形不包括标题栏、边框、滚动条、状态栏...

From MSDN:
GetWindowRect
Retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.

GetClientRect
Retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).

More: client rect does not include title bar, borders, scroll bars, status bar...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文