请问CFileDialog如何设定它的窗口弹出位置?
下面代码,不能实现,请只教:CFileDialog Dlg(true,NULL, ExtendName.c_str(), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
ExtendShow.c_str(), CWnd::FromHandle(m_hWnd) );
RECT rc;
Dlg.GetWindowRect(&rc);
int x=(MainFrameRect.right-MainFrameRect.left)/2-(rc.right-rc.left)/2;
int y=(MainFrameRect.bottom-MainFrameRect.top)/2-(rc.bottom-rc.top)/2;
Dlg.MoveWindow(x,y,(rc.right-rc.left),(rc.bottom-rc.top),false);

CString DlgFileName;
if(Dlg.DoModal()==IDOK)
{
DlgFileName=Dlg.GetPathName();
}

解决方案 »

  1.   

    窗口还没有创建,不能调用MoveWindow方法。
      

  2.   

    CFileDialog Dlg(true,NULL, ExtendName.c_str(), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,ExtendShow.c_str(), CWnd::FromHandle(m_hWnd) );

    CString DlgFileName;
    if(Dlg.DoModal()==IDOK)
    {
    DlgFileName=Dlg.GetPathName();
    }
    RECT rc;
    Dlg.GetWindowRect(&rc);
    int x=(MainFrameRect.right-MainFrameRect.left)/2-(rc.right-rc.left)/2;
    int y=(MainFrameRect.bottom-MainFrameRect.top)/2-(rc.bottom-rc.top)/2;
    Dlg.MoveWindow(x,y,(rc.right-rc.left),(rc.bottom-rc.top),false);这样也不行啊?为什么呢?
      

  3.   

    RECT rc;
    Dlg.GetWindowRect(&rc);
    int x=(MainFrameRect.right-MainFrameRect.left)/2-(rc.right-rc.left)/2;
    int y=(MainFrameRect.bottom-MainFrameRect.top)/2-(rc.bottom-rc.top)/2;
    Dlg.MoveWindow(x,y,(rc.right-rc.left),(rc.bottom-rc.top),false);if(Dlg.DoModal()==IDOK)
    {
    DlgFileName=Dlg.GetPathName();
    }
      

  4.   

    CFileDialog Dlg(true,NULL, ExtendName.c_str(), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,ExtendShow.c_str(), CWnd::FromHandle(m_hWnd) );

    CString DlgFileName;
    if(Dlg.DoModal()==IDOK)
    {
    DlgFileName=Dlg.GetPathName();
    }
    RECT rc;
    Dlg.GetWindowRect(&rc);
    int x=(MainFrameRect.right-MainFrameRect.left)/2-(rc.right-rc.left)/2;
    int y=(MainFrameRect.bottom-MainFrameRect.top)/2-(rc.bottom-rc.top)/2;
    Dlg.MoveWindow(x,y,(rc.right-rc.left),(rc.bottom-rc.top),false);不能弹出窗体,请只教,谢谢!!!!!!!!!1
      

  5.   

    CFileDialog Dlg(true,NULL, ExtendName.c_str(), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,ExtendShow.c_str(), CWnd::FromHandle(m_hWnd) );CString DlgFileName;
    if(Dlg.DoModal()==IDOK)//单击OK后,窗口都消失了,以后再移动窗口位置当然不行了
    {
    DlgFileName=Dlg.GetPathName();
    }
    RECT rc;
    Dlg.GetWindowRect(&rc);
    int x=(MainFrameRect.right-MainFrameRect.left)/2-(rc.right-rc.left)/2;
    int y=(MainFrameRect.bottom-MainFrameRect.top)/2-(rc.bottom-rc.top)/2;
    Dlg.MoveWindow(x,y,(rc.right-rc.left),(rc.bottom-rc.top),false);
      

  6.   

    有一个偏门的方法,不知你愿不愿试
    将你的CFileDialog定义为成员指针变量
    CFileDialog* m_pdlg;
    在你要显示对话框的函数中SetTimer(102, 10, NULL);m_pdlg = new CFileDialog(true,NULL, ExtendName.c_str(), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,ExtendShow.c_str(), CWnd::FromHandle(m_hWnd) );
    m_pdlg->DoModal();
    delete m_pdlg;然后,响应WM_TIMER消息
    在该消息处理函数中加上
    if(nIDEvent == 102){
      KillTimer(nIDEvent);
      int x=(MainFrameRect.right-MainFrameRect.left)/2-(rc.right-rc.left)/2;
      int y=(MainFrameRect.bottom-MainFrameRect.top)/2-(rc.bottom-rc.top)/2;      m_pdlg->GetParent()->SetWindowPos(NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
    }当然,你也可以派生CFileDialog,进行移动
    可能也可以写OPENFILENAME的LPOFNHOOKPROC,不过没试过,不知道成不成
      

  7.   

    OPENFILENAME OpenFileName;   
    CHAR szFile[MAX_PATH]      = "\0";  
    CHAR szSystem32[MAX_PATH];    
    strcpy( szFile, "");   
    ZeroMemory(&OpenFileName, sizeof(OPENFILENAME));   
    // 填充 OPENFILENAME 结构以支持模板和挂接。   
    OpenFileName.lStructSize       = sizeof(OPENFILENAME);  
    OpenFileName.hwndOwner         = this->GetSafeHwnd();    
    OpenFileName.hInstance         = NULL;    
    OpenFileName.lpstrFile         = szFile;  
    OpenFileName.nMaxFile          = sizeof(szFile);    
    OpenFileName.lpstrTitle        = "Select a File";    
    OpenFileName.Flags             = OFN_FILEMUSTEXIST;      szSystem32[0] = '\0';   
       OpenFileName.lpstrInitialDir   = szSystem32;
       // 调用公共对话函数。    
       if (GetOpenFileName(&OpenFileName))
    请问如何设定上面对话框的位置?