The ClientToScreen function replaces the client-area coordinates in the POINT structure with the screen coordinates. The screen coordinates are relative to the upper-left corner of the screen. Note, a screen-coordinate point that is above the window's client area has a negative y-coordinate. Similarly, a screen coordinate to the left of a client area has a negative x-coordinate.
The ScreenToClient member function replaces the screen coordinates given in lpPoint or lpRect with client coordinates. The new coordinates are relative to the upper-left corner of the CWnd client area.
实际就是一个屏幕坐标,一个客户区坐标,这两个坐标系统的转换
GetWindowRect得到的是screen coordinates. GetClientRect得到的是client-area coordinates,所以GetClientRect得到的总是以(0,0)为左上的点。
The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.
如果我们要获取一个窗口pWnd相对于父窗口parent客户区的位置应该是:
Rect rc;
pWnd->GetWindowRect(&rc);
parent->ScreenToClient(&rc);
如果如下:
pWnd->GetWindowRect(&rc);
pWnd->ScreenToClient(&rc);
得到的rc左顶坐标会出项负数,因为将自己的窗口往客户区映射,会出现标题栏/边框等的位置差错。