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

CFileDialog

543 views
Skip to first unread message

phil oakleaf

unread,
May 10, 2009, 6:07:31 PM5/10/09
to
Hi there,

running MFC on Windows 64bit and wanting to use CFileDialog to load/save
a file but not change the place where the main document File/Open+SAveAs
writes the files.


I've looked through the documentation and found reference to

CFileDialog fileDlg(TRUE,.....);
fileDlg.m_ofn.lpstrInitialDir="C:\\";


but a) is does not set the initial directory to C:\
and b) the next File:SaveAs takes to where I loaded that file

I'm sure I am missing something simple but cannot figure out what it is

Any help will be very much appreciated.

Regards
Phil

Scot T Brennecke

unread,
May 10, 2009, 8:24:12 PM5/10/09
to
Which version of Windows? Is it Vista? If so, read this:
CFileDialog::m_ofn:
http://msdn.microsoft.com/en-us/library/43xtah3y.aspx
Vista had some "breaking changes" with regard to the OPENFILENAME structure and the open and save
file common dialogs in general.

"phil oakleaf" <ne...@oakleafsoftware.co.uk> wrote in message
news:ucA4Hvb0...@TK2MSFTNGP05.phx.gbl...

phil oakleaf

unread,
May 11, 2009, 2:09:28 AM5/11/09
to
Scot

Thanks for the tip - I am using Vista 64bit and building with VS-2005

There appear to be no methods called

UpdateOFNFromShellDialog
ApplyOFNToShellDialog


are these in a later version of MFC?

Thanks
Phil

Giovanni Dicanio

unread,
May 11, 2009, 5:44:00 AM5/11/09
to

"phil oakleaf" <ne...@oakleafsoftware.co.uk> ha scritto nel messaggio
news:ueIrb8f0...@TK2MSFTNGP05.phx.gbl...

I can see them using VS2008.

Giovanni


Scot T Brennecke

unread,
May 11, 2009, 6:24:46 AM5/11/09
to
VS2005 was made before Vista, so it's not "aware" of the need for such functions.

"phil oakleaf" <ne...@oakleafsoftware.co.uk> wrote in message

news:ueIrb8f0...@TK2MSFTNGP05.phx.gbl...

phil oakleaf

unread,
May 11, 2009, 6:44:49 AM5/11/09
to
that makes sense

Upgrade time!!!!

Many thanks
Phil

phil oakleaf

unread,
May 17, 2009, 5:39:29 AM5/17/09
to
I've installed VS-2008
Updated MFC to the latest version

To get the ApplyOFNToShellDialog methods visible I've had to change
WINVER from 0x0400 to 0X0600, which worries me.

Does this create compatability problems if the software is run on older
versions of Windows (we have some users on WIn95)


Anyway, having done all this when I do the following


m_myFileDialogPtr->UpdateOFNFromShellDialog();
m_myFileDialogPtr->m_ofn.lpstrTitle = L"New Dialog Title";
m_myFileDialogPtr->ApplyOFNToShellDialog();

m_myFileDialogPtr->DoModal();

as soon as DoModal is called, I get an assert

f:\dd\vctools......\dlgfil.cpp" - a file I dont have

followed by

"Encountered an improper argument"

All I am trying to do is get CFileDialog to not change folder on Vista :)

Any ideas?

Many thanks

phil oakleaf

unread,
May 17, 2009, 7:38:35 AM5/17/09
to


Sorry, I meant to say that I want to set the initial folder that
CFileDialog displays

David Wilkinson

unread,
May 17, 2009, 11:14:02 AM5/17/09
to
phil oakleaf wrote:
> I've installed VS-2008
> Updated MFC to the latest version
>
> To get the ApplyOFNToShellDialog methods visible I've had to change
> WINVER from 0x0400 to 0X0600, which worries me.
>
> Does this create compatability problems if the software is run on older
> versions of Windows (we have some users on WIn95)

Yes, Visual C++ 2008 supports only Windows 2000 and up.

<http://msdn.microsoft.com/en-us/library/ms235435.aspx>

It's possible that particular programs generated with VC++ 2008 would run on
Windows 98 or earlier, but you would need to test them very carefully.

I must say I have mixed feelings about this backward compatibility for legacy
targets. Windows 2000 will be the next to go, but I doubt Microsoft would dare
remove support for XP any time soon.

--
David Wilkinson
Visual C++ MVP

Giovanni Dicanio

unread,
May 17, 2009, 11:31:24 AM5/17/09
to

"phil oakleaf" <ne...@oakleafsoftware.co.uk> ha scritto nel messaggio
news:OTFo$Nt1JH...@TK2MSFTNGP06.phx.gbl...

> I've installed VS-2008
> Updated MFC to the latest version
>
> To get the ApplyOFNToShellDialog methods visible I've had to change WINVER
> from 0x0400 to 0X0600, which worries me.
>
> Does this create compatability problems if the software is run on older
> versions of Windows (we have some users on WIn95)

I may be wrong, but I think that if you want to support Win95, you can't use
VS2008.
IIRC, the latest VC++ compiler that supports building code for Win95 is
Visual Studio .NET 2003 (a.k.a. VC++7.1).
(I'm not sure if VS2005 supports Win95... I recall that VS2005 supports
Win98.)

Moreover, I think that if you want to use the new Vista dialog, your code
can't run on Win95.

> Anyway, having done all this when I do the following
>
>
> m_myFileDialogPtr->UpdateOFNFromShellDialog();
> m_myFileDialogPtr->m_ofn.lpstrTitle = L"New Dialog Title";
> m_myFileDialogPtr->ApplyOFNToShellDialog();
>
> m_myFileDialogPtr->DoModal();
>
> as soon as DoModal is called, I get an assert
>
> f:\dd\vctools......\dlgfil.cpp" - a file I dont have

I have the file 'dlgfil.cpp' in this folder:

C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc

I've tried this code on VS2008 and it works fine (you can build a
dialog-based app with MFC, and associate this code to the click of a button
on the dialog-box):

<code>

void CTest1Dlg::OnBnClickedButton1()
{
// Open file dialog
CFileDialog fileDlg(TRUE);

// Update the m_ofn variable
fileDlg.UpdateOFNFromShellDialog();

// Change the title
fileDlg.m_ofn.lpstrTitle = L"New Dialog Title";

// Apply the changes
fileDlg.ApplyOFNToShellDialog();

// Show the window
fileDlg.DoModal();
}

</code>

HTH,
Giovanni

Giovanni Dicanio

unread,
May 17, 2009, 11:34:36 AM5/17/09
to

"phil oakleaf" <ne...@oakleafsoftware.co.uk> ha scritto nel messaggio
news:%23rhljQu...@TK2MSFTNGP04.phx.gbl...

> Sorry, I meant to say that I want to set the initial folder that
> CFileDialog displays

So, you can set the m_ofn.lpstrInitialDir field, like this:

<code>

void CTest1Dlg::OnBnClickedButton1()
{
CFileDialog fileDlg(TRUE);

// Update the m_ofn variable
fileDlg.UpdateOFNFromShellDialog();

// Change the title
fileDlg.m_ofn.lpstrTitle = L"New Dialog Title";

// Set initial folder
CString initialFolder = ... << initial folder path >>;
fileDlg.m_ofn.lpstrInitialDir = initialFolder;

// Apply the changes
fileDlg.ApplyOFNToShellDialog();

// Show the window
fileDlg.DoModal();
}

</code>

Giovanni

Scot T Brennecke

unread,
May 18, 2009, 5:00:56 AM5/18/09
to
I think it would be cheaper to simply buy your Win95 users an upgrade to their OS rather than to
spend the time and headache trying to support such a ridiculously old and pathetic pseudo-OS.

"phil oakleaf" <ne...@oakleafsoftware.co.uk> wrote in message

news:OTFo$Nt1JH...@TK2MSFTNGP06.phx.gbl...

0 new messages