Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Set CFileDialog default path at DoModal?

67 views
Skip to first unread message

Landon

unread,
Jul 23, 2008, 8:42:01 PM7/23/08
to
I use MFC Visual C++ 4.2.

I want to set CFileDialog default path so when user click a button that will
do the dialog, the default path will be the one I set.

I have read the MSDN Library and there was only GetPathName. No SetPathName.

CFileDialog dlg( TRUE, NULL, NULL, OFN_FILEMUSTEXIST, "All Files
(*.*)|*.*||" );
if( dlg.DoModal() == IDOK ){

}

How to set the path?

Thank you very much.

Mark Salsbery [MVP]

unread,
Jul 23, 2008, 9:08:13 PM7/23/08
to
"Landon" <Lan...@discussions.microsoft.com> wrote in message
news:1017D645-F289-4382...@microsoft.com...


Before you call DoModal(), you can set the initial directory by setting the
dialog object's m_ofn.lpstrInitialDir member.

See the current docs for the OPENFILENAME structure for changes in behavior
on Vista.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

>
> Thank you very much.

Giovanni Dicanio

unread,
Jul 24, 2008, 4:58:08 AM7/24/08
to

"Landon" <Lan...@discussions.microsoft.com> ha scritto nel messaggio
news:1017D645-F289-4382...@microsoft.com...

> I want to set CFileDialog default path so when user click a button that
> will
> do the dialog, the default path will be the one I set.
>
> I have read the MSDN Library and there was only GetPathName. No
> SetPathName.
>
> CFileDialog dlg( TRUE, NULL, NULL, OFN_FILEMUSTEXIST, "All Files
> (*.*)|*.*||" );

CFileDialog is a wrapper on Win32 Platform SDK structure OPENFILENAME.

"OPENFILENAME"
http://msdn.microsoft.com/en-us/library/ms646839(VS.85).aspx

You may be interested in the 'lpstrInitialDir' field of that structure.

To access OPENFILENAME structure embedded in CFileDialog, you can use
CFileDialog::GetOFN() method.

Giovanni

0 new messages