Default document's path - how to change?  
Author Message
sunshine7000k





PostPosted: Tue Nov 30 14:57:19 CST 2004 Top

MFC >> Default document's path - how to change?

Hello

I recently posted a question regarding default path; I'd like to widen this
question.

Suppose we have MDI application (with two or more document types, if it does
matter). After first call of (wizard generated) menu option "Open" or "Save"
or "Save As" we can see dialog opened at location of current user's My
Documents folder. I would like to change this path for one, default path. It
seems to be extremely easy...
I tried calling CDocument::SetPathName(strMyPath); - with absolutely no
results. What should I change to set new path that will be used as default?
Or what to override to get access to function that directly uses
CFileDialog? Overriding CDocument::OnSaveDocument(LPCTSTR lpszPathName) has
no sense, because it is called AFTER the "Save" dialog is displayed :-/

Thanks in advance for help.

Visual Studio329  
 
 
AliR





PostPosted: Tue Nov 30 14:57:19 CST 2004 Top

MFC >> Default document's path - how to change? I am really not sure how to do that. Actually stepping throught the code the
Doc manager doesn't even intialize the lpstrInitalDir variable.

Anyway, why don't you do this
instead of letting the default implementation do your open, saves, and such
do them yourself.

Here is an example of the open
Change the message map from CWinApp::OnFileOpen to just OnMyFileOpen

void CMyApp::OnMyFileOpen()
{
CFileDialog Dlg(..pass whatever dir you want);
if (Dlg.DoModal() != IDCANCEL)
{
OpenDocumentFile(Dlg.GetPathName());
}
}

As far as the save goes, the method SetPathName, really needs a file name,
if you just pass a path to this function, then when it comes to displaying
the save dialog MFC passes NULL as the filepath, which most likely starts in
the current working directory.

AliR.



> Hello
>
> I recently posted a question regarding default path; I'd like to widen
this
> question.
>
> Suppose we have MDI application (with two or more document types, if it
does
> matter). After first call of (wizard generated) menu option "Open" or
"Save"
> or "Save As" we can see dialog opened at location of current user's My
> Documents folder. I would like to change this path for one, default path.
It
> seems to be extremely easy...
> I tried calling CDocument::SetPathName(strMyPath); - with absolutely no
> results. What should I change to set new path that will be used as
default?
> Or what to override to get access to function that directly uses
> CFileDialog? Overriding CDocument::OnSaveDocument(LPCTSTR lpszPathName)
has
> no sense, because it is called AFTER the "Save" dialog is displayed :-/
>
> Thanks in advance for help.
>
>


 
 
Ashish





PostPosted: Tue Nov 30 14:57:19 CST 2004 Top

MFC >> Default document's path - how to change? You can access the m_ofn member of CFileDialog and set its lpstrInitialDir
string to the one you want and then call DoModal.
HTH
Ashish



> Hello
>
> I recently posted a question regarding default path; I'd like to widen
this
> question.
>
> Suppose we have MDI application (with two or more document types, if it
does
> matter). After first call of (wizard generated) menu option "Open" or
"Save"
> or "Save As" we can see dialog opened at location of current user's My
> Documents folder. I would like to change this path for one, default path.
It
> seems to be extremely easy...
> I tried calling CDocument::SetPathName(strMyPath); - with absolutely no
> results. What should I change to set new path that will be used as
default?
> Or what to override to get access to function that directly uses
> CFileDialog? Overriding CDocument::OnSaveDocument(LPCTSTR lpszPathName)
has
> no sense, because it is called AFTER the "Save" dialog is displayed :-/
>
> Thanks in advance for help.
>
>


 
 
Tom





PostPosted: Tue Nov 30 15:13:35 CST 2004 Top

MFC >> Default document's path - how to change? You need to override DoPromptFileName(). This article will give you some
direction.

http://www.codeguru.com/Cpp/W-D/doc_view/fileopensave/print.php/c3309/

Tom



> Hello
>
> I recently posted a question regarding default path; I'd like to widen
> this
> question.
>
> Suppose we have MDI application (with two or more document types, if it
> does
> matter). After first call of (wizard generated) menu option "Open" or
> "Save"
> or "Save As" we can see dialog opened at location of current user's My
> Documents folder. I would like to change this path for one, default path.
> It
> seems to be extremely easy...
> I tried calling CDocument::SetPathName(strMyPath); - with absolutely no
> results. What should I change to set new path that will be used as
> default?
> Or what to override to get access to function that directly uses
> CFileDialog? Overriding CDocument::OnSaveDocument(LPCTSTR lpszPathName)
> has
> no sense, because it is called AFTER the "Save" dialog is displayed :-/
>
> Thanks in advance for help.
>
>