基于单文档的程序,我想把对话框移动跟视图区的左上对齐,怎样在对话框类中得到view左上角的坐标。this->GetParentWindow()->GetActiveView()->GetClientRect(&rt);
this->MoveWindow(rt.Left, rt.top ,...);不行,怎么弄???

解决方案 »

  1.   

    能否保证Parent关系?如果不能,
    可以使用AfxGetMainWnd()或者AfxGetApp()->m_pMainwnd得到主窗体,
    再以此获取视图。
      

  2.   

    GetClientRect得到的总是以(0,0)为左上角的。
    试用GetWindowRect及ScreenToClient组合。
      

  3.   

    extern CMainFrame* g_pMainFrame;    //全局变量,指向主框架。void CDlg1::OnShowWindow(BOOL bShow, UINT nStatus) 
    {
    CDialog::OnShowWindow(bShow, nStatus);

    // TODO: Add your message handler code here
    CRect rcTemp, rcDes,rcParent;
    this->GetWindowRect(&rcTemp); g_pMainFrame->GetActiveView()->GetWindowRect(&rcParent);
    rcDes.left = rcParent.left;
    rcDes.top = rcParent.top;
    rcDes.right = rcDes.left + rcTemp.Width();
    rcDes.bottom = rcDes.top + rcTemp.Height(); this->MoveWindow(rcDes, TRUE);

    }
      

  4.   

    CMainFrame* g_pMainFrame;
    void CMainFrame::OnMovdlg()     //菜单消息处理函数
    {
    // TODO: Add your command handler code here
    g_pMainFrame = this;
    CMovDlg dlg;
    dlg.DoModal();}
    ///////////////////////////////////////////////////
    BOOL CMovDlg::OnInitDialog() 
    {
    CDialog::OnInitDialog();

    // TODO: Add extra initialization here
    extern CMainFrame* g_pMainFrame; 
    CRect rcTemp, rcDes,rcParent;
    this->GetWindowRect(&rcTemp); g_pMainFrame->GetActiveView()->GetWindowRect(&rcParent);
    rcDes.left = rcParent.left;
    rcDes.top = rcParent.top;
    rcDes.right = rcDes.left + rcTemp.Width();
    rcDes.bottom = rcDes.top + rcTemp.Height(); this->MoveWindow(rcDes, TRUE);
    return TRUE;  
    }