void AfxGlobalsRelease() { InterlockedDecrement(&g_dwAfxGlobalDataRef); if (g_dwAfxGlobalDataRef == 0) { ControlBarCleanUp(); } }
BOOL CvJoyListApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("Local AppWizard-Generated Applications")); CvJoyListDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n"); } #ifndef _AFXDLL ControlBarCleanUp(); #endif // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
BOOL CGrabXmlApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); __super::InitInstance(); AfxEnableControlContainer(); // Create the shell manager, in case the dialog contains // any shell tree view or shell list view controls. CShellManager *pShellManager = new CShellManager; // Activate "Windows Native" visual manager for enabling themes in MFC controls CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("Local AppWizard-Generated Applications")); CGrabXmlDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n"); TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n"); } if (pShellManager != NULL) { delete pShellManager; } #ifndef _AFXDLL ControlBarCleanUp(); #endif return FALSE; }
int CAlarmCenterApp::ExitInstance() { ControlBarCleanUp(); CLOSEHANDLE(m_hMutex); //CefShutdown(); WSACleanup(); CWinApp::ExitInstance(); CAppResource::release_singleton(); util::CConfigHelper::release_singleton(); core::user_manager::release_singleton(); res::release_singleton(); return exit_code_; }
BOOL CDiskFormatApp::InitInstance() { // 응용 프로그램 매니페스트가 ComCtl32.dll 버전 6 이상을 사용하여 비주얼 스타일을 // 사용하도록 지정하는 경우, Windows XP 상에서 반드시 InitCommonControlsEx()가 필요합니다. // InitCommonControlsEx()를 사용하지 않으면 창을 만들 수 없습니다. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 응용 프로그램에서 사용할 모든 공용 컨트롤 클래스를 포함하도록 // 이 항목을 설정하십시오. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); // 대화 상자에 셸 트리 뷰 또는 // 셸 목록 뷰 컨트롤이 포함되어 있는 경우 셸 관리자를 만듭니다. CShellManager *pShellManager = new CShellManager; // MFC 컨트롤의 테마를 사용하기 위해 "Windows 원형" 비주얼 관리자 활성화 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // 표준 초기화 // 이들 기능을 사용하지 않고 최종 실행 파일의 크기를 줄이려면 // 아래에서 필요 없는 특정 초기화 // 루틴을 제거해야 합니다. // 해당 설정이 저장된 레지스트리 키를 변경하십시오. // TODO: 이 문자열을 회사 또는 조직의 이름과 같은 // 적절한 내용으로 수정해야 합니다. SetRegistryKey(_T("로컬 응용 프로그램 마법사에서 생성된 응용 프로그램")); CDiskFormatDlg 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"); TRACE(traceAppMsg, 0, "경고: 대화 상자에서 MFC 컨트롤을 사용하는 경우 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS를 수행할 수 없습니다.\n"); } // 위에서 만든 셸 관리자를 삭제합니다. if (pShellManager != nullptr) { delete pShellManager; } #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) ControlBarCleanUp(); #endif // 대화 상자가 닫혔으므로 응용 프로그램의 메시지 펌프를 시작하지 않고 응용 프로그램을 끝낼 수 있도록 FALSE를 // 반환합니다. return FALSE; }
BOOL CSliderSampleApp::InitInstance() { // アプリケーション マニフェストが visual スタイルを有効にするために、 // ComCtl32.dll Version 6 以降の使用を指定する場合は、 // Windows XP に InitCommonControlsEx() が必要です。さもなければ、ウィンドウ作成はすべて失敗します。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // アプリケーションで使用するすべてのコモン コントロール クラスを含めるには、 // これを設定します。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); // ダイアログにシェル ツリー ビューまたはシェル リスト ビュー コントロールが // 含まれている場合にシェル マネージャーを作成します。 CShellManager *pShellManager = new CShellManager; // MFC コントロールでテーマを有効にするために、"Windows ネイティブ" のビジュアル マネージャーをアクティブ化 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // 標準初期化 // これらの機能を使わずに最終的な実行可能ファイルの // サイズを縮小したい場合は、以下から不要な初期化 // ルーチンを削除してください。 // 設定が格納されているレジストリ キーを変更します。 // TODO: 会社名または組織名などの適切な文字列に // この文字列を変更してください。 SetRegistryKey(_T("アプリケーション ウィザードで生成されたローカル アプリケーション")); CSliderSampleDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: ダイアログが <OK> で消された時のコードを // 記述してください。 } else if (nResponse == IDCANCEL) { // TODO: ダイアログが <キャンセル> で消された時のコードを // 記述してください。 } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "警告: ダイアログの作成に失敗しました。アプリケーションは予期せずに終了します。\n"); TRACE(traceAppMsg, 0, "警告: ダイアログで MFC コントロールを使用している場合、#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS を指定できません。\n"); } // 上で作成されたシェル マネージャーを削除します。 if (pShellManager != nullptr) { delete pShellManager; } #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) ControlBarCleanUp(); #endif // ダイアログは閉じられました。アプリケーションのメッセージ ポンプを開始しないで // アプリケーションを終了するために FALSE を返してください。 return FALSE; }
BOOL CTrafficMonitorApp::InitInstance() { //设置配置文件的路径 wchar_t path[MAX_PATH]; GetModuleFileNameW(NULL, path, MAX_PATH); m_module_path = path; m_system_path = CCommon::GetSystemPath(); m_temp_path = CCommon::GetTemplatePath(); m_app_data_cfg_path = CCommon::GetAppDataConfigPath(); #ifdef _DEBUG m_config_path = L".\\config.ini"; m_history_traffic_path = L".\\history_traffic.dat"; m_log_path = L".\\error.log"; m_skin_path = L".\\skins"; #else //AppData里面的程序配置文件路径 m_config_path = m_app_data_cfg_path + L"config.ini"; m_history_traffic_path = m_app_data_cfg_path + L"history_traffic.dat"; m_log_path = m_app_data_cfg_path + L"error.log"; //原来的、程序所在目录下的配置文件的路径 wstring exe_path = CCommon::GetExePath(); wstring config_path_old = exe_path + L"config.ini"; wstring history_traffic_path_old = exe_path + L"history_traffic.dat"; wstring log_path_old = exe_path + L"error.log"; //如果程序所在目录下含有配置文件,则将其移动到AppData对应的目录下面 CCommon::MoveAFile(config_path_old.c_str(), m_config_path.c_str()); CCommon::MoveAFile(history_traffic_path_old.c_str(), m_history_traffic_path.c_str()); CCommon::MoveAFile(log_path_old.c_str(), m_log_path.c_str()); m_skin_path = exe_path + L"skins"; #endif m_is_windows10_fall_creator = CCommon::IsWindows10FallCreatorOrLater(); //从ini文件载入设置 LoadConfig(); //初始化界面语言 CCommon::SetThreadLanguage(m_general_data.language); #ifndef _DEBUG wstring cmd_line{ m_lpCmdLine }; bool is_restart{ cmd_line.find(L"RestartByRestartManager") != wstring::npos }; //如果命令行参数中含有字符串“RestartByRestartManager”则说明程序是被Windows重新启动的 //bool when_start{ CCommon::WhenStart(m_no_multistart_warning_time) }; if (is_restart && m_is_windows10_fall_creator) //当前Windows版本是秋季创意者更新时,如果程序被重新启动,则直接退出程序 { //AfxMessageBox(_T("调试信息:程序已被Windows的重启管理器重新启动。")); return FALSE; } //检查是否已有实例正在运行 HANDLE hMutex = ::CreateMutex(NULL, TRUE, _T("TrafficMonitor-1419J3XLKL1w8OZc")); if (hMutex != NULL) { if (GetLastError() == ERROR_ALREADY_EXISTS) { //char buff[128]; //string cmd_line_str{ CCommon::UnicodeToStr(cmd_line.c_str()) }; //sprintf_s(buff, "when_start=%d, m_no_multistart_warning=%d, cmd_line=%s", when_start, m_no_multistart_warning, cmd_line_str.c_str()); //CCommon::WriteLog(buff, _T(".\\start.log")); if (!m_no_multistart_warning) { AfxMessageBox(CCommon::LoadText(IDS_AN_INSTANCE_RUNNING)); } return FALSE; } } #endif SaveConfig(); // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); // 创建 shell 管理器,以防对话框包含 // 任何 shell 树视图控件或 shell 列表视图控件。 CShellManager *pShellManager = new CShellManager; // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); //启动时检查更新 if (m_general_data.check_update_when_start) { m_pUpdateThread = AfxBeginThread(CheckUpdateThreadFunc, NULL); } CTrafficMonitorDlg 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"); TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); } // 删除上面创建的 shell 管理器。 if (pShellManager != NULL) { delete pShellManager; } #ifndef _AFXDLL ControlBarCleanUp(); #endif // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }
BOOL CKTVStartApp::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 // Enable High-DPI support on Windows 7 or newer. CefEnableHighDPISupport(); //wchar_t path[MAX_PATH]; //GetModuleFileName(NULL, path, sizeof(path)); ////判断环境是否为WOW64 //BOOL isWOW64; //REGSAM p; //IsWow64Process(GetCurrentProcess(), &isWOW64); //if (isWOW64) { // p = KEY_WRITE | KEY_WOW64_64KEY; //} //else { // p = KEY_WRITE; //} //HKEY hKey; //if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, NULL, 0, p, NULL, &hKey, NULL) != ERROR_SUCCESS) { // //失败 // return 0; //} //if (RegSetValueEx(hKey, TEXT("KTVStart"), 0, REG_SZ, (BYTE*)path, sizeof(path) * sizeof(TCHAR)) != ERROR_SUCCESS) { // //失败 // return 0; //} //RegCloseKey(hKey); CefMainArgs main_args(theApp.m_hInstance); CefRefPtr<SimpleApp> app(new SimpleApp); int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) { exit(exit_code); } CefSettings settings; //settings.log_severity = LOGSEVERITY_DISABLE; settings.ignore_certificate_errors = true; //settings.command_line_args_disabled = 0; //settings.Add("enable-media-stream", "enable-media-stream"); CefSettingsTraits::init(&settings); settings.multi_threaded_message_loop = true; CefInitialize(main_args, settings, app.get(), NULL); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); // 创建 shell 管理器,以防对话框包含 // 任何 shell 树视图控件或 shell 列表视图控件。 CShellManager *pShellManager = new CShellManager; // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); // 安装钩子 //g_HookHwnd = SetWindowsHookEx(WH_KEYBOARD_LL, MyHookFun, m_hInstance, 0); CKTVStartDlg 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"); TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); } // 删除上面创建的 shell 管理器。 if (pShellManager != NULL) { delete pShellManager; } #ifndef _AFXDLL ControlBarCleanUp(); #endif // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }
BOOL CMFC_D3D_SimplificationApp::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); // 创建 shell 管理器,以防对话框包含 // 任何 shell 树视图控件或 shell 列表视图控件。 CShellManager *pShellManager = new CShellManager; // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); CMFC_D3D_SimplificationDlg 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"); TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); } // 删除上面创建的 shell 管理器。 if (pShellManager != NULL) { delete pShellManager; } #ifndef _AFXDLL ControlBarCleanUp(); #endif // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }