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

    Question

  • 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
    Tuesday, November 03, 2009 8:11 PM

Answers

All replies

  • 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
    Tuesday, November 03, 2009 10:15 PM
  • 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
    Tuesday, November 03, 2009 11:28 PM
  • 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
    Wednesday, November 04, 2009 2:04 AM
  • 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.
    Wednesday, November 04, 2009 11:05 AM
  • 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
    Wednesday, November 04, 2009 8:50 PM
  • 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
    Thursday, November 05, 2009 1:37 AM
  • 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
    Thursday, November 05, 2009 3:18 AM
  • 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.
    Thursday, November 05, 2009 10:32 AM
  • 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
    Thursday, November 05, 2009 5:22 PM