SetCurrentDirectory problem ..
I am using CFileDialog to open different types of files in my application. I open file from c:\stdparamfile directory by File Menu
Open menu item. (OnOpenDocument) . But when I change directory and open other type of file, that path is set for OnOpenDocument function. I need to select path c:\stdparamfile directory again.
I am using GetCurrentDirectory , SetCurrentDirectory functions but problem exists.
I set dialog path by dlg.m_ofn.lpstrInitialDir .
How to get back to original directory ?
pl help
Re: SetCurrentDirectory problem ..
If you want to keep the original current directory after CFileDialog::DoModal call, just set OFN_NOCHANGEDIR flag.
Re: SetCurrentDirectory problem ..
Thank you sir , I will ..
Re: SetCurrentDirectory problem ..
Sir , I used the flag as follows ..
CFileDialog dlg (TRUE , _T("rec"), _T("*.rec"), OFN_HIDEREADONLY|OFN_NOCHANGEDIR, szFilters);
It has no effect.
It is changing directory of OnOpenDocument
What to do ?
Re: SetCurrentDirectory problem ..
Quote:
Originally Posted by
new_2012
I am using GetCurrentDirectory , SetCurrentDirectory functions but problem exists.
How to get back to original directory ?
pl help
Why doesn't that work? Is the problem that you just want to get back to the original directory, or you don't wan the user to be able to change directory? OFN_NOCHANGEDIR will allow the user to change directory, but it should restore your app's working directory to what it was before the dialog was opened.
Re: SetCurrentDirectory problem ..
When I start my application , it loads file with OnOpenDocument , where I used saved filename in registry. That file is from parameter directory.
Now , when I record data , I use CFileDialog to open a file to save data. That file is in other directory . I call that record directory.
At this time , dialog shows parameter directory .
Now again , if I need to open another parameter file , the open menu item from file menu , shows record data directory. I need to change directory again.
To avoid this .. I tried ..
save current directory.
open record file .
restore current directory.
save data.
close record file.
but SetCurrentDirectory , GetCurrentDirectory functions didn't work. I am not able to check directory name by GetCurrentDirectory as it is TCHAR.
I set OFN_NOCHANGEDIR flag also.
pl guide
Re: SetCurrentDirectory problem ..
OFN_NOCHANGEDIR does not effect GetOpenFileName.
In some cases, setting the CFileDialog's m_ofn.lpstrInitialDir works.
You might be able to use a callback function similar to:
http://forums.codeguru.com/showthrea...61#post2102361
Re: SetCurrentDirectory problem ..
Quote:
Originally Posted by
new_2012
When I start my application , it loads file with OnOpenDocument , where I used saved filename in registry. That file is from parameter directory.
Now , when I record data , I use CFileDialog to open a file to save data. That file is in other directory . I call that record directory.
At this time , dialog shows parameter directory .
Now again , if I need to open another parameter file , the open menu item from file menu , shows record data directory. I need to change directory again.
To avoid this .. I tried ..
save current directory.
open record file .
restore current directory.
save data.
close record file.
but SetCurrentDirectory , GetCurrentDirectory functions didn't work. I am not able to check directory name by GetCurrentDirectory as it is TCHAR.
I set OFN_NOCHANGEDIR flag also.
pl guide
Get and Set CurrentDirectory functions do work. You need to be more specific when you say the didn't. Maybe show some code.
Re: SetCurrentDirectory problem ..
Are you checking the return value from these functions for success/failure? Is your application multi-threaded as multithreaded applications and shared library code should not use these functions and should avoid using relative path names.
See
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
As GCDEF suggested, it would be more helpful if you posted the code with which you are having the problems.
Re: SetCurrentDirectory problem ..
sir ,
All the return values are correct and I have checked them.
When my application starts .. the code executed is
CString str, buf , currpath;
TCHAR filename[1024];
_tgetcwd( filename, _MAX_PATH);
currpath = filename;
str = GetProfileString(_T("History"), _T("Filename"), 0);
_tfinddata_t fr;
TCHAR* mystr = (LPTSTR)(LPCTSTR) str;
if (_tfindfirst(mystr, &fr) != -1)
CDocument * pdc = OpenDocumentFile(str); // opens last saved Parameter File from Parameter Directory
else {
str = currpath + _T("\\std.mts\\default.pam"); // opens default file from default Parameter Directory
pDoc->OnSaveDocument(str);
}
Normally the user changes Parameter file if needed and saves back to disk.
Then he needs to record the file data into record directory.
In Record Dialog , the code executed is .....
CFileDialog dlg (TRUE , _T("rec"),_T("*.rec"),OFN_HIDEREADONLY|OFN_NOCHANGEDIR,szFilters);
dwRet = GetCurrentDirectoryW(_MAX_PATH ,cdir);
if ((dlg.DoModal()) == IDOK) { // Select Record Directory to save record file
code to save recorded data;
}
_tchdir(cdir); // this is additional I have tried
qb = SetCurrentDirectoryW(cdir);
Now problem is ... The Current Directory before CFileDialog is "c:\\mtsex_card\\std.mts"
In Record File Dialog , I change it to c:\\ResPathTry .
Now even after executing SetCurrentDirectoryW(cdir) , the OpenFileDialog
shows directory c:\\ResPathTry.
Then I added ..
dwRet = GetCurrentDirectoryW(_MAX_PATH ,cdir);
and return value in dwRet was 21 which corrosponds to "c:\\mtsex_card\\std.mts"
The path may be set properly but CFileDialog from OpenDocument is not getting it.
I can save paths to registry and set the path to CFileDialog using dlg.m_ofn.lpstrInitialDir
feature but I am not able to use this feature in OnOpenDocument ... ???
So what Can I do ?