[!if RIBBON_TOOLBAR] // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面 // (“Fluent UI”)。该示例仅供参考, // 用以补充《Microsoft 基础类参考》和 // MFC C++ 库软件随附的相关电子文档。 // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。 // 若要了解有关 Fluent UI 许可计划的详细信息,请访问 // https://go.microsoft.com/fwlink/?LinkId=238214 | w. // // 版权所有(C) Microsoft Corporation // 保留所有权利。 [!endif] // $appimpl$: 定义应用程序的类行为。 // #include "pch.h" #include "framework.h" #include "$appheader$" #include "$dialogheader$" #ifdef _DEBUG #define new DEBUG_NEW #endif // $appclass$ BEGIN_MESSAGE_MAP($appclass$, $appbaseclass$) ON_COMMAND(ID_HELP, &CWinApp::OnHelp) END_MESSAGE_MAP() // $appclass$ 构造 $appclass$::$appclass$() { [!if RESTART_MGR_SUPPORT] // 支持重新启动管理器 m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; [!endif] // TODO: 在此处添加构造代码, // 将所有重要的初始化放置在 InitInstance 中 } // 唯一的 $appclass$ 对象 $appclass$ theApp; [!if AUTOMATION] const GUID CDECL BASED_CODE _tlid = $guid_lib_id_staticconst$; const WORD _wVerMajor = 1; const WORD _wVerMinor = 0; [!endif] // $appclass$ 初始化 BOOL $appclass$::InitInstance() { [!if MANIFEST] // 如果应用程序存在以下情况,Windows XP 上需要 InitCommonControlsEx() // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); [!endif] $appbaseclass$::InitInstance(); [!if SOCKETS] if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } [!endif] [!if AUTOMATION || ACCESSIBILITY] // 初始化 OLE 库 if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } [!endif] [!if ACTIVEX_CONTROLS] AfxEnableControlContainer(); [!endif] [!if !NO_MFC_CONTROLS] // 创建 shell 管理器,以防对话框包含 // 任何 shell 树视图控件或 shell 列表视图控件。 CShellManager *pShellManager = new CShellManager; // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); [!endif] // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); [!if AUTOMATION] // 分析自动化开关或注册/注销开关的命令行。 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 应用程序是用 /Embedding 或 /Automation 开关启动的。 //使应用程序作为自动化服务器运行。 if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { // 通过 CoRegisterClassObject() 注册类工厂。 COleTemplateServer::RegisterAll(); } // 应用程序是用 /Unregserver 或 /Unregister 开关启动的。 移除 // 注册表中的项。 else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { COleObjectFactory::UpdateRegistryAll(FALSE); AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor); return FALSE; } // 应用程序是以独立方式或用其他开关(如 /Register // 或 /Regserver)启动的。 更新注册表项,包括类型库。 else { COleObjectFactory::UpdateRegistryAll(); AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid); if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister) return FALSE; } [!endif] $dialogclass$ dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: 在此放置处理何时用 // “确定”来关闭对话框的代码 } else if (nResponse == IDCANCEL) { // TODO: 在此放置处理何时用 // “取消”来关闭对话框的代码 } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); [!if !NO_MFC_CONTROLS] TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); [!endif] } [!if !NO_MFC_CONTROLS] // 删除上面创建的 shell 管理器。 if (pShellManager != nullptr) { delete pShellManager; } [!endif] #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) ControlBarCleanUp(); #endif // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; } [!if AUTOMATION || ACCESSIBILITY] int $appclass$::ExitInstance() { AfxOleTerm(FALSE); return $appbaseclass$::ExitInstance(); } [!endif]