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

  1. // MDI2Views.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include "MDI2ViewsDoc.h"
  7. #include "MDI2Views.h"
  8. #include "MainFrm.h"
  9. #include "ChildFrm.h"
  10. #include "DefaultView.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. // CMDI2ViewsApp
  20.  
  21. BEGIN_MESSAGE_MAP(CMDI2ViewsApp, CWinApp)
  22.     //{{AFX_MSG_MAP(CMDI2ViewsApp)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.     //}}AFX_MSG_MAP
  25.     // Standard file based document commands
  26.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  27.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  28.     // Standard print setup command
  29.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  30. END_MESSAGE_MAP()
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMDI2ViewsApp construction
  34.  
  35. CMDI2ViewsApp::CMDI2ViewsApp()
  36. {
  37.     // TODO: add construction code here,
  38.     // Place all significant initialization in InitInstance
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // The one and only CMDI2ViewsApp object
  43.  
  44. CMDI2ViewsApp theApp;
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMDI2ViewsApp initialization
  48.  
  49. BOOL CMDI2ViewsApp::InitInstance()
  50. {
  51.     AfxEnableControlContainer();
  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.     // Change the registry key under which our settings are stored.
  65.     // You should modify this string to be something appropriate
  66.     // such as the name of your company or organization.
  67.     SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  68.  
  69.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  70.  
  71.     // Register the application's document templates.  Document templates
  72.     //  serve as the connection between documents, frame windows and views.
  73.  
  74.     CMultiDocTemplate* pDocTemplate;
  75.     pDocTemplate = new CMultiDocTemplate(
  76.         IDR_MDI2VITYPE,
  77.         RUNTIME_CLASS(CMDI2ViewsDoc),
  78.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  79.         RUNTIME_CLASS(CDefaultView));
  80.     AddDocTemplate(pDocTemplate);
  81.  
  82.  
  83.     // create main MDI Frame window
  84.     CMainFrame* pMainFrame = new CMainFrame;
  85.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  86.         return FALSE;
  87.     m_pMainWnd = pMainFrame;
  88.  
  89.     // Parse command line for standard shell commands, DDE, file open
  90.     CCommandLineInfo cmdInfo;
  91.     ParseCommandLine(cmdInfo);
  92.  
  93.     // Dispatch commands specified on the command line
  94.     if (!ProcessShellCommand(cmdInfo))
  95.         return FALSE;
  96.  
  97.     // The main window has been initialized, so show and update it.
  98.     pMainFrame->ShowWindow(m_nCmdShow);
  99.     pMainFrame->UpdateWindow();
  100.  
  101.     return TRUE;
  102. }
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CAboutDlg dialog used for App About
  106.  
  107. class CAboutDlg : public CDialog
  108. {
  109. public:
  110.     CAboutDlg();
  111.  
  112. // Dialog Data
  113.     //{{AFX_DATA(CAboutDlg)
  114.     enum { IDD = IDD_ABOUTBOX };
  115.     //}}AFX_DATA
  116.  
  117.     // ClassWizard generated virtual function overrides
  118.     //{{AFX_VIRTUAL(CAboutDlg)
  119.     protected:
  120.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  121.     //}}AFX_VIRTUAL
  122.  
  123. // Implementation
  124. protected:
  125.     //{{AFX_MSG(CAboutDlg)
  126.         // No message handlers
  127.     //}}AFX_MSG
  128.     DECLARE_MESSAGE_MAP()
  129. };
  130.  
  131. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  132. {
  133.     //{{AFX_DATA_INIT(CAboutDlg)
  134.     //}}AFX_DATA_INIT
  135. }
  136.  
  137. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  138. {
  139.     CDialog::DoDataExchange(pDX);
  140.     //{{AFX_DATA_MAP(CAboutDlg)
  141.     //}}AFX_DATA_MAP
  142. }
  143.  
  144. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  145.     //{{AFX_MSG_MAP(CAboutDlg)
  146.         // No message handlers
  147.     //}}AFX_MSG_MAP
  148. END_MESSAGE_MAP()
  149.  
  150. // App command to run the dialog
  151. void CMDI2ViewsApp::OnAppAbout()
  152. {
  153.     CAboutDlg aboutDlg;
  154.     aboutDlg.DoModal();
  155. }
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CMDI2ViewsApp commands
  159.