mfc1.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // mfc1.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "mfc1.h"
  5. #include "MainFrm.h"
  6. #include "ChildFrm.h"
  7. #include "mfc1Doc.h"
  8. #include "mfc1View.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // Cmfc1App
  13. BEGIN_MESSAGE_MAP(Cmfc1App, CWinApp)
  14. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  15. // Standard file based document commands
  16. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  17. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  18. // Standard print setup command
  19. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  20. END_MESSAGE_MAP()
  21. // Cmfc1App construction
  22. Cmfc1App::Cmfc1App()
  23. {
  24. // TODO: add construction code here,
  25. // Place all significant initialization in InitInstance
  26. }
  27. // The one and only Cmfc1App object
  28. Cmfc1App theApp;
  29. // Cmfc1App initialization
  30. BOOL Cmfc1App::InitInstance()
  31. {
  32. // InitCommonControls() is required on Windows XP if an application
  33. // manifest specifies use of ComCtl32.dll version 6 or later to enable
  34. // visual styles. Otherwise, any window creation will fail.
  35. InitCommonControls();
  36. CWinApp::InitInstance();
  37. // Initialize OLE libraries
  38. if (!AfxOleInit())
  39. {
  40. AfxMessageBox(IDP_OLE_INIT_FAILED);
  41. return FALSE;
  42. }
  43. AfxEnableControlContainer();
  44. // Standard initialization
  45. // If you are not using these features and wish to reduce the size
  46. // of your final executable, you should remove from the following
  47. // the specific initialization routines you do not need
  48. // Change the registry key under which our settings are stored
  49. // TODO: You should modify this string to be something appropriate
  50. // such as the name of your company or organization
  51. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  52. LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
  53. // Register the application's document templates. Document templates
  54. // serve as the connection between documents, frame windows and views
  55. CMultiDocTemplate* pDocTemplate;
  56. pDocTemplate = new CMultiDocTemplate(IDR_mfc1TYPE,
  57. RUNTIME_CLASS(Cmfc1Doc),
  58. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  59. RUNTIME_CLASS(Cmfc1View));
  60. if (!pDocTemplate)
  61. return FALSE;
  62. AddDocTemplate(pDocTemplate);
  63. // create main MDI Frame window
  64. CMainFrame* pMainFrame = new CMainFrame;
  65. if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
  66. return FALSE;
  67. m_pMainWnd = pMainFrame;
  68. // call DragAcceptFiles only if there's a suffix
  69. // In an MDI app, this should occur immediately after setting m_pMainWnd
  70. // Enable drag/drop open
  71. m_pMainWnd->DragAcceptFiles();
  72. // Enable DDE Execute open
  73. EnableShellOpen();
  74. RegisterShellFileTypes(TRUE);
  75. // Parse command line for standard shell commands, DDE, file open
  76. CCommandLineInfo cmdInfo;
  77. ParseCommandLine(cmdInfo);
  78. // Dispatch commands specified on the command line. Will return FALSE if
  79. // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
  80. if (!ProcessShellCommand(cmdInfo))
  81. return FALSE;
  82. // The main window has been initialized, so show and update it
  83. pMainFrame->ShowWindow(m_nCmdShow);
  84. pMainFrame->UpdateWindow();
  85. return TRUE;
  86. }
  87. // CAboutDlg dialog used for App About
  88. class CAboutDlg : public CDialog
  89. {
  90. public:
  91. CAboutDlg();
  92. // Dialog Data
  93. enum { IDD = IDD_ABOUTBOX };
  94. protected:
  95. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  96. // Implementation
  97. protected:
  98. DECLARE_MESSAGE_MAP()
  99. };
  100. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  101. {
  102. }
  103. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  104. {
  105. CDialog::DoDataExchange(pDX);
  106. }
  107. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  108. END_MESSAGE_MAP()
  109. // App command to run the dialog
  110. void Cmfc1App::OnAppAbout()
  111. {
  112. CAboutDlg aboutDlg;
  113. aboutDlg.DoModal();
  114. }
  115. // Cmfc1App message handlers