Solved

CFileDialog changing default directory

Posted on 1998-07-22
14
489 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:ernan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1319593
You can use SetCurrentDirectory function to the cuurrent directory to the one indicated in the ComboBox.
0
 

Author Comment

by:ernan
ID: 1319594
Sorry I also would like the CFileDialog to refresh itself showing the path directory etc.
0
 

Author Comment

by:ernan
ID: 1319595
Adjusted points to 175
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:jstolan
ID: 1319596
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.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319597
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.
0
 

Author Comment

by:ernan
ID: 1319598
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.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319599
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.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319600
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.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319601
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.
0
 
LVL 8

Accepted Solution

by:
trestan earned 250 total points
ID: 1319602
Sorry for the repeated sending.
I send another suggestion after that. But I can not see it. I do not know what's wrong. I want to tell you that add this line in your program:
GetParent()->PostMessage( WM_NOTIFY,  CDN_FOLDERCHANGE, 0);
Please try to see if it works. If the message can be receive by the window, may be you do not need to fill the structure after you use SetCurrentDirectory.
0
 

Author Comment

by:ernan
ID: 1319603
Trestan I tried what you said but it crashed in COMCTRL32.dll
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319604
Which one you used? Use SetCurrentDirectory then send the message?
0
 

Expert Comment

by:NotJeff
ID: 1319605
I tried the above and it didn't work, it crashed.
0
 

Expert Comment

by:NotJeff
ID: 1319606
I tried the above and it didn't work, it crashed.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ShiftLeft challenge 21 89
NotAlone Challenge 20 88
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 475
Work with App store 7 94
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question