Link to home
Start Free TrialLog in
Avatar of ernan
ernan

asked on

CFileDialog changing default directory

I have a class derived from CFileDialog. I have inserted a CComboBox at the bottom of the dialog. In the added combo box are a list of previously used directories for saving reading.
What I want to do is when somebody selects a directory on the ComboBox this will change the default directory in the CFileDialog to the one selected in the ComboBox.
Avatar of trestan
trestan
Flag of Canada image

You can use SetCurrentDirectory function to the cuurrent directory to the one indicated in the ComboBox.
Avatar of ernan
ernan

ASKER

Sorry I also would like the CFileDialog to refresh itself showing the path directory etc.
Avatar of ernan

ASKER

Adjusted points to 175
This is a little tricky.  The key is to fool the dialog into thinking that the user made the change himself.  When the user selects an item from your combo box, you should manually change the appropriate dialog box controls to match what you want.  You then send a message pretending to be from the control you just changed.

For example, if you modified an Edit Control you would send an EN_CHANGE message to the CFileDialog with the lParam set to the id and handle of the edit control.

I made this a comment because I don't think it's specific enough for an answer, but I hope it gets you on the write track.
Under your ON_EN_CHANGE function of the ComboBox, you should fill in the OPENFILENAME structure (the m_ofn data member of your CFileDialog instance). Then call the CFileDialog::OnFolderChange()function. This should renew the display the list box. Please try to see if there is any problem.
Avatar of ernan

ASKER

Thanks trestan I tried what you said but it did not work, I am now picking up the changes from the combo box and making changes to the m_ofn structure, I tried then to call the OnFolderChange function but this does nothing, I even had a look at the source code for it, it just ASSERT(this), so I think that I may have to destroy and reinitialize the dialog at this stage.
If you close the dialog and open it again, definitely the content should be renewed. But it sounds a little stupid. Actually I think there is must a way to do it. I did not try it, but you can try to post a message WM_NOTIFY CDN_FOLDERCHANGE to the dialog window instead of call the function directely. You see, the default file dialog can change the content when you choose a different path. So it should be working in this way. Just try!
Good luck.
If you close the dialog and open it again, definitely the content should be renewed. But it sounds a little stupid. Actually I think there is must a way to do it. I did not try it, but you can try to post a message WM_NOTIFY CDN_FOLDERCHANGE to the dialog window instead of call the function directely. You see, the default file dialog can change the content when you choose a different path. So it should be working in this way. Just try!
Good luck.
If you close the dialog and open it again, definitely the content should be renewed. But it sounds a little stupid. Actually I think there is must a way to do it. I did not try it, but you can try to post a message WM_NOTIFY CDN_FOLDERCHANGE to the dialog window instead of call the function directely. You see, the default file dialog can change the content when you choose a different path. So it should be working in this way. Just try!
Good luck.
ASKER CERTIFIED SOLUTION
Avatar of trestan
trestan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ernan

ASKER

Trestan I tried what you said but it crashed in COMCTRL32.dll
Which one you used? Use SetCurrentDirectory then send the message?
I tried the above and it didn't work, it crashed.
I tried the above and it didn't work, it crashed.