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

CFileDialog Initial Directory

371 views
Skip to first unread message

Craig Henderson

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to
How do I set the initial directory in the CFileDialog common control? I have
tries setting
m_ofn.lpstrInitialDir = "C:\\Temp";
and setting this to NULL and using the SetCurrentDirectory() API, but to no
avail.

Any clues?

Craig
chenders...@synertec.co.uk
remove _NOSPAM from email

V.Sivakumar

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to
Hi,

If the "lpstrFile" member contains a string that specifies a valid path, the
common
dialog box procedure will use the path specified by "lpstrFile" instead of
the path
specified by the string to which lpstrInitialDir points.


Regards,
Sivakumar Velusamy

"Craig Henderson" <chenders...@synertec.co.uk> wrote in message
news:945773089.630.0....@news.demon.co.uk...

Charles Bisbee

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to
set the lpstrInitialDir in the m_ofn of the dialog after you create it
and before you execute DoModal()

The m_ofn structure is
typedef struct tagOFN {
DWORD lStructSize;
HWND hwndOwner;
HINSTANCE hInstance;
LPCTSTR lpstrFilter;
LPTSTR lpstrCustomFilter;
DWORD nMaxCustFilter;
DWORD nFilterIndex;
LPTSTR lpstrFile;
DWORD nMaxFile;
LPTSTR lpstrFileTitle;
DWORD nMaxFileTitle;
LPCTSTR lpstrInitialDir;
LPCTSTR lpstrTitle;
DWORD Flags;
WORD nFileOffset;
WORD nFileExtension;
LPCTSTR lpstrDefExt;
DWORD lCustData;
LPOFNHOOKPROC lpfnHook;
LPCTSTR lpTemplateName;
#if (_WIN32_WINNT >= 0x0500)
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)
} OPENFILENAME;


careca

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
Try
CFileDialog fileopendlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, NULL);
fileopendlg.m_ofn.lpstrInitialDir = "C:\\Temp";


Craig Henderson <chenders...@synertec.co.uk> schrieb in im
Newsbeitrag: 945773089.630.0....@news.demon.co.uk...

Craig Henderson

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
Tries that, no luck ;(


"careca" <ko...@ti-nov3.fbe.fh-weingarten.de> wrote in message
news:83ptof$b4k$1...@kilbeggan.xlink.net...

Craig Henderson

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
But this is what doesn't work in my app ;(

"Charles Bisbee" <prin...@home.com> wrote in message
news:ECE078D19685D3119E980008C7F9E55D3FD2C9@CPECMAILE01...

Scot T Brennecke

unread,
Dec 24, 1999, 3:00:00 AM12/24/99
to
Craig,
You need to be more specific. The answers you have been given are the
correct way to do it. If it isn't working for you, you need to share a
snippet of your code so we can tell you what you are doing wrong.

anti...@nowhere.com

unread,
Jan 1, 2000, 3:00:00 AM1/1/00
to
"Craig Henderson" <chenders...@synertec.co.uk> rambled on for a while about:

>> Try
>> CFileDialog fileopendlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, NULL);
>> fileopendlg.m_ofn.lpstrInitialDir = "C:\\Temp";
>>

>Tries that, no luck ;(
>

Make sure you set the start directory after the dialogue is constructed but before it is displayed.


Craig Henderson

unread,
Jan 4, 2000, 3:00:00 AM1/4/00
to
Ok, here's the code. As you can see I am using the lpstrInitialDir and
SetCurrentDirectory and it STILL doesn't work ;(
Please help, I'm sure it's gonna be really obvious to someone and I'm gonna
look real stupid :)

void CMyClass::OpenDocument(void)
{
CString strFilename;
CFileDialog dlg(TRUE, NULL, NULL,
OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_SHAREAWARE,
_TEXT("All Files (*.*)|*.*|"),
this);

dlg.m_ofn.lpstrInitialDir = "C:\\Temp";
::SetCurrentDirectory(dlg.m_ofn.lpstrInitialDir);
if (dlg.DoModal() != IDOK)
return;
}

Cheers,


Craig
chenders...@synertec.co.uk
remove _NOSPAM from email

"Scot T Brennecke" <mar...@airmail.net> wrote in message
news:386342A3...@airmail.net...

Scot T Brennecke

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
Your code looks fine. Now I guess you need to explain what "it doesn't work"
really means. What are the symptoms of it not working?

0 new messages