-
September 23rd, 2013, 04:06 AM
#1
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
-
September 23rd, 2013, 04:17 AM
#2
Re: SetCurrentDirectory problem ..
If you want to keep the original current directory after CFileDialog::DoModal call, just set OFN_NOCHANGEDIR flag.
Last edited by ovidiucucu; September 23rd, 2013 at 04:21 AM.
-
September 23rd, 2013, 04:25 AM
#3
Re: SetCurrentDirectory problem ..
Thank you sir , I will ..
-
September 23rd, 2013, 05:22 AM
#4
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 ?
-
September 23rd, 2013, 05:39 AM
#5
Re: SetCurrentDirectory problem ..
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.
-
September 23rd, 2013, 05:51 AM
#6
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
-
September 23rd, 2013, 06:46 AM
#7
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
Last edited by Philip Nicoletti; September 23rd, 2013 at 07:47 AM.
-
September 23rd, 2013, 08:18 AM
#8
Re: SetCurrentDirectory problem ..
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.
-
September 23rd, 2013, 08:32 AM
#9
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 24th, 2013, 01:02 AM
#10
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 ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|