home *** CD-ROM | disk | FTP | other *** search
- // Browser.cpp : Defines the class behaviors for the application.
- //
-
- #include "stdafx.h"
- #include "Browser.h"
-
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "BrowserDoc.h"
- #include "BrowserView.h"
- #include "DataView.h"
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CBrowserApp
-
- BEGIN_MESSAGE_MAP(CBrowserApp, CWinApp)
- //{{AFX_MSG_MAP(CBrowserApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CBrowserApp construction
-
- CBrowserApp::CBrowserApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CBrowserApp object
-
- CBrowserApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // CBrowserApp initialization
-
- BOOL CBrowserApp::InitInstance()
- {
- AfxEnableControlContainer();
-
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
-
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
-
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
-
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
-
- m_pTemplate = new CMultiDocTemplate(
- IDR_ACCESSTYPE,
- RUNTIME_CLASS(CBrowserDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CBrowserView));
- AddDocTemplate(m_pTemplate);
-
- //Template to add another view to the document. This view
- //has its own set of resources.
-
- m_pDataTemplate = new CMultiDocTemplate(
- IDR_DATATYPE, //Data view resources
- RUNTIME_CLASS( CBrowserDoc ), //Same document class
- RUNTIME_CLASS( CChildFrame ), // custom MDI child frame
- RUNTIME_CLASS( CDataView ) ); //Data view class
- //Don't add template because we will manage it. We have to
- //delete the template in the destructor to avoid memory leak.
-
- // create main MDI Frame window
- CMainFrame * pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
-
- // Enable drag/drop open
- m_pMainWnd->DragAcceptFiles();
-
- // Enable DDE Execute open
- EnableShellOpen();
- RegisterShellFileTypes(TRUE);
-
- // Parse command line for standard shell commands, DDE, file open
- CCommandLineInfo cmdInfo;
-
- //We want to open with an empty frame, so we modify the cmdInfo data
- //structure to indicate no new file. See article Q141725
-
- if ( CCommandLineInfo::FileNew == cmdInfo.m_nShellCommand )
- cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
-
- ParseCommandLine(cmdInfo);
-
- // Dispatch commands specified on the command line
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
-
- //Reset the toolbar for the mainframe
- pMainFrame->m_wndToolBar.LoadToolBar(IDR_MAINFRAME);
- ( ( CFrameWnd * ) pMainFrame )->RecalcLayout( );
-
- // The main window has been initialized, so update and show it.
- pMainFrame->UpdateWindow();
- pMainFrame->ShowWindow(m_nCmdShow);
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- // No message handlers
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // App command to run the dialog
- void CBrowserApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CBrowserApp commands
-
-
- void CBrowserApp::OnFileOpen()
- {
- // TODO: Add your command handler code here
-
- CFileDialog dlg( TRUE, //Open dialog
- "mdb", "*.mdb", //Extension and filename
- OFN_HIDEREADONLY | OFN_PATHMUSTEXIST
- | OFN_FILEMUSTEXIST, //No read-only box, only valid names
- "Access files(*.mdb)|*.mdb|All files(*.*)|*.*||", //File filters
- NULL ); //Parent
-
- if ( IDOK == dlg.DoModal( ) ) //Show the File Open dialog
- {
- CBrowserDoc * pDoc = NULL;
-
- CString path = dlg.GetPathName( ); //Get the complete path
- CString title = dlg.GetFileTitle( ); //Get just the filename
-
- if ( NULL == pDoc ) //We need a document to open a database
- {
- pDoc =
- (CBrowserDoc *) m_pTemplate->OpenDocumentFile(NULL);
- }
-
- CDaoDatabase * pDB = pDoc->GetDatabase( ); //From exercise 1
-
- if ( pDB->IsOpen( ) ) //Close the database if it's open
- pDB->Close( );
-
- try
- {
- pDoc->GetDatabase( )->Open( path ); //Open the database
- }
- catch( CException * ex )
- {
- ex->ReportError( );
- ex->Delete( );
- }
-
- CChildFrame * pF = ( CChildFrame * )
- ( ( CMainFrame * ) AfxGetMainWnd( ) )->GetActiveFrame( );
- pF->m_strCaption = title;
- pDoc->SetTitle( title );
- pDoc->UpdateAllViews( NULL );
- }
- }
-
-
- CBrowserApp::~CBrowserApp( )
- {
- //We created the template, but didn't add it to the
- //list maintained by the app, so we have to delete it
- delete m_pDataTemplate;
- }
-