void CMy2011_12_03_oneDlg::OnButtonTest()
{
// TODO: Add your control notification handler code here
CRect rectEdit;
CRect rectDlg;
CWnd *pWnd = GetDlgItem(IDC_EDIT);
pWnd->GetClientRect(rectEdit);//此时获取到的结果只是相对于本控件(IDC_EDIT)区域,本控件的左上角为(0, 0)
//top = 0 left = 0 bottom = 控件高度 right = 控件宽度
pWnd->ClientToScreen(rectEdit);//屏幕坐标,此时参考点为屏幕左上角(0,0)点。
//控件相对于屏幕的左边位置。此时top left bottom right都发生变化,但是控件的
//高度以及宽度不变。
GetClientRect(rectDlg);
ClientToScreen(rectDlg);
int x = rectEdit.left - rectDlg.left;//文本框控件IDC_EDIT在对话框中X坐标
int y = rectEdit.top - rectDlg.top;//文本框控件IDC_EDIT在对话框中Y坐标
}
VC屏幕坐标与窗口坐标
最新推荐文章于 2021-05-18 21:51:16 发布