Microsoft Developer Network > Forenhomepage > Visual C++ General > How to change a current directory from a CFileDialog-based class after the call to DoModal()?
Stellen Sie eine FrageStellen Sie eine Frage
 

BeantwortetHow to change a current directory from a CFileDialog-based class after the call to DoModal()?

  • Dienstag, 3. November 2009 20:11mfaynberg TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hello everyone!
    I am using VS2008/C++ on Windows XP platform.
    I have a class derived from CFileDialog. I have added a combobox to this dialog, which containg a list of the most recently used directories - to simplify the navigation. After a user makes his choice, the dialog has to switch to a selected location. How to force the dialog to do it?
    Thank you in advance,
    Mike

    Mike Faynberg

Antworten

Alle Antworten

  • Dienstag, 3. November 2009 22:15Sheng Jiang 蒋晟MVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    No API exists. You can send the undocumented WM_USER+7 to get a IShellBrowser interface, but that may break in a Windows Update.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
  • Dienstag, 3. November 2009 23:28mfaynberg TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Sheng Jiang,

    thank you so much!

    It is a bit disappointing... I wanted actually to create something like MRU but for locations, not for files... Anyway - I have never used the IShellBrowser interface before. Could you refer me to an example: how to change a working directory in the case like this?

    Best regards,

    Mike

    Mike Faynberg
  • Mittwoch, 4. November 2009 02:04Sheng Jiang 蒋晟MVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Vorgeschlagene Antwort
    Search for IShellBrowser cfiledialog.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
  • Mittwoch, 4. November 2009 11:05Rong-Chun ZhangMSFT, ModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    Hello Mike,

    >Could you refer me to an example: how to change a working directory in the case like this?

    Please take a look at the following article.
    http://www.codeproject.com/KB/dialog/select_all_button.aspx

    It shows us how to add a select all button to CFileDialog with the help of IShellBrowser interface.

    Besides Sheng's suggestion, another idea is add the recent location to the Favorite Links of the CFileDialog. For example
    http://www.insidercoding.com/post/2008/07/16/Tutorial-Adding-a-Custom-Place-to-CFileDialog.aspx

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Mittwoch, 4. November 2009 20:50mfaynberg TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Enthält Code
    Hello Sheng Jiang and Rong-Chun Zgang,

    I greatly appreciate your input.

    Actually I figured it out myself... It looks like follows:
    /*
    #define WM_UNDOCUMENTED (WM_USER + 7)
    */
    IShellBrowser *pSB = (IShellBrowser *)GetParent()->SendMessage( WM_UNDOCUMENTED, 0, 0 );
    if( pSB != 0 )
    {
            CStringW sw( strNewDirectory );
    	PIDLIST_ABSOLUTE pidl;
    	DWORD flags = SFGAO_FOLDER;
    	HRESULT hr = SHILCreateFromPath( sw, &pidl, &flags );
    	ASSERT( hr == S_OK );
    	flags = SBSP_SAMEBROWSER | SBSP_DEFMODE | SBSP_ABSOLUTE;
    	hr = pSB->BrowseObject( pidl, flags );
    		                                // The call works fine, but returns
    		                                // ... S_FALSE
    //	ASSERT( hr == S_OK );
    }
    
    
    The only minor problem - like one can see from comments - is that the call to BrowseObject() returns S_FALSE, despite that works fine.
    Why? Any misunderstanding on my side regarding flags definition, or something else?

    Best regards and thank you once more,

    Mike



    Mike Faynberg
  • Donnerstag, 5. November 2009 01:37Sheng Jiang 蒋晟MVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    use SUCCEEDED(hr) or FAILED(hr) to determine success or failure. Error codes generally begins with E_.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
  • Donnerstag, 5. November 2009 03:18mfaynberg TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hello Sheng Jiang,

    thank you for your help! It is OK now. Hopefully even if Microsoft breaks this undocumented option later, they will give us something different in order to keep the functionality

    Best regards,

    MIke


    Mike Faynberg
  • Donnerstag, 5. November 2009 10:32Rong-Chun ZhangMSFT, ModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hello Mike,

    Is the issue resloved? If there is anything we can help, welcome to post here.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Donnerstag, 5. November 2009 17:22mfaynberg TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hi Rong-Chun Znang,

    Yes it is resolved - at least until it breaks (hopefully not!) after some Microsoft update.

    Thank you so much!

    Mike


    Mike Faynberg