Yechezkel
asked on
Changing location in Open/Save dialog
How can I programatically change the current location in an open/save dialog while it is open (from within a class derived from CFileDialog)? I can put the new path in the edit box which shows the filename, but how can I get the list control to go there?
ASKER
If you read my question clearly you will see that I want to change the location _while the dialog is open_.
if u wann change the location while the dialog is open what is the problem ?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
The problem is that that closes the dialog. I want the location to change while the dialog stays open.
You can use the DlgDirList() function (of CWnd class). It fills a list box with a file or directory listing. Only thing you should know is the ID of the list control. The declaration is:
int DlgDirList( LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT nFileType );
int DlgDirList( LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT nFileType );
Sorry, I didn't read your question carefully.
DanRollins is right, actually he is click "Open" button.
But in dialog template the "Open" button has the same ID as "OK" button. it is 0x0001.
And in fileopen dialog, if you click "open" and the text in FileName is a disrectory, you will change to that dir, The dialog will not close.
DanRollins is right, actually he is click "Open" button.
But in dialog template the "Open" button has the same ID as "OK" button. it is 0x0001.
And in fileopen dialog, if you click "open" and the text in FileName is a disrectory, you will change to that dir, The dialog will not close.
ASKER
That's not exactly what I want...
ASKER
(The previous comment was for arun_ta)
ASKER
Thanks! I was trying it with the full filename. And Thanks j_jin for clarifying it for me.
BTW SendMessage works instead of PostMessage which allows me to set the edit box to the filename (without the path) immediately after showing the directory.
BTW SendMessage works instead of PostMessage which allows me to set the edit box to the filename (without the path) immediately after showing the directory.
Test carefully before putting SendMessage in your production code.
I avoided it because My test code was running as a notification handler -- a typical usage for this would be to change directories when the user changes file types; that is in the OnTypeChange() function.
In some cases (perhaps not this one) you can get into trouble taking major actions in a notification handler. The SendMessage could trigger a cascade of actions... one of which is another notification. Just a thought.
-- Dan
P.S. Thanks for your fuss-free accepting of my answer. Often when someone like arun_ta locks a question, it can be a hassle straightening things out.
I avoided it because My test code was running as a notification handler -- a typical usage for this would be to change directories when the user changes file types; that is in the OnTypeChange() function.
In some cases (perhaps not this one) you can get into trouble taking major actions in a notification handler. The SendMessage could trigger a cascade of actions... one of which is another notification. Just a thought.
-- Dan
P.S. Thanks for your fuss-free accepting of my answer. Often when someone like arun_ta locks a question, it can be a hassle straightening things out.
You can set m_ofn.lpstrInitialDir to the path you want.
for example, you may do like this:
CFileDialog fd(true);
fd.m_ofn.lpstrInitialDir = "c:\\";
if(fd.DoModal() == IDOK)
{
// Do something;
}
then you will open the file dialog in C:\ dir.