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

  1. // MDI2ViewsB.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MDI2ViewsB.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "ChildFrm.h"
  9. #include "MDI2ViewsBDoc.h"
  10. #include "DefaultView.h"
  11.  
  12. #include "italicsview.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMDI2ViewsApp
  22.  
  23. BEGIN_MESSAGE_MAP(CMDI2ViewsBApp, CWinApp)
  24.     //{{AFX_MSG_MAP(CMDI2ViewsApp)
  25.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  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. // CMDI2ViewsBApp construction
  36.  
  37. CMDI2ViewsBApp::CMDI2ViewsBApp()
  38. {
  39.     // TODO: add construction code here,
  40.     // Place all significant initialization in InitInstance
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // The one and only CMDI2ViewsApp object
  45.  
  46. CMDI2ViewsBApp theApp;
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CMDI2ViewsApp initialization
  50.  
  51. BOOL CMDI2ViewsBApp::InitInstance()
  52. {
  53.     AfxEnableControlContainer();
  54.  
  55.     // Standard initialization
  56.     // If you are not using these features and wish to reduce the size
  57.     //  of your final executable, you should remove from the following
  58.     //  the specific initialization routines you do not need.
  59.  
  60. #ifdef _AFXDLL
  61.     Enable3dControls();            // Call this when using MFC in a shared DLL
  62. #else
  63.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  64. #endif
  65.  
  66.     // Change the registry key under which our settings are stored.
  67.     // You should modify this string to be something appropriate
  68.     // such as the name of your company or organization.
  69.     SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  70.  
  71.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  72.  
  73.     // Register the application's document templates.  Document templates
  74.     //  serve as the connection between documents, frame windows and views.
  75.  
  76.     m_pDefaultTemplate = new CMultiDocTemplate(
  77.         IDR_MDI2VITYPE,
  78.         RUNTIME_CLASS(CMDI2ViewsBDoc),
  79.         RUNTIME_CLASS(CChildFrame),
  80.         RUNTIME_CLASS(CDefaultView));
  81.     AddDocTemplate(m_pDefaultTemplate);
  82.  
  83.     // The italics view gets its own menu and icons, which can be
  84.     // copies of those provided by App Wizard, but they do have to be
  85.     // unique. The ID is also used in a string resource.
  86.     m_pItalicsTemplate = new CMultiDocTemplate(
  87.         IDR_MDI2VITYPE2,
  88.         RUNTIME_CLASS(CMDI2ViewsBDoc),
  89.         RUNTIME_CLASS(CChildFrame),
  90.         RUNTIME_CLASS(CItalicsView));
  91.     AddDocTemplate(m_pItalicsTemplate);
  92.  
  93.     // create main MDI Frame window
  94.     CMainFrame* pMainFrame = new CMainFrame;
  95.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  96.         return FALSE;
  97.     m_pMainWnd = pMainFrame;
  98.  
  99.     // Parse command line for standard shell commands, DDE, file open
  100.     CCommandLineInfo cmdInfo;
  101.     ParseCommandLine(cmdInfo);
  102.  
  103.     // Dispatch commands specified on the command line
  104.     if (!ProcessShellCommand(cmdInfo))
  105.         return FALSE;
  106.  
  107.     // The main window has been initialized, so show and update it.
  108.     pMainFrame->ShowWindow(m_nCmdShow);
  109.     pMainFrame->UpdateWindow();
  110.  
  111.     return TRUE;
  112. }
  113.  
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CAboutDlg dialog used for App About
  116.  
  117. class CAboutDlg : public CDialog
  118. {
  119. public:
  120.     CAboutDlg();
  121.  
  122. // Dialog Data
  123.     //{{AFX_DATA(CAboutDlg)
  124.     enum { IDD = IDD_ABOUTBOX };
  125.     //}}AFX_DATA
  126.  
  127.     // ClassWizard generated virtual function overrides
  128.     //{{AFX_VIRTUAL(CAboutDlg)
  129.     protected:
  130.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  131.     //}}AFX_VIRTUAL
  132.  
  133. // Implementation
  134. protected:
  135.     //{{AFX_MSG(CAboutDlg)
  136.         // No message handlers
  137.     //}}AFX_MSG
  138.     DECLARE_MESSAGE_MAP()
  139. };
  140.  
  141. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  142. {
  143.     //{{AFX_DATA_INIT(CAboutDlg)
  144.     //}}AFX_DATA_INIT
  145. }
  146.  
  147. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  148. {
  149.     CDialog::DoDataExchange(pDX);
  150.     //{{AFX_DATA_MAP(CAboutDlg)
  151.     //}}AFX_DATA_MAP
  152. }
  153.  
  154. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  155.     //{{AFX_MSG_MAP(CAboutDlg)
  156.         // No message handlers
  157.     //}}AFX_MSG_MAP
  158. END_MESSAGE_MAP()
  159.  
  160. // App command to run the dialog
  161. void CMDI2ViewsBApp::OnAppAbout()
  162. {
  163.     CAboutDlg aboutDlg;
  164.     aboutDlg.DoModal();
  165. }
  166.  
  167. /////////////////////////////////////////////////////////////////////////////
  168. // CMDI2ViewsApp commands
  169.