MFC Doc/View: How to modify the default 'Open' dialog?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: MFC Doc/View: How to modify the default 'Open' dialog?

Hybrid View

  1. #1
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    MFC Doc/View: How to modify the default 'Open' dialog?

    Q: How to modify the default 'Open' dialog?

    A:
    • Delete or comment the following line added in message map of CWinApp-derived class by the AppWizard:
      Code:
      ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
    • Using ClassWizard map yourself ID_FILE_OPEN command

    • Write this code in ID_FILE_OPEN handler function:
      Code:
      void CMyApp::OnFileOpen() 
      {
         LPCTSTR pszFilter = 
            _T("Bitmap files (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|")
            _T("JPEG files (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif||");
      
         CFileDialog dlgFile(TRUE, NULL, NULL, 
                             OFN_HIDEREADONLY,
                             pszFilter,
                             AfxGetMainWnd());
      
         if(IDOK == dlgFile.DoModal())
         {
            OpenDocumentFile(dlgFile.GetPathName());
         }
      }



    Last edited by Andreas Masur; September 18th, 2005 at 05:08 PM.

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: MFC Doc/View: How to modify the default 'Open' dialog?

    A:
    Another solution is to derive from CDocManager and override CDocManager::DoPromptFileName.
    In the overridden DoPromptFileName, we can either write our own implementation or modify some parameters then call the base class method.
    Finally, in InitInstance of application, replace the call to AddDocTemplate as shown below.

    Next example changes the default dialog title and shows "Help" button.
    Code:
    class CCustomDocManager : public CDocManager
    {
    public:
       virtual BOOL DoPromptFileName(CString& fileName, UINT nIDSTitle,
                   DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate);
    };
    Code:
    BOOL CCustomDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle,
                   DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
    {
       // set the custom title
       nIDSTitle = bOpenFileDialog ? IDS_CUSTOM_OPEN_TITLE : IDS_CUSTOM_SAVEAS_TITLE;
       // add "show Help button" flag
       lFlags |= OFN_SHOWHELP;          
       // call the base class function
       return CDocManager::DoPromptFileName(fileName, nIDSTitle,
                                     lFlags, bOpenFileDialog, pTemplate);
    }
    Code:
    BOOL CMyApp::InitInstance()
    {
    // ...
       // AddDocTemplate(pDocTemplate); // <-- replace this
       if (m_pDocManager == NULL)
       {
          m_pDocManager = new CCustomDocManager;
       }
       m_pDocManager->AddDocTemplate(pDocTemplate);
    // ...
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center