home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c07 / mdiapp / mdiapp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.0 KB  |  153 lines

  1. // MDIApp.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MDIApp.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "ChildFrm.h"
  9. #include "MDIDoc.h"
  10. #include "MDIView.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMDIAppApp
  20.  
  21. BEGIN_MESSAGE_MAP(CMDIAppApp, CWinApp)
  22.     //{{AFX_MSG_MAP(CMDIAppApp)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code!
  26.     //}}AFX_MSG_MAP
  27.     // Standard file based document commands
  28.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  29.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  30.     // Standard print setup command
  31.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMDIAppApp construction
  36.  
  37. CMDIAppApp::CMDIAppApp()
  38. {
  39.     // TODO: add construction code here,
  40.     // Place all significant initialization in InitInstance
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // The one and only CMDIAppApp object
  45.  
  46. CMDIAppApp theApp;
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CMDIAppApp initialization
  50.  
  51. BOOL CMDIAppApp::InitInstance()
  52. {
  53.     // Standard initialization
  54.     // If you are not using these features and wish to reduce the size
  55.     //  of your final executable, you should remove from the following
  56.     //  the specific initialization routines you do not need.
  57.  
  58. #ifdef _AFXDLL
  59.     Enable3dControls();            // Call this when using MFC in a shared DLL
  60. #else
  61.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  62. #endif
  63.  
  64.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  65.  
  66.     // Register the application's document templates.  Document templates
  67.     //  serve as the connection between documents, frame windows and views.
  68.  
  69.     CMultiDocTemplate* pDocTemplate;
  70.     pDocTemplate = new CMultiDocTemplate(
  71.         IDR_MDIAPPTYPE,
  72.         RUNTIME_CLASS(CMDIAppDoc),
  73.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  74.         RUNTIME_CLASS(CMDIAppView));
  75.     AddDocTemplate(pDocTemplate);
  76.  
  77.     // create main MDI Frame window
  78.     CMainFrame* pMainFrame = new CMainFrame;
  79.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  80.         return FALSE;
  81.     m_pMainWnd = pMainFrame;
  82.  
  83.     // Parse command line for standard shell commands, DDE, file open
  84.     CCommandLineInfo cmdInfo;
  85.     ParseCommandLine(cmdInfo);
  86.  
  87.     // Dispatch commands specified on the command line
  88.     if (!ProcessShellCommand(cmdInfo))
  89.         return FALSE;
  90.  
  91.     // The main window has been initialized, so show and update it.
  92.     pMainFrame->ShowWindow(m_nCmdShow);
  93.     pMainFrame->UpdateWindow();
  94.  
  95.     return TRUE;
  96. }
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CAboutDlg dialog used for App About
  100.  
  101. class CAboutDlg : public CDialog
  102. {
  103. public:
  104.     CAboutDlg();
  105.  
  106. // Dialog Data
  107.     //{{AFX_DATA(CAboutDlg)
  108.     enum { IDD = IDD_ABOUTBOX };
  109.     //}}AFX_DATA
  110.  
  111.     // ClassWizard generated virtual function overrides
  112.     //{{AFX_VIRTUAL(CAboutDlg)
  113.     protected:
  114.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  115.     //}}AFX_VIRTUAL
  116.  
  117. // Implementation
  118. protected:
  119.     //{{AFX_MSG(CAboutDlg)
  120.         // No message handlers
  121.     //}}AFX_MSG
  122.     DECLARE_MESSAGE_MAP()
  123. };
  124.  
  125. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  126. {
  127.     //{{AFX_DATA_INIT(CAboutDlg)
  128.     //}}AFX_DATA_INIT
  129. }
  130.  
  131. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  132. {
  133.     CDialog::DoDataExchange(pDX);
  134.     //{{AFX_DATA_MAP(CAboutDlg)
  135.     //}}AFX_DATA_MAP
  136. }
  137.  
  138. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  139.     //{{AFX_MSG_MAP(CAboutDlg)
  140.         // No message handlers
  141.     //}}AFX_MSG_MAP
  142. END_MESSAGE_MAP()
  143.  
  144. // App command to run the dialog
  145. void CMDIAppApp::OnAppAbout()
  146. {
  147.     CAboutDlg aboutDlg;
  148.     aboutDlg.DoModal();
  149. }
  150.  
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CMDIAppApp commands
  153.