一、了解下几个函数
1、movewindow
了解下:MoveWindow
自己塞进去的是屏幕坐标
CrvtFaultRodDlg* dlg = new CrvtFaultRodDlg();if (dlg != NULL){BOOL ret = dlg->Create(IDD_DlgCrvtFaultRod, NULL);if (ret) //Create failed.{RECT rect;{RECT rect1;dlg->GetWindowRect(&rect1);//获取窗口高宽int px = GetSystemMetrics(SM_CXFULLSCREEN);//获取屏幕高宽int py = GetSystemMetrics(SM_CYFULLSCREEN);int wx = rect1.right - rect1.left;int wy = rect1.bottom - rect1.top;rect.left = (px - wx) / 2;rect.top = (py - wy) / 2;rect.bottom = rect.top + wy;rect.right = rect.left + wx;}dlg->MoveWindow(&rect);dlg->ShowWindow(SW_SHOW);}}
2、GetWindowRect
了解下 GetWindowRect
获取 CWnd
的屏幕坐标
3、GetClientRect
了解下 GetClientRect
获取 CWnd
工作区的尺寸。
4、ClientToScreen
了解下 ClientToScreen
函数将指定点的工作区坐标转换为屏幕坐标
5、ScreenToClient
了解下 ScreenToClient
函数将屏幕上指定点的屏幕坐标转换为工作区坐标。
二、使用示例
1、对话框内使用(GetClientRect
)
RECT rect;GetWindowRect(&rect);
主窗口全屏,此时 rect 左,上,0,0 ;
主窗口不全屏,此时 rect 左,上,非0,非0 ;
因此上述用法不合理,需要将屏幕坐标统一转到工作区。使用ScreenToClient 。
RECT rect;GetWindowRect(&rect);ScreenToClient(&rect);bool BRe = mTab.Create( TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, // TCS_TABS 边框绘制rect, this, IDC_TABRod);if (!BRe) return;