FieldTestTool.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
  2. // ("Fluent UI"),该示例仅作为参考资料提供,
  3. // 用以补充《Microsoft 基础类参考》和
  4. // MFC C++ 库软件随附的相关电子文档。
  5. // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
  6. // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
  7. // http://msdn.microsoft.com/officeui。
  8. //
  9. // 版权所有 (C) Microsoft Corporation
  10. // 保留所有权利。
  11. // FieldTestTool.cpp : 定义应用程序的类行为。
  12. //
  13. #include "stdafx.h"
  14. #include "afxwinappex.h"
  15. #include "FieldTestTool.h"
  16. #include "MainFrm.h"
  17. #include "ChildFrm.h"
  18. #include "FieldTestToolDoc.h"
  19. #include "FieldTestToolView.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #endif
  23. // CFieldTestToolApp
  24. BEGIN_MESSAGE_MAP(CFieldTestToolApp, CWinAppEx)
  25. ON_COMMAND(ID_APP_ABOUT, &CFieldTestToolApp::OnAppAbout)
  26. // 基于文件的标准文档命令
  27. ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
  28. ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
  29. // 标准打印设置命令
  30. ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
  31. END_MESSAGE_MAP()
  32. // CFieldTestToolApp 构造
  33. CFieldTestToolApp::CFieldTestToolApp()
  34. {
  35. m_bHiColorIcons = TRUE;
  36. // TODO: 在此处添加构造代码,
  37. // 将所有重要的初始化放置在 InitInstance 中
  38. }
  39. // 唯一的一个 CFieldTestToolApp 对象
  40. CFieldTestToolApp theApp;
  41. // CFieldTestToolApp 初始化
  42. BOOL CFieldTestToolApp::InitInstance()
  43. {
  44. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  45. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  46. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  47. INITCOMMONCONTROLSEX InitCtrls;
  48. InitCtrls.dwSize = sizeof(InitCtrls);
  49. // 将它设置为包括所有要在应用程序中使用的
  50. // 公共控件类。
  51. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  52. InitCommonControlsEx(&InitCtrls);
  53. CWinAppEx::InitInstance();
  54. // 初始化 OLE 库
  55. if (!AfxOleInit())
  56. {
  57. AfxMessageBox(IDP_OLE_INIT_FAILED);
  58. return FALSE;
  59. }
  60. AfxEnableControlContainer();
  61. // 标准初始化
  62. // 如果未使用这些功能并希望减小
  63. // 最终可执行文件的大小,则应移除下列
  64. // 不需要的特定初始化例程
  65. // 更改用于存储设置的注册表项
  66. // TODO: 应适当修改该字符串,
  67. // 例如修改为公司或组织名
  68. SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
  69. LoadStdProfileSettings(0); // 加载标准 INI 文件选项
  70. InitContextMenuManager();
  71. InitShellManager();
  72. InitKeyboardManager();
  73. InitTooltipManager();
  74. CMFCToolTipInfo ttParams;
  75. ttParams.m_bVislManagerTheme = TRUE;
  76. theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
  77. // 获取模块的目录;
  78. TCHAR szDrive[MAX_PATH] = { 0 };
  79. TCHAR szDir[MAX_PATH] = { 0 };
  80. TCHAR szExt[MAX_PATH] = { 0 };
  81. ::GetModuleFileName(NULL, Global::g_szCurModulePath, sizeof(Global::g_szCurModulePath) / sizeof(TCHAR));
  82. _tsplitpath_s(Global::g_szCurModulePath, szDrive, szDir, Global::g_szFna, szExt);
  83. _tcscpy_s(Global::g_szCurModuleDir, szDrive);
  84. _tcscat_s(Global::g_szCurModuleDir, szDir);
  85. #ifdef _DEBUG
  86. //::GetCurrentDirectory(MAX_PATH, Global::g_szCurModuleDir);
  87. //_tcscat_s(Global::g_szCurModuleDir, _T("\\"));
  88. ::SetCurrentDirectory(Global::g_szCurModuleDir);
  89. #endif
  90. Global::GetConfig();
  91. // 注册应用程序的文档模板。文档模板
  92. // 将用作文档、框架窗口和视图之间的连接
  93. CMultiDocTemplate* pDocTemplate;
  94. pDocTemplate = new CMultiDocTemplate(IDR_FieldTestToolTYPE,
  95. RUNTIME_CLASS(CFieldTestToolDoc),
  96. RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
  97. RUNTIME_CLASS(CFieldTestToolView));
  98. if (!pDocTemplate)
  99. return FALSE;
  100. AddDocTemplate(pDocTemplate);
  101. // 创建主 MDI 框架窗口
  102. CMainFrame* pMainFrame = new CMainFrame;
  103. pMainFrame->m_pDocTemplate = pDocTemplate;
  104. pMainFrame->m_pDoc = (CFieldTestToolDoc *)pDocTemplate->CreateNewDocument();
  105. if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
  106. {
  107. delete pMainFrame;
  108. return FALSE;
  109. }
  110. m_pMainWnd = pMainFrame;
  111. // 仅当具有后缀时才调用 DragAcceptFiles
  112. // 在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生
  113. // 分析标准外壳命令、DDE、打开文件操作的命令行
  114. CCommandLineInfo cmdInfo;
  115. #ifdef DISABLE_NEWFILE
  116. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  117. #endif
  118. ParseCommandLine(cmdInfo);
  119. // 调度在命令行中指定的命令。如果
  120. // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
  121. if (!ProcessShellCommand(cmdInfo))
  122. return FALSE;
  123. // 主窗口已初始化,因此显示它并对其进行更新
  124. pMainFrame->ShowWindow(m_nCmdShow);
  125. pMainFrame->UpdateWindow();
  126. return TRUE;
  127. }
  128. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  129. class CAboutDlg : public CDialog
  130. {
  131. public:
  132. CAboutDlg();
  133. // 对话框数据
  134. enum { IDD = IDD_ABOUTBOX };
  135. protected:
  136. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  137. // 实现
  138. protected:
  139. DECLARE_MESSAGE_MAP()
  140. };
  141. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  142. {
  143. }
  144. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  145. {
  146. CDialog::DoDataExchange(pDX);
  147. }
  148. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  149. END_MESSAGE_MAP()
  150. // 用于运行对话框的应用程序命令
  151. void CFieldTestToolApp::OnAppAbout()
  152. {
  153. CAboutDlg aboutDlg;
  154. aboutDlg.DoModal();
  155. }
  156. // CFieldTestToolApp 自定义加载/保存方法
  157. void CFieldTestToolApp::PreLoadState()
  158. {
  159. BOOL bNameValid;
  160. CString strName;
  161. bNameValid = strName.LoadString(IDS_EDIT_MENU);
  162. ASSERT(bNameValid);
  163. GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
  164. }
  165. void CFieldTestToolApp::LoadCustomState()
  166. {
  167. }
  168. void CFieldTestToolApp::SaveCustomState()
  169. {
  170. }
  171. // CFieldTestToolApp 消息处理程序