VC ScreenToClient与ClientToScreen

13 篇文章 0 订阅

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左顶坐标会出项负数,因为将自己的窗口往客户区映射,会出现标题栏/边框等的位置差错。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值