home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / dynamenu / dynamenu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  5.3 KB  |  186 lines

  1. // dynamenu.cpp
  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. // Purpose: implementation of the CDynaMenuApp class
  14. //
  15. // Functions:
  16. //      Most of this file was generated by AppWizard.  The functions
  17. //      which contain code specific to this sample are:
  18. //
  19. //      CDynaMenuApp::InitInstance()         -- per-instance initialization
  20.  
  21. #include "stdafx.h"
  22. #include "dynamenu.h"
  23.  
  24. #include "mainfrm.h"
  25. #include "dmdoc.h"
  26. #include "dmview.h"
  27.  
  28. #include "mdichild.h" // Our private CMDIChildWnd class
  29.  
  30. #ifdef _DEBUG
  31. #undef THIS_FILE
  32. static char BASED_CODE THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CDynaMenuApp
  37.  
  38. BEGIN_MESSAGE_MAP(CDynaMenuApp, CWinApp)
  39.     //{{AFX_MSG_MAP(CDynaMenuApp)
  40.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  41.         // NOTE - the ClassWizard will add and remove mapping macros here.
  42.         //    DO NOT EDIT what you see in these blocks of generated code!
  43.     //}}AFX_MSG_MAP
  44.     // Standard file based document commands
  45.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  46.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  47.     // Standard print setup command
  48.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  49. END_MESSAGE_MAP()
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CDynaMenuApp construction
  53.  
  54. CDynaMenuApp::CDynaMenuApp()
  55. {
  56.     // TODO: add construction code here,
  57.     // Place all significant initialization in InitInstance
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // The one and only CDynaMenuApp object
  62.  
  63. CDynaMenuApp NEAR theApp;
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CDynaMenuApp initialization
  67.  
  68. //***********************************************************************
  69. // Function: CDynaMenuApp::InitInstance()
  70. //
  71. // Purpose:
  72. //      InitInstance is called by the framework to perform per-instance
  73. //      initialization of the application.
  74. //
  75. //      This function is the code generated by AppWizard with one
  76. //      exception - we use our own class for the frame window attached
  77. //      to a document template, instead of using CMDIChildWnd.
  78. //
  79. // Parameters:
  80. //      none
  81. //
  82. // Returns:
  83. //      nonzero if successful, otherwise 0
  84. //
  85. // Comments:
  86. //      see the CWinApp::InitInstance() documentation for further info.
  87. //
  88. //***********************************************************************
  89. BOOL CDynaMenuApp::InitInstance()
  90. {
  91.     // Standard initialization
  92.     // If you are not using these features and wish to reduce the size
  93.     //  of your final executable, you should remove from the following
  94.     //  the specific initialization routines you do not need.
  95.  
  96.     SetDialogBkColor();        // Set dialog background color to gray
  97.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  98.  
  99.     // Register the application's document templates.  Document templates
  100.     //  serve as the connection between documents, frame windows and views.
  101.  
  102.     CMultiDocTemplate* pDocTemplate;
  103.     pDocTemplate = new CMultiDocTemplate(
  104.         IDR_DYMENUTYPE,
  105.         RUNTIME_CLASS(CDynaMenuDoc),
  106.         RUNTIME_CLASS(CDynaMDIChildWnd),        // our private MDI child class!!
  107.         RUNTIME_CLASS(CDynaMenuView));
  108.     AddDocTemplate(pDocTemplate);
  109.  
  110.     // create main MDI Frame window
  111.     CMainFrame* pMainFrame = new CMainFrame;
  112.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  113.         return FALSE;
  114.     m_pMainWnd = pMainFrame;
  115.  
  116.     // enable file manager drag/drop and DDE Execute open
  117.     EnableShellOpen();
  118.     RegisterShellFileTypes(TRUE);
  119.  
  120.     // Parse command line for standard shell commands, DDE, file open
  121.     CCommandLineInfo cmdInfo;
  122.     ParseCommandLine(cmdInfo);
  123.  
  124.     // Dispatch commands specified on the command line
  125.     if (!ProcessShellCommand(cmdInfo))
  126.         return FALSE;
  127.  
  128.     m_pMainWnd->DragAcceptFiles();
  129.     // The main window has been initialized, so show and update it.
  130.     pMainFrame->ShowWindow(m_nCmdShow);
  131.     pMainFrame->UpdateWindow();
  132.  
  133.     return TRUE;
  134. }
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CAboutDlg dialog used for App About
  138.  
  139. class CAboutDlg : public CDialog
  140. {
  141. public:
  142.     CAboutDlg();
  143.  
  144. // Dialog Data
  145.     //{{AFX_DATA(CAboutDlg)
  146.     enum { IDD = IDD_ABOUTBOX };
  147.     //}}AFX_DATA
  148.  
  149. // Implementation
  150. protected:
  151.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  152.     //{{AFX_MSG(CAboutDlg)
  153.         // No message handlers
  154.     //}}AFX_MSG
  155.     DECLARE_MESSAGE_MAP()
  156. };
  157.  
  158. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  159. {
  160.     //{{AFX_DATA_INIT(CAboutDlg)
  161.     //}}AFX_DATA_INIT
  162. }
  163.  
  164. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  165. {
  166.     CDialog::DoDataExchange(pDX);
  167.     //{{AFX_DATA_MAP(CAboutDlg)
  168.     //}}AFX_DATA_MAP
  169. }
  170.  
  171. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  172.     //{{AFX_MSG_MAP(CAboutDlg)
  173.         // No message handlers
  174.     //}}AFX_MSG_MAP
  175. END_MESSAGE_MAP()
  176.  
  177. // App command to run the dialog
  178. void CDynaMenuApp::OnAppAbout()
  179. {
  180.     CAboutDlg aboutDlg;
  181.     aboutDlg.DoModal();
  182. }
  183.  
  184. /////////////////////////////////////////////////////////////////////////////
  185. // CDynaMenuApp commands
  186.