一、了解下几个函数
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
获取 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);
ScreenToClient2(rect);
bool BRe = mTab.Create( TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, // TCS_TABS 边框绘制
rect, this, IDC_TABRod);
if (!BRe) return;
2、GetTitleBarInfo
void ScreenToClient2(RECT& rect)
{
ScreenToClient(&rect);
TITLEBARINFO re;
re.cbSize = sizeof(TITLEBARINFO);
if (GetTitleBarInfo(&re))
{
RECT& rcTitleBar = re.rcTitleBar;
ScreenToClient(&rcTitleBar);
rect.top = rect.top + abs(rcTitleBar.top) + 5;
rect.bottom = rect.bottom + abs(rcTitleBar.bottom) + 5;
}
}