谢谢!

解决方案 »

  1.   

    得到桌面窗口句柄->得到桌面窗口Rect->得到该窗口Rect->计算后SetWindowPos
      

  2.   

    类似代码
    nWidth  = (rChild.right - rChild.left);
           nHeight = (rChild.bottom - rChild.top);       // calculate parent window center point
           pCenter.x = rParent.left+((rParent.right
                     - rParent.left)/2);
           pCenter.y = rParent.top+((rParent.bottom
                     - rParent.top)/2);       // calculate message box starting point
           pStart.x = (pCenter.x - (nWidth/2));
           pStart.y = (pCenter.y - (nHeight/2));
        
           // adjust if message box is off desktop
           if(pStart.x < 0) pStart.x = 0;
           if(pStart.y < 0) pStart.y = 0;
           if(pStart.x + nWidth > rDesktop.right)
              pStart.x = rDesktop.right - nWidth;
           if(pStart.y + nHeight > rDesktop.bottom)
              pStart.y = rDesktop.bottom - nHeight;       // move message box
           MoveWindow(hChildWnd,
                      pStart.x, pStart.y,
                      nWidth, nHeight,
                      FALSE);具体的例子
    http://www.codeguru.com/Cpp/W-P/win32/messagebox/article.php/c4541/
      

  3.   

    void CenterWindow( CWnd* pAlternateOwner = NULL );
      

  4.   

    void CenterWindow( CWnd* pAlternateOwner = NULL );
    这个是子窗体位于主窗体的中央吧
      

  5.   

    算出来不就得了吗?
    HWND hChild;   //Child window handle.
    HWND hParent;  //Parent window handle.
    CSize size;
    CRect ChildRect;
    CRect ParentRect;
    GetWindowRect(hChild,&ChildRect);
    GetWindowRect(hParent,&ParentRect);size.cx = (ParentRect.right - ChildRect.right)/2;
    size.cy = (ParentRect.bottom - ChildRect.bottom)/2;
      

  6.   

    各位,关键是我没法取得哪个窗口的rect,取出来的数据是错的!
      

  7.   

    你首先要获得了窗口句柄,然后再用GetWindowRect去获得它的矩形尺寸!
      

  8.   

    取得桌面大小,然后用MoveWindow改变窗口位置
      

  9.   

    创建一个非模态窗口:CSize size;
    CRect ChildRect;
    CRect ParentRect;CDialog* pDlg = new CDialog();
    pDlg->Create(IDD_MYDIALOG,this);  //从资源中上装入对话框pDlg->GetWindowRect(&ChildRect);
    GetWindowRect(&ParentRect);size.cx = (ParentRect.right - ChildRect.right)/2;
    size.cy = (ParentRect.bottom - ChildRect.bottom)/2;pDlg->MoveWindow(size.cx,size.cx,ChildRect.right,ChildRect.bottom,TRUE);
    PDlg->ShowWindow(SW_SHOWNORMAL);
      

  10.   

    void CenterWindow(
       CWnd* pAlternateOwner = NULL 
    );
    //这个函数也可以帮你实现