ClientToScreen ScreenToClient MoveWindow

本文详细介绍了在窗口布局中如何使用按钮的坐标转换、窗口移动等操作,通过实例展示了如何将按钮从屏幕坐标转换为窗口客户区坐标,并进行移动。涵盖了`ClientToScreen`、`ScreenToClient`和`MoveWindow`等关键函数的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


RECT rect;//LEFT,TOP,RIGHT,BOTTOM

1.ClientToScreen
GetDlgItem(IDOK)->GetClientRect(&rect);//获得按钮大小rect(0,0,101,29)
GetDlgItem(IDOK)->ClientToScreen(&rect);//获得按钮在屏幕中的坐标

// -----------------------------------------------------------------------------------------------


GetDlgItem(IDOK)->GetClientRect(&rect);//获得按钮大小坐标rect(0,0,101,29)
this->ClientToScreen(&rect);//J将dlg窗口客户区中的rect(0,0,101,29)坐标转化成屏幕坐标
//-----------------------------------------------------------------------------


2.ScreenToClient

GetDlgItem(IDOK)->GetWindowRect(&rect);//获得按钮屏幕坐标rect(100,100,201,129)
this->ScreenToClient(&rect);//将按钮屏幕坐标rect(100,100,201,129)转换成在dlg窗口客户区中的坐标
this->MoveWindow(&rect);//dlg移动到该坐标范围(0,0,101,29)

GetDlgItem(IDOK)->MoveWindow(&rect);//将按钮移动到dlg客户区中该位置
//------------------------------------------------------------------------------------------------------

GetDlgItem(IDOK)->GetWindowRect(&rect);//获得按钮屏幕坐标rect(100,100,201,129)
GetDlgItem(IDOK)->ScreenToClient(&rect);//将按钮屏幕坐标rect(100,100,201,129)转换成在按钮窗口客户区中的坐标(0,0,101,29)

rect.right += 10;
GetDlgItem(IDOK)->MoveWindow(&rect);//将按钮移动到dlg客户区中该位置

//----------------------------------------------------------------------------------------------------------

this->GetWindowRect(&rect);//获得dlg屏幕坐标rect(100,100,201,129)
this->ScreenToClient(&rect);//将按钮屏幕坐标rect(100,100,201,129)转换成在dlg窗口客户区中的坐标(-3,-22,300,100)

3.MoveWindow

//For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. 
//For a child window, they are relative to the upper-left corner of the parent window's client area.

this->MoveWindow(&rect);//dlg移动到该坐标范围(0,0,101,29)

GetDlgItem(IDOK)->MoveWindow(&rect);//将按钮移动到dlg客户区中该位置



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值