mfc1.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // mfc1.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "MainFrm.h"
  5. #include "mfc1.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. AfxMessageBox(IDP_OLE_INIT_FAILED);
  40. return FALSE;
  41. }
  42. AfxEnableControlContainer();
  43. // Standard initialization
  44. // If you are not using these features and wish to reduce the size
  45. // of your final executable, you should remove from the following
  46. // the specific initialization routines you do not need
  47. // Change the registry key under which our settings are stored
  48. // TODO: You should modify this string to be something appropriate
  49. // such as the name of your company or organization
  50. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  51. LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
  52. // Register the application's document templates. Document templates
  53. // serve as the connection between documents, frame windows and views
  54. CMultiDocTemplate* pDocTemplate;
  55. pDocTemplate =
  56. new CMultiDocTemplate(IDR_mfc1TYPE, RUNTIME_CLASS(Cmfc1Doc),
  57. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  58. RUNTIME_CLASS(Cmfc1View));
  59. if (!pDocTemplate)
  60. return FALSE;
  61. AddDocTemplate(pDocTemplate);
  62. // create main MDI Frame window
  63. CMainFrame* pMainFrame = new CMainFrame;
  64. if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
  65. return FALSE;
  66. m_pMainWnd = pMainFrame;
  67. // call DragAcceptFiles only if there's a suffix
  68. // In an MDI app, this should occur immediately after setting m_pMainWnd
  69. // Enable drag/drop open
  70. m_pMainWnd->DragAcceptFiles();
  71. // Enable DDE Execute open
  72. EnableShellOpen();
  73. RegisterShellFileTypes(TRUE);
  74. // Parse command line for standard shell commands, DDE, file open
  75. CCommandLineInfo cmdInfo;
  76. ParseCommandLine(cmdInfo);
  77. // Dispatch commands specified on the command line. Will return FALSE if
  78. // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
  79. if (!ProcessShellCommand(cmdInfo))
  80. return FALSE;
  81. // The main window has been initialized, so show and update it
  82. pMainFrame->ShowWindow(m_nCmdShow);
  83. pMainFrame->UpdateWindow();
  84. return TRUE;
  85. }
  86. // CAboutDlg dialog used for App About
  87. class CAboutDlg : public CDialog
  88. {
  89. public:
  90. CAboutDlg();
  91. // Dialog Data
  92. enum
  93. {
  94. IDD = IDD_ABOUTBOX
  95. };
  96. protected:
  97. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  98. // Implementation
  99. protected:
  100. DECLARE_MESSAGE_MAP()
  101. };
  102. CAboutDlg::CAboutDlg()
  103. : CDialog(CAboutDlg::IDD)
  104. {
  105. }
  106. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  107. {
  108. CDialog::DoDataExchange(pDX);
  109. }
  110. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  111. END_MESSAGE_MAP()
  112. // App command to run the dialog
  113. void Cmfc1App::OnAppAbout()
  114. {
  115. CAboutDlg aboutDlg;
  116. aboutDlg.DoModal();
  117. }
  118. // Cmfc1App message handlers