I am currently trying to write an app that uses an SDI framework created
with VC++6.0 AppWizard. Nothing fancy, just one view and a few dialogs. The
problem that I am running into has to do with the Open Dialog Box. I need
to have a control (lets say a button) that will do the same thing as
selecting File\Open on the menu bar. I just can't seem to find the correct
entry point, (i.e.. what is called when you select File\Open).
I have tried using the OnFileOpen() function in the CDocManager class, which
gets close to what I want, but it doesn't include my program's extension
filters, only (*.* all files). It seems that this should be an easy thing
to do, but for some reason I can't figure it out.
Any help in this matter would be greatly appreciated.
Thanks in advance,
RJB
The File Open dialog box is one of so-called Common Dialogs. You can
open it by calling GetOpenFileName().
You need to #include <commdlg.h> and link with comdlg32.lib.
Norm
You should find this line in your app class message map:
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
That means CWinApp::OnFileOpen is called when File/Open is selected. It
is a protected function so you can't call it from your button. But you
can add your own public OnFileOpen function in your app class and change
the message map line to:
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
void CYourApp::OnFileOpen( )
{
CWinApp::OnFileOpen();
}
It should still work as before. But now your button handler can also
call your OnFileOpen:
void CYourView::OnButton()
{
CYourApp* pApp = (CYourApp*)AfxGetApp();
pApp->OnFileOpen();
}
--
Scott McPhillips [VC++ MVP]
It's very easy if you use doc-view architecture.
Open String table in a resource view. Double-click IDR_MAINFRAME.
This string contains 7 substrings separated by newline character '\n'
For substring No 4 put something like: My Application files (*.XXX)
For substring No 5 put your extension: .XXX
Your File-Open dialog should work correctly now.
Regards,
Michael
Norm,
Thanks for the input on my problem, but I used Mr. McPhillips solution.
It was more along the lines of how I think and program.
Thanks again for the effort.
Laters,
Robert
Scott,
Thank so much for your input. Your solution was a perfect fit for my
problem. You are definitely an MVP!.\
Thanx again,
Laters,
Robert
Michael,
Thanks for the reply to my problem, but Mr. McPhillips had the correct
solution for me. BTW I had already taken care of your suggestion in my
String Table before my first post. Thanks again for the reply.
Laters,
Robert