C++ WinApi 中的 GetClientRect 和 GetWindowRect 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7561049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between GetClientRect and GetWindowRect in WinApi?
提问by Abzac
What of these should I use in InvalidateRect to refresh my window? And why?
我应该在 InvalidateRect 中使用哪些来刷新我的窗口?为什么?
回答by David Heffernan
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.
GetWindowRect
返回屏幕坐标中的矩形,而GetClientRect
返回客户端坐标中的矩形。
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
.
InvalidateRect
接收客户端坐标中的矩形。如果要使整个客户区无效,请传递NULL
到InvalidateRect
. 您可以传入由 返回的矩形GetClientRect
,但通过更简单明了NULL
。
回答by J?rgen Sigvardsson
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.
一个非常简单的解释是,它GetWindowRect()
为您提供了包含窗口边框的矩形。GetClientRect()
为您提供不包括边框的矩形 - 分配给窗口特定绘图的区域。
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.
请注意,GetWindowRect()
在屏幕坐标中返回一个矩形 - 相对于屏幕/显示器的坐标。GetClientRect()
返回一个相对于自身的矩形。
回答by ChrisF
GetClientRect
gets the coordinates of the window's client area. Specifically this is the area insidethe window chrome and excludesthe header etc. One of the comments on the MSDN pagesums it up quite well:
GetClientRect
获取窗口客户区的坐标。具体来说,这是窗口镶边内的区域,不包括标题等。MSDN 页面上的评论之一总结得很好:
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 includesthe header, status bar etc. However according to a comment on the MSDN page
GetWindowsRect
获取整个窗口的坐标。这包括标题、状态栏等。但是根据MSDN 页面上的评论
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.
Vista 下未与 WINVER=6 链接的应用程序将在此处收到一组误导性的值,这些值并未考虑 Vista Aero 应用于窗口的“玻璃”像素的额外填充。
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
.
因此,除非 Windows 7 已修复此问题,否则请仔细检查您获得的结果并确保您拥有正确的WINVER
.
回答by Marco
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.
来自 MSDN:
GetWindowRect
检索指定窗口的边界矩形的尺寸。尺寸以相对于屏幕左上角的屏幕坐标给出。
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).
GetClientRect
检索窗口客户区的坐标。客户坐标指定客户区的左上角和右下角。因为客户坐标相对于窗口客户区的左上角,所以左上角的坐标是 (0,0)。
More: client rect does not include title bar, borders, scroll bars, status bar...
更多:客户端矩形不包括标题栏、边框、滚动条、状态栏...