123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
- // ("Fluent UI"),该示例仅作为参考资料提供,
- // 用以补充《Microsoft 基础类参考》和
- // MFC C++ 库软件随附的相关电子文档。
- // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
- // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
- // http://msdn.microsoft.com/officeui。
- //
- // 版权所有 (C) Microsoft Corporation
- // 保留所有权利。
- // FieldTestTool.cpp : 定义应用程序的类行为。
- //
- #include "stdafx.h"
- #include "afxwinappex.h"
- #include "FieldTestTool.h"
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "FieldTestToolDoc.h"
- #include "FieldTestToolView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CFieldTestToolApp
- BEGIN_MESSAGE_MAP(CFieldTestToolApp, CWinAppEx)
- ON_COMMAND(ID_APP_ABOUT, &CFieldTestToolApp::OnAppAbout)
- // 基于文件的标准文档命令
- ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
- // 标准打印设置命令
- ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
- END_MESSAGE_MAP()
- // CFieldTestToolApp 构造
- CFieldTestToolApp::CFieldTestToolApp()
- {
- m_bHiColorIcons = TRUE;
- // TODO: 在此处添加构造代码,
- // 将所有重要的初始化放置在 InitInstance 中
- }
- // 唯一的一个 CFieldTestToolApp 对象
- CFieldTestToolApp theApp;
- // CFieldTestToolApp 初始化
- BOOL CFieldTestToolApp::InitInstance()
- {
- // 如果一个运行在 Windows XP 上的应用程序清单指定要
- // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
- //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
- INITCOMMONCONTROLSEX InitCtrls;
- InitCtrls.dwSize = sizeof(InitCtrls);
- // 将它设置为包括所有要在应用程序中使用的
- // 公共控件类。
- InitCtrls.dwICC = ICC_WIN95_CLASSES;
- InitCommonControlsEx(&InitCtrls);
- CWinAppEx::InitInstance();
- // 初始化 OLE 库
- if (!AfxOleInit())
- {
- AfxMessageBox(IDP_OLE_INIT_FAILED);
- return FALSE;
- }
- AfxEnableControlContainer();
- // 标准初始化
- // 如果未使用这些功能并希望减小
- // 最终可执行文件的大小,则应移除下列
- // 不需要的特定初始化例程
- // 更改用于存储设置的注册表项
- // TODO: 应适当修改该字符串,
- // 例如修改为公司或组织名
- SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
- LoadStdProfileSettings(0); // 加载标准 INI 文件选项
- InitContextMenuManager();
- InitShellManager();
- InitKeyboardManager();
- InitTooltipManager();
- CMFCToolTipInfo ttParams;
- ttParams.m_bVislManagerTheme = TRUE;
- theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
- // 获取模块的目录;
- TCHAR szDrive[MAX_PATH] = { 0 };
- TCHAR szDir[MAX_PATH] = { 0 };
- TCHAR szExt[MAX_PATH] = { 0 };
- ::GetModuleFileName(NULL, Global::g_szCurModulePath, sizeof(Global::g_szCurModulePath) / sizeof(TCHAR));
- _tsplitpath_s(Global::g_szCurModulePath, szDrive, szDir, Global::g_szFna, szExt);
- _tcscpy_s(Global::g_szCurModuleDir, szDrive);
- _tcscat_s(Global::g_szCurModuleDir, szDir);
- #ifdef _DEBUG
- //::GetCurrentDirectory(MAX_PATH, Global::g_szCurModuleDir);
- //_tcscat_s(Global::g_szCurModuleDir, _T("\\"));
- ::SetCurrentDirectory(Global::g_szCurModuleDir);
- #endif
- Global::GetConfig();
- // 注册应用程序的文档模板。文档模板
- // 将用作文档、框架窗口和视图之间的连接
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(IDR_FieldTestToolTYPE,
- RUNTIME_CLASS(CFieldTestToolDoc),
- RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
- RUNTIME_CLASS(CFieldTestToolView));
- if (!pDocTemplate)
- return FALSE;
- AddDocTemplate(pDocTemplate);
- // 创建主 MDI 框架窗口
- CMainFrame* pMainFrame = new CMainFrame;
- pMainFrame->m_pDocTemplate = pDocTemplate;
- pMainFrame->m_pDoc = (CFieldTestToolDoc *)pDocTemplate->CreateNewDocument();
- if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
- {
- delete pMainFrame;
- return FALSE;
- }
- m_pMainWnd = pMainFrame;
- // 仅当具有后缀时才调用 DragAcceptFiles
- // 在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生
- // 分析标准外壳命令、DDE、打开文件操作的命令行
- CCommandLineInfo cmdInfo;
- #ifdef DISABLE_NEWFILE
- cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
- #endif
- ParseCommandLine(cmdInfo);
- // 调度在命令行中指定的命令。如果
- // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
- // 主窗口已初始化,因此显示它并对其进行更新
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
- return TRUE;
- }
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // 用于运行对话框的应用程序命令
- void CFieldTestToolApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- // CFieldTestToolApp 自定义加载/保存方法
- void CFieldTestToolApp::PreLoadState()
- {
- BOOL bNameValid;
- CString strName;
- bNameValid = strName.LoadString(IDS_EDIT_MENU);
- ASSERT(bNameValid);
- GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
- }
- void CFieldTestToolApp::LoadCustomState()
- {
- }
- void CFieldTestToolApp::SaveCustomState()
- {
- }
- // CFieldTestToolApp 消息处理程序
|