窗口本身有标题栏和框架的高度和宽度,所以你执行MoveWindow之后会出现偏差。
需要减去相应的坐标,rec.top需要减掉标题栏的高度,rec.left需要减掉窗口的边框宽度。边框的宽度可以用GetClientRect和GetWindowRect得到的Width()之差/2取得。
处理起来就是这样的:
CRect rc;
CRect rcWnd;
         CRect rcClient;
         int nBorderWidth;
  ::GetClientRect(this->GetSafeHwnd(),&rcClient);
         ::GetWindowRect(this->GetSafeHwnd(),&rcWnd);
  ::GetWindowRect(GetDlgItem(IDC_EDIT1)->GetSafeHwnd(),&rc);
         nBorderWidth = (rcWnd.Width() - rcClient.Width()) / 2;
  ::MoveWindow( GetDlgItem(IDC_EDIT2)->GetSafeHwnd(),rc.left - nBorderWidth  - rcClient.left,rc.top - nBorderWidth  - rcClient.top,rc.Width() ,rc.Height() ,TRUE);