home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / mdibind / mdibind.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  6KB  |  218 lines

  1. // MDIBind.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "MDIBind.h"
  15.  
  16. #include "MainFrm.h"
  17. #include "RDCFrm.h"
  18. #include "GridFrm.h"
  19. #include "MaskFrm.h"
  20. #include "MDIDoc.h"
  21. #include "gridView.h"
  22. #include "MaskView.h"
  23. #include "RDCView.h"
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMDIBindApp
  33.  
  34. BEGIN_MESSAGE_MAP(CMDIBindApp, CWinApp)
  35.     //{{AFX_MSG_MAP(CMDIBindApp)
  36.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  37.         // NOTE - the ClassWizard will add and remove mapping macros here.
  38.         //    DO NOT EDIT what you see in these blocks of generated code!
  39.     //}}AFX_MSG_MAP
  40.     // Standard file based document commands
  41.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  42.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  43. END_MESSAGE_MAP()
  44.  
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // The Doc Template for all controls (sharing the menu nIDMenu)
  48. class CControlsDocTemplate : public CMultiDocTemplate
  49. {
  50. public:
  51.     CControlsDocTemplate(HMENU nIDMenu,UINT nIDResource,
  52.         CRuntimeClass* pDocClass,
  53.         CRuntimeClass* pFrameClass,
  54.         CRuntimeClass* pViewClass) :
  55.         CMultiDocTemplate(nIDResource, pDocClass,
  56.                 pFrameClass, pViewClass)
  57.             {
  58.                 m_hMenuShared = nIDMenu;
  59.             };
  60. protected:
  61.     virtual ~CControlsDocTemplate(){
  62.         m_hMenuShared = NULL;
  63.     }
  64. };
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CMDIBindApp construction
  68. CMDIBindApp::CMDIBindApp()
  69. {
  70.     // TODO: add construction code here,
  71.     // Place all significant initialization in InitInstance
  72. }
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // The one and only CMDIBindApp object
  76.  
  77. CMDIBindApp theApp;
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CMDIBindApp initialization
  81.  
  82. BOOL CMDIBindApp::InitInstance()
  83. {
  84.     AfxEnableControlContainer();
  85.     // Standard initialization
  86.     // If you are not using these features and wish to reduce the size
  87.     // of your final executable, you should remove from the following
  88.     // the specific initialization routines you do not need.
  89.  
  90. #ifdef _AFXDLL
  91.     Enable3dControls();         // Call this when using MFC in a shared DLL
  92. #else
  93.     Enable3dControlsStatic();   // Call this when linking to MFC statically
  94. #endif
  95.  
  96.     LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)
  97.  
  98.     // Register the application's document templates.  Document templates
  99.     // serve as the connection between documents, frame windows and views.
  100.     // Load the menu shared between all templates
  101.     m_hMenuShared = ::LoadMenu(m_hInstance,
  102.         MAKEINTRESOURCE(IDR_CONTROLMENU));
  103.  
  104.  
  105.     CControlsDocTemplate* pRDCTemplate;
  106.     // we need to hold RDC template to force RDC creation at startup
  107.     pRDCTemplate = new CControlsDocTemplate(
  108.         m_hMenuShared,IDR_RDCTYPE,
  109.         RUNTIME_CLASS(CMDIBindDoc),
  110.         RUNTIME_CLASS(CRDCFrame), // RDC child frame
  111.         RUNTIME_CLASS(CRDCView));
  112.     AddDocTemplate(pRDCTemplate);
  113.  
  114.     AddDocTemplate(
  115.         new CControlsDocTemplate(
  116.         m_hMenuShared,IDR_GRIDTYPE,
  117.         RUNTIME_CLASS(CMDIBindDoc),
  118.         RUNTIME_CLASS(CGridFrame), // Grid child frame
  119.         RUNTIME_CLASS(CGridView))
  120.     );
  121.  
  122.     AddDocTemplate(
  123.         new CControlsDocTemplate(
  124.         m_hMenuShared,IDR_MASKTYPE,
  125.         RUNTIME_CLASS(CMDIBindDoc),
  126.         RUNTIME_CLASS(CMaskFrame), // Mask child frame
  127.         RUNTIME_CLASS(CMaskView))
  128.     );
  129.  
  130. // create main MDI Frame window
  131.     CMainFrame* pMainFrame = new CMainFrame;
  132.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  133.         return FALSE;
  134.     m_pMainWnd = pMainFrame;
  135.  
  136.     // Parse command line for standard shell commands, DDE, file open
  137.     CCommandLineInfo cmdInfo;
  138.     ParseCommandLine(cmdInfo);
  139.  
  140.  
  141.     if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
  142.     {   // Don't display a new MDI child window dialog
  143.         // but create a new RDC window during startup
  144.         cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  145.         pRDCTemplate->OpenDocumentFile(NULL);
  146.     }
  147.     else    // Dispatch commands specified on the command line
  148.     if (!ProcessShellCommand(cmdInfo))
  149.         return FALSE;
  150.  
  151.     // The main window has been initialized, so show and update it.
  152.     pMainFrame->ShowWindow(m_nCmdShow);
  153.     pMainFrame->UpdateWindow();
  154.  
  155.     return TRUE;
  156. }
  157.  
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CMDIBindApp commands
  160. int CMDIBindApp::ExitInstance()
  161. {
  162.     ::DestroyMenu(m_hMenuShared);
  163.     return CWinApp::ExitInstance();
  164. }
  165.  
  166. /////////////////////////////////////////////////////////////////////////////
  167. // CAboutDlg dialog used for App About
  168.  
  169. class CAboutDlg : public CDialog
  170. {
  171. public:
  172.     CAboutDlg();
  173.  
  174. // Dialog Data
  175.     //{{AFX_DATA(CAboutDlg)
  176.     enum { IDD = IDD_ABOUTBOX };
  177.     //}}AFX_DATA
  178.  
  179.     // ClassWizard generated virtual function overrides
  180.     //{{AFX_VIRTUAL(CAboutDlg)
  181.     protected:
  182.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  183.     //}}AFX_VIRTUAL
  184.  
  185. // Implementation
  186. protected:
  187.     //{{AFX_MSG(CAboutDlg)
  188.         // No message handlers
  189.     //}}AFX_MSG
  190.     DECLARE_MESSAGE_MAP()
  191. };
  192.  
  193. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  194. {
  195.     //{{AFX_DATA_INIT(CAboutDlg)
  196.     //}}AFX_DATA_INIT
  197. }
  198.  
  199. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  200. {
  201.     CDialog::DoDataExchange(pDX);
  202.     //{{AFX_DATA_MAP(CAboutDlg)
  203.     //}}AFX_DATA_MAP
  204. }
  205.  
  206. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  207.     //{{AFX_MSG_MAP(CAboutDlg)
  208.         // No message handlers
  209.     //}}AFX_MSG_MAP
  210. END_MESSAGE_MAP()
  211.  
  212. // App command to run the dialog
  213. void CMDIBindApp::OnAppAbout()
  214. {
  215.     CAboutDlg aboutDlg;
  216.     aboutDlg.DoModal();
  217. }
  218.