int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { CefEnableHighDPISupport(); CefMainArgs mainArgs(hInst); CefRefPtr<CefCommandLine> cmdLine = CefCommandLine::CreateCommandLine(); cmdLine->InitFromString(::GetCommandLineW()); CefRefPtr<CefApp> app; auto appType = GetAppType(cmdLine); if (appType == AppType::BROWSER) app = new BrowserApp(); else if (appType == AppType::RENDERER) app = new RendererApp(); int exitCode = CefExecuteProcess(mainArgs, app, nullptr); if (exitCode >= 0) return exitCode; CefSettings settings; settings.no_sandbox = true; settings.remote_debugging_port = 1337; CefString(&settings.cache_path).FromASCII("./cache/"); CefInitialize(mainArgs, settings, app, nullptr); CefRunMessageLoop(); CefShutdown(); return 0; }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); CefEnableHighDPISupport(); CefScopedSandboxInfo scoped_sandbox; CefMainArgs main_args(hInstance); CefRefPtr<NgineSlackApp> app(new NgineSlackApp); int exit_code = CefExecuteProcess(main_args, app.get(), scoped_sandbox.sandbox_info()); if (exit_code >= 0) { return exit_code; } LimitSingleInstance lsi(NGINESLACK); if (lsi.IsAnotherInstanceRunning()) { HWND hWnd = FindWindow(NGINESLACK, NULL); if( hWnd==NULL ) { MessageBox(NULL, L"Already running. You need to terminate it manually.", NGINESLACK, MB_OK); } else { ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); } return 0; } _AtlBaseModule.SetResourceInstance(hInstance); GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); CefSettings settings; CefSetting_SetCachePath(settings); settings.persist_session_cookies = TRUE; settings.log_severity = LOGSEVERITY_DISABLE; settings.ignore_certificate_errors = TRUE; CefInitialize(main_args, settings, app.get(), scoped_sandbox.sandbox_info()); CefRunMessageLoop(); CefShutdown(); return 0; }
int main(int argc, char* argv[]) { CefEnableHighDPISupport(); CefMainArgs mainArgs(argc, argv); auto cmdLine = CefCommandLine::CreateCommandLine(); cmdLine->InitFromArgv(argc, argv); std::string configPath = cmdLine->GetSwitchValue("config").ToString(); if (configPath.empty()) { configPath = "config.default.json"; } AppConfig config; if (!LoadAppConfig(configPath.c_str(), &config)) { return -1; } CefRefPtr<CefApp> app(new App(config)); int exitCode = CefExecuteProcess(mainArgs, app, nullptr); if (exitCode >= 0) { return exitCode; } CefSettings settings; settings.no_sandbox = true; settings.remote_debugging_port = 1337; settings.single_process = false; CefString(&settings.cache_path).FromASCII(CACHE_PATH); CefInitialize(mainArgs, settings, app, nullptr); CefRunMessageLoop(); CefShutdown(); return 0; }
int main(int argc, char *argv[]) { if (IsSubprocess(argc, argv)) { // QMessageBox::about(NULL, "1", "2"); return RunCefSubprocess(argc, argv); } // argc = 2; // argv[1] = "--ppapi-flash-path=plugins\\pepflashplayer.dll"; QApplication a(argc, argv); // Enable High-DPI support on Windows 7 or newer. CefEnableHighDPISupport(); void* sandbox_info = NULL; #if defined(CEF_USE_SANDBOX) // Manage the life span of the sandbox information object. This is necessary // for sandbox support on Windows. See cef_sandbox_win.h for complete details. CefScopedSandboxInfo scoped_sandbox; sandbox_info = scoped_sandbox.sandbox_info(); #endif HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); // Provide CEF with command-line arguments. CefMainArgs main_args(hInstance); // SimpleApp implements application-level callbacks. It will create the first // browser instance in OnContextInitialized() after CEF has initialized. // QMessageBox::about(NULL, "main", "1"); CefRefPtr<SimpleApp> app(new SimpleApp()); // CEF applications have multiple sub-processes (render, plugin, GPU, etc) // that share the same executable. This function checks the command-line and, // if this is a sub-process, executes the appropriate logic. // QMessageBox::about(NULL, "main", "2"); // int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info); // // The sub-process has completed so return here. // QMessageBox::about(NULL, "main", QString("%1").arg(exit_code)); // // if (exit_code >= 0) { // QMessageBox::about(NULL, "main", "3"); // return 0; // } // QMessageBox::about(NULL, "main", "4"); // Specify CEF global settings here. CefSettings settings; #if !defined(CEF_USE_SANDBOX) settings.no_sandbox = true; #endif settings.multi_threaded_message_loop = true; settings.remote_debugging_port = 2012; // settings.single_process = true; // Initialize CEF. CefInitialize(main_args, settings, app.get(), sandbox_info); QtCef w; w.show(); int result = a.exec(); // Shut down CEF. #ifndef _DEBUG CefShutdown(); #endif // _DEBUG return result; }
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; }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #else int main(int argc, char* argv[]) { #endif // Do all the standard CEF setup stuff. //------------------------------------- void * sandbox_info = nullptr; #ifdef _WIN32 // Enable High-DPI support on Windows 7 or newer. CefEnableHighDPISupport(); // Read command line arguments. CefMainArgs main_args(hInstance); #else // Read command line arguments. CefMainArgs main_args(argc, argv); #endif // Create the process reference. CefRefPtr<loot::LootApp> app(new loot::LootApp); // Run the process. int exit_code = CefExecuteProcess(main_args, app.get(), nullptr); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; } #ifdef _WIN32 // Check if LOOT is already running //--------------------------------- HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, L"LOOT.Shell.Instance"); if (hMutex != NULL) { // An instance of LOOT is already running, so focus its window then quit. HWND hWnd = ::FindWindow(NULL, L"LOOT"); ::SetForegroundWindow(hWnd); return 0; } else { //Create the mutex so that future instances will not run. hMutex = ::CreateMutex(NULL, FALSE, L"LOOT.Shell.Instance"); } #endif // Handle command line args (not CEF args) //---------------------------------------- processCommandLineArguments(app); // Back to CEF //------------ // Initialise CEF settings. CefSettings cef_settings = GetCefSettings(); #ifndef _WIN32 // Install xlib error handlers so that the application won't be terminated // on non-fatal errors. XSetErrorHandler(XErrorHandlerImpl); XSetIOErrorHandler(XIOErrorHandlerImpl); #endif // Initialize CEF. CefInitialize(main_args, cef_settings, app.get(), sandbox_info); // Run the CEF message loop. This will block until CefQuitMessageLoop() is called. CefRunMessageLoop(); // Shut down CEF. CefShutdown(); #ifdef _WIN32 // Release the program instance mutex. if (hMutex != NULL) ReleaseMutex(hMutex); #endif return 0; }