我发现用GetWindowRect(),对父窗口来说,左上角的坐标就是(0,0)
这不对啊
同时设置窗口在屏幕中的位置(相对于显示器左上角)用什么
RECT rect;
(GetDlgItem(IDC_BUTTON1))->GetWindowRect(&rect);
CString str;
str.Format("left = %d,top = %d,right = %d,bottom = %d",rect.left,rect.top,rect.right,rect.bottom);
AfxMessageBox(str);
GetWindowRect()后调用ClientToScreen();
设置窗口在屏幕中的位置(相对于
SetWindowPos();
设置窗口在屏幕中的位置(相对于
SetWindowPos();
设置窗口在屏幕中的位置(相对于显示器左上角)用什么函数呢?
MoveWindow() and SetWindowPos() both functions du the work.
父窗口和子窗口的屏幕坐标,就是相对于显示器左上角的坐标。
CWnd::GetWindowRect(&rect);//Get the coordinate relative the 显示器左上角.
CWnd::GetClientRect(&rect);//Get the coordinate of window.the value is
//(0,0,width,height)
CWnd::ScreenToClient();//change the screen
void CFlashDlg::LocateWnd()//设置窗口在屏幕中的位置
{
int sysMetrixX,sysMetrixY;
CRect NewWndRect,OldWndRect;
GetClientRect(&OldWndRect);
sysMetrixX=GetSystemMetrics(SM_CXSCREEN);
sysMetrixY=GetSystemMetrics(SM_CYSCREEN);
NewWndRect.left=(sysMetrixX-OldWndRect.Width())/2;
NewWndRect.top =(sysMetrixY-OldWndRect.Height())/2;
NewWndRect.right=NewWndRect.left+OldWndRect.Width();
NewWndRect.bottom=NewWndRect.top+OldWndRect.Height();
WINDOWPLACEMENT wndpl;
wndpl.length=sizeof(WINDOWPLACEMENT);
wndpl.flags=0;
wndpl.showCmd=SW_SHOWNORMAL;
wndpl.rcNormalPosition=NewWndRect;
SetWindowPlacement(&wndpl);
}
用GetWindowPlacement()也可以得到窗口的屏幕坐标
