BOOL CMEditor2App::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); SetRegistryKey(_T("MEditor2 - MPlayer 首选项")); CString sCmdLine(this->m_lpCmdLine); int OpenType = 0; CString ProgramName; CString program_dir; TCHAR szFilePath[MAX_PATH + 1]; GetModuleFileName(NULL, szFilePath, MAX_PATH); ProgramName.Format(_T("%s"),szFilePath); ProgramName = ProgramName.Right(15); ProgramName.MakeLower(); (_tcsrchr(szFilePath, _T('\\')))[1] = 0; program_dir.Format(_T("%s"),szFilePath); if(sCmdLine.Find(_T("Open Editor")) >= 0 || sCmdLine.Find(_T("--open-ontop")) >= 0) OpenType = 3; CString langfile_tc; CString langfile_en; if(IsFileExist(program_dir + _T("tools\\meditor2.tc.dll"))) langfile_tc = program_dir + _T("tools\\meditor2.tc.dll"); if(IsFileExist(program_dir + _T("tools\\meditor2.en.dll"))) langfile_en = program_dir + _T("tools\\meditor2.en.dll"); if(IsFileExist(program_dir + _T("codecs\\meditor2.tc.dll"))) langfile_tc = program_dir + _T("codecs\\meditor2.tc.dll"); if(IsFileExist(program_dir + _T("codecs\\meditor2.en.dll"))) langfile_en = program_dir + _T("codecs\\meditor2.en.dll"); if(IsFileExist(program_dir + _T("meditor2.tc.dll"))) langfile_tc = program_dir + _T("meditor2.tc.dll"); if(IsFileExist(program_dir + _T("meditor2.en.dll"))) langfile_en = program_dir + _T("meditor2.en.dll"); if(langfile_tc.GetLength()>1 || langfile_en.GetLength()> 1) { AppLanguage = GetPrivateProfileInt(_T("Option"),_T("Language"), 0, program_dir + _T("kk.ini")); if(AppLanguage == 0) { LANGID _SysLangId = GetSystemDefaultLangID(); if(PRIMARYLANGID(_SysLangId) == LANG_CHINESE) { if(SUBLANGID(_SysLangId) == SUBLANG_CHINESE_SIMPLIFIED) AppLanguage = 1; //Simplified Chinese GBK else if(SUBLANGID(_SysLangId) == SUBLANG_CHINESE_TRADITIONAL) AppLanguage = 4; //Traditional Chinese Big5 else AppLanguage = 3; //ANSI } else AppLanguage = 2; //ANSI } } CString strSatellite = _T(""); if(AppLanguage == 2 && langfile_en.GetLength() > 1) strSatellite = langfile_en; else if((AppLanguage == 3 || AppLanguage == 4) && langfile_tc.GetLength() > 1) strSatellite = langfile_tc; hResourceHandleOld = NULL; hResourceHandleMod = NULL; if (strSatellite.GetLength() > 2) { hResourceHandleOld = AfxGetResourceHandle(); hResourceHandleMod = LoadLibrary(strSatellite); if (hResourceHandleMod) AfxSetResourceHandle(hResourceHandleMod); } CMEditor2Dlg dlg; m_pMainWnd = &dlg; dlg.m_OpenType = OpenType; INT_PTR nResponse = dlg.DoModal(); if (hResourceHandleMod) FreeLibrary(hResourceHandleMod); if (nResponse == IDOK) { // “确定”来关闭对话框的代码 } else if (nResponse == IDCANCEL) { // “取消”来关闭对话框的代码 } return FALSE; }
BOOL CWSConfigAssistantApp::InitInstance() { CLimitSingleInstance lsi(SINGLE_INSTANCE_MUTEX_NAME); if ( lsi.IsAnotherInstanceRunning() ) { MessageBox(NULL, _T("An instance of Workshare Configuration Assistant is already running. Please close that to run another instance."), _T("Workshare"), MB_OK | MB_ICONWARNING); return FALSE; } if( m_pInstallAgent ) { m_pInstallAgent->Initialize(); // workaround for imanage f*****g up our current path // stores path internally. m_pInstallAgent->GetInstallDir(); } // Ensure Windows Message box displayed when can not load Workshare Message component has correct title free((void*)m_pszAppName); m_pszAppName =_tcsdup(_T("Workshare Configuration Assistant")); CStdString sCmdLine(GetCommandLine()); sCmdLine.MakeLower(); bool bRunTests(sCmdLine.Find(_T("runtests")) != -1); bool bAutoRunTests(sCmdLine.Find(_T("autoruntests")) != -1); bool bRunFunctionalTests(sCmdLine.Find(_T("functionaltests")) != -1); if(bRunTests) { m_iRetCode = RunAppTestsEx(bAutoRunTests, bRunFunctionalTests, false, _T(""), false); CoFreeUnusedLibraries(); return FALSE; } if( m_pInstallAgent && !m_pInstallAgent->WasCommandLineValid()) { AfxMessageBox(m_pInstallAgent->GetCommandLineHelp(),MB_OK); return FALSE; } if(m_pInstallAgent && m_pInstallAgent->IsQuiet()) { if(GetInstallAgent()) GetInstallAgent()->LogEvent(_T("CWSConfigAssistantApp::OnInitDialog - Quiet Silent version of the application.")); SafeDeleteSingleItem(m_pInstallAgent); m_pInstallAgent = NULL; CQuietProgressDlg dlg; dlg.DoModal(); m_iRetCode = dlg.GetResult(); } else if (!IsSilent()) { if(GetInstallAgent()) GetInstallAgent()->LogEvent(_T("CWSConfigAssistantApp::OnInitDialog - Running UI version of the application.")); CWSConfigAssistantDlg dlg(_T("Workshare")); dlg.SetWizardMode(); m_pMainWnd = &dlg; if( ::IsWindow(dlg.m_hWnd) ) dlg.SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); INT_PTR ret = dlg.DoModal(); if (ret == IDCANCEL) { m_iRetCode = 1602; } } else { if(GetInstallAgent()) GetInstallAgent()->LogEvent(_T("CWSConfigAssistantApp::OnInitDialog - Running Silent version of the application.")); SafeDeleteSingleItem(m_pInstallAgent); m_pInstallAgent = NULL; CStdString sResult; m_iRetCode = InstallAgent::Run(GetCommandLine(), sResult); } return FALSE; }