mfc1.cpp 3.8 KB

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