// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); // Determine if we should use an already running instance of Brackets. HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, FIRST_INSTANCE_MUTEX_NAME); if ((hMutex != NULL) && AppGetCommandLine()->HasArguments() && (lpCmdLine != NULL)) { // for subsequent instances, re-use an already running instance if we're being called to // open an existing file on the command-line (eg. Open With.. from Windows Explorer) HWND hFirstInstanceWnd = cef_main_window::FindFirstTopLevelInstance(); if (hFirstInstanceWnd != NULL) { ::SetForegroundWindow(hFirstInstanceWnd); if (::IsIconic(hFirstInstanceWnd)) ::ShowWindow(hFirstInstanceWnd, SW_RESTORE); // message the other Brackets instance to actually open the given filename std::wstring wstrFilename = lpCmdLine; ConvertToUnixPath(wstrFilename); // note: WM_COPYDATA will manage passing the string across process space COPYDATASTRUCT data; data.dwData = ID_WM_COPYDATA_SENDOPENFILECOMMAND; data.cbData = (wstrFilename.length() + 1) * sizeof(WCHAR); data.lpData = (LPVOID)wstrFilename.c_str(); ::SendMessage(hFirstInstanceWnd, WM_COPYDATA, (WPARAM)(HWND)hFirstInstanceWnd, (LPARAM)(LPVOID)&data); // exit this instance return 0; } // otherwise, fall thru and launch a new instance } if (hMutex == NULL) { // first instance of this app, so create the mutex and continue execution of this instance. hMutex = ::CreateMutex(NULL, FALSE, FIRST_INSTANCE_MUTEX_NAME); } CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Check command if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = AppGetCachePath(); } // Initialize CEF. CefInitialize(main_args, settings, app.get()); CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine(); if (cmdLine->HasSwitch(cefclient::kStartupPath)) { wcscpy(szInitialUrl, cmdLine->GetSwitchValue(cefclient::kStartupPath).c_str()); } else { // If the shift key is not pressed, look for the index.html file if (GetAsyncKeyState(VK_SHIFT) == 0) { // Get the full pathname for the app. We look for the index.html // file relative to this location. wchar_t appPath[MAX_PATH]; wchar_t *pathRoot; GetModuleFileName(NULL, appPath, MAX_PATH); // Strip the .exe filename (and preceding "\") from the appPath // and store in pathRoot pathRoot = wcsrchr(appPath, '\\'); // Look for .\dev\src\index.html first wcscpy(pathRoot, L"\\dev\\src\\index.html"); // If the file exists, use it if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } if (!wcslen(szInitialUrl)) { // Look for .\www\index.html next wcscpy(pathRoot, L"\\www\\index.html"); if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } } } } if (!wcslen(szInitialUrl)) { // If we got here, either the startup file couldn't be found, or the user pressed the // shift key while launching. Prompt to select the index.html file. OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szInitialUrl; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0"; ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file."; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; if (!GetOpenFileName(&ofn)) { // User cancelled, exit the app CefShutdown(); return 0; } } // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; // Start the node server process startNodeProcess(); gFilesToOpen = GetFilenamesFromCommandLine(); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } OnBeforeShutdown(); // Shut down CEF. CefShutdown(); // release the first instance mutex if (hMutex != NULL) ReleaseMutex(hMutex); return result; }
CefString AppGetCachePath() { std::wstring cachePath = ClientApp::AppGetSupportDirectory(); cachePath += L"/cef_data"; return CefString(cachePath); }
// Returns the application browser settings based on command line arguments. void AppGetBrowserSettings(CefBrowserSettings& settings) { ASSERT(g_command_line.get()); if (!g_command_line.get()) return; settings.remote_fonts_disabled = g_command_line->HasSwitch(cefclient::kRemoteFontsDisabled); CefString(&settings.default_encoding) = g_command_line->GetSwitchValue(cefclient::kDefaultEncoding); settings.encoding_detector_enabled = g_command_line->HasSwitch(cefclient::kEncodingDetectorEnabled); settings.javascript_disabled = g_command_line->HasSwitch(cefclient::kJavascriptDisabled); settings.javascript_open_windows_disallowed = g_command_line->HasSwitch(cefclient::kJavascriptOpenWindowsDisallowed); settings.javascript_close_windows_disallowed = g_command_line->HasSwitch(cefclient::kJavascriptCloseWindowsDisallowed); settings.javascript_access_clipboard_disallowed = g_command_line->HasSwitch( cefclient::kJavascriptAccessClipboardDisallowed); settings.dom_paste_disabled = g_command_line->HasSwitch(cefclient::kDomPasteDisabled); settings.caret_browsing_enabled = g_command_line->HasSwitch(cefclient::kCaretBrowsingDisabled); settings.java_disabled = g_command_line->HasSwitch(cefclient::kJavaDisabled); settings.plugins_disabled = g_command_line->HasSwitch(cefclient::kPluginsDisabled); settings.universal_access_from_file_urls_allowed = g_command_line->HasSwitch(cefclient::kUniversalAccessFromFileUrlsAllowed); settings.file_access_from_file_urls_allowed = g_command_line->HasSwitch(cefclient::kFileAccessFromFileUrlsAllowed); settings.web_security_disabled = g_command_line->HasSwitch(cefclient::kWebSecurityDisabled); settings.xss_auditor_enabled = g_command_line->HasSwitch(cefclient::kXssAuditorEnabled); settings.image_load_disabled = g_command_line->HasSwitch(cefclient::kImageLoadingDisabled); settings.shrink_standalone_images_to_fit = g_command_line->HasSwitch(cefclient::kShrinkStandaloneImagesToFit); settings.site_specific_quirks_disabled = g_command_line->HasSwitch(cefclient::kSiteSpecificQuirksDisabled); settings.text_area_resize_disabled = g_command_line->HasSwitch(cefclient::kTextAreaResizeDisabled); settings.page_cache_disabled = g_command_line->HasSwitch(cefclient::kPageCacheDisabled); settings.tab_to_links_disabled = g_command_line->HasSwitch(cefclient::kTabToLinksDisabled); settings.hyperlink_auditing_disabled = g_command_line->HasSwitch(cefclient::kHyperlinkAuditingDisabled); settings.user_style_sheet_enabled = g_command_line->HasSwitch(cefclient::kUserStyleSheetEnabled); CefString(&settings.user_style_sheet_location) = g_command_line->GetSwitchValue(cefclient::kUserStyleSheetLocation); settings.author_and_user_styles_disabled = g_command_line->HasSwitch(cefclient::kAuthorAndUserStylesDisabled); settings.local_storage_disabled = g_command_line->HasSwitch(cefclient::kLocalStorageDisabled); settings.databases_disabled = g_command_line->HasSwitch(cefclient::kDatabasesDisabled); settings.application_cache_disabled = g_command_line->HasSwitch(cefclient::kApplicationCacheDisabled); settings.webgl_disabled = g_command_line->HasSwitch(cefclient::kWebglDisabled); settings.accelerated_compositing_disabled = g_command_line->HasSwitch(cefclient::kAcceleratedCompositingDisabled); settings.accelerated_layers_disabled = g_command_line->HasSwitch(cefclient::kAcceleratedLayersDisabled); settings.accelerated_video_disabled = g_command_line->HasSwitch(cefclient::kAcceleratedVideoDisabled); settings.accelerated_2d_canvas_disabled = g_command_line->HasSwitch(cefclient::kAcceledated2dCanvasDisabled); settings.accelerated_painting_enabled = g_command_line->HasSwitch(cefclient::kAcceleratedPaintingEnabled); settings.accelerated_filters_enabled = g_command_line->HasSwitch(cefclient::kAcceleratedFiltersEnabled); settings.accelerated_plugins_disabled = g_command_line->HasSwitch(cefclient::kAcceleratedPluginsDisabled); settings.developer_tools_disabled = g_command_line->HasSwitch(cefclient::kDeveloperToolsDisabled); settings.fullscreen_enabled = g_command_line->HasSwitch(cefclient::kFullscreenEnabled); }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow) { g_hInstance = hInstance; json_value* appSettings = GetApplicationSettings(); if (GetApplicationSettingsError().length()) { std::string error = GetApplicationSettingsError(); error.append("\nApplication will terminate immediately. "); FatalError(NULL, error); } // Debugging options. bool show_console = (*appSettings)["debugging"]["show_console"]; bool subprocess_show_console = (*appSettings)["debugging"]["subprocess_show_console"]; std::string log_level = (*appSettings)["debugging"]["log_level"]; std::string log_file = (*appSettings)["debugging"]["log_file"]; log_file = GetAbsolutePath(log_file); // Initialize logging. if (std::wstring(lpstrCmdLine).find(L"--type=") != std::string::npos) { // This is a subprocess. InitializeLogging(subprocess_show_console, log_level, log_file); } else { // Main browser process. InitializeLogging(show_console, log_level, log_file); } // Command line arguments LPWSTR *argv; int argc; argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argv) { for (int i = 0; i < argc; i++) { std::string argument = WideToUtf8(std::wstring(argv[i])); size_t pos = argument.find("="); if (pos != std::string::npos) { std::string name = argument.substr(0, pos); std::string value = argument.substr(pos+1, std::string::npos); if (name == "--cgi-environment" && value.length()) { g_cgiEnvironmentFromArgv.assign(value); } } } } else { LOG_WARNING << "CommandLineToArgvW() failed"; } // CEF subprocesses. CefMainArgs main_args(hInstance); CefRefPtr<App> app(new App); int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) { ShutdownLogging(); return exit_code; } LOG_INFO << "--------------------------------------------------------"; LOG_INFO << "Started application"; if (log_file.length()) LOG_INFO << "Logging to: " << log_file; else LOG_INFO << "No logging file set"; LOG_INFO << "Log level = " << FILELog::ToString(FILELog::ReportingLevel()); // Main window title option. std::string main_window_title = (*appSettings)["main_window"]["title"]; if (main_window_title.empty()) main_window_title = GetExecutableName(); // Single instance guid option. const char* single_instance_guid = (*appSettings)["application"]["single_instance_guid"]; if (single_instance_guid && single_instance_guid[0] != 0) { int guidSize = strlen(single_instance_guid) + 1; g_singleInstanceApplicationGuid = new wchar_t[guidSize]; Utf8ToWide(single_instance_guid, g_singleInstanceApplicationGuid, guidSize); } if (g_singleInstanceApplicationGuid && g_singleInstanceApplicationGuid[0] != 0) { g_singleInstanceApplication.Initialize( g_singleInstanceApplicationGuid); if (g_singleInstanceApplication.IsRunning()) { HWND hwnd = FindWindow(g_singleInstanceApplicationGuid, NULL); if (hwnd) { if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE); SetForegroundWindow(hwnd); return 0; } } } // Window class name. if (g_singleInstanceApplicationGuid) { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", g_singleInstanceApplicationGuid); } else { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", Utf8ToWide(GetExecutableName()).c_str()); } if (!StartWebServer()) { FatalError(NULL, "Error while starting an internal local server.\n" "Application will terminate immediately."); } CefSettings cef_settings; // log_file std::string chrome_log_file = (*appSettings)["chrome"]["log_file"]; chrome_log_file = GetAbsolutePath(chrome_log_file); CefString(&cef_settings.log_file) = chrome_log_file; // log_severity std::string chrome_log_severity = (*appSettings)["chrome"]["log_severity"]; cef_log_severity_t log_severity = LOGSEVERITY_DEFAULT; if (chrome_log_severity == "verbose") { log_severity = LOGSEVERITY_VERBOSE; } else if (chrome_log_severity == "info") { log_severity = LOGSEVERITY_INFO; } else if (chrome_log_severity == "warning") { log_severity = LOGSEVERITY_WARNING; } else if (chrome_log_severity == "error") { log_severity = LOGSEVERITY_ERROR; } else if (chrome_log_severity == "disable") { log_severity = LOGSEVERITY_DISABLE; } cef_settings.log_severity = log_severity; // cache_path std::string cache_path = (*appSettings)["chrome"]["cache_path"]; cache_path = GetAbsolutePath(cache_path); CefString(&cef_settings.cache_path) = cache_path; // remote_debugging_port // A value of -1 will disable remote debugging. int remote_debugging_port = static_cast<long>( (*appSettings)["chrome"]["remote_debugging_port"]); if (remote_debugging_port == 0) { remote_debugging_port = random(49152, 65535+1); int i = 100; while (((i--) > 0) && remote_debugging_port == GetWebServerPort()) { remote_debugging_port = random(49152, 65535+1); } } if (remote_debugging_port > 0) { LOG_INFO << "remote_debugging_port = " << remote_debugging_port; cef_settings.remote_debugging_port = remote_debugging_port; } // Sandbox support cef_settings.no_sandbox = true; CefInitialize(main_args, cef_settings, app.get(), NULL); CreateMainWindow(hInstance, nCmdShow, main_window_title); CefRunMessageLoop(); CefShutdown(); LOG_INFO << "Ended application"; LOG_INFO << "--------------------------------------------------------"; ShutdownLogging(); return 0; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Check command if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = AppGetCachePath(); } // Initialize CEF. CefInitialize(main_args, settings, app.get()); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance, settings.locale); // If the shift key is not pressed, look for the index.html file if (GetAsyncKeyState(VK_SHIFT) == 0) { // Get the full pathname for the app. We look for the index.html // file relative to this location. wchar_t appPath[MAX_PATH]; wchar_t *pathRoot; GetModuleFileName(NULL, appPath, MAX_PATH); // Strip the .exe filename (and preceding "\") from the appPath // and store in pathRoot pathRoot = wcsrchr(appPath, '\\'); // Look for .\dev\src\index.html first wcscpy(pathRoot, L"\\dev\\src\\index.html"); // If the file exists, use it if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } if (!wcslen(szInitialUrl)) { // Look for .\www\index.html next wcscpy(pathRoot, L"\\www\\index.html"); if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } } } if (!wcslen(szInitialUrl)) { // If we got here, either the startup file couldn't be found, or the user pressed the // shift key while launching. Prompt to select the index.html file. OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szInitialUrl; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0"; ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file."; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; if (!GetOpenFileName(&ofn)) { // User cancelled, exit the app CefShutdown(); return 0; } } // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; // Temporary localization hack. Default to English. Check for French. DWORD menuId = IDC_CEFCLIENT; if (settings.locale.str && (settings.locale.length > 0) && (CefString(settings.locale.str) == CefString("fr-FR"))) { menuId = IDC_CEFCLIENT_FR; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(menuId)); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } OnBeforeShutdown(); // Shut down CEF. CefShutdown(); return result; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, stopWnd = NULL, editWnd = NULL; static WNDPROC editWndOldProc = NULL; // Static members used for the find dialog. static FINDREPLACE fr; static WCHAR szFindWhat[80] = {0}; static WCHAR szLastFindWhat[80] = {0}; static bool findNext = false; static bool lastMatchCase = false; int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; #ifdef SHOW_TOOLBAR_UI if (hWnd == editWnd) { // Callback for the edit window switch (message) { case WM_CHAR: if (wParam == VK_RETURN && g_handler.get()) { // When the user hits the enter key load the URL CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); wchar_t strPtr[MAX_URL_LENGTH+1] = {0}; *((LPWORD)strPtr) = MAX_URL_LENGTH; LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr); if (strLen > 0) { strPtr[strLen] = 0; browser->GetMainFrame()->LoadURL(strPtr); } return 0; } } return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam); } else #endif // SHOW_TOOLBAR_UI { // Callback for the main window switch (message) { case WM_CREATE: { // Create the single static handler class instance g_handler = new ClientHandler(); g_handler->SetMainHwnd(hWnd); // Create the child windows used for navigation RECT rect; int x = 0; GetClientRect(hWnd, &rect); #ifdef SHOW_TOOLBAR_UI backWnd = CreateWindow(L"BUTTON", L"Back", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_BACK, hInst, 0); x += BUTTON_WIDTH; forwardWnd = CreateWindow(L"BUTTON", L"Forward", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD, hInst, 0); x += BUTTON_WIDTH; reloadWnd = CreateWindow(L"BUTTON", L"Reload", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD, hInst, 0); x += BUTTON_WIDTH; stopWnd = CreateWindow(L"BUTTON", L"Stop", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_STOP, hInst, 0); x += BUTTON_WIDTH; editWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED, x, 0, rect.right - BUTTON_WIDTH * 4, URLBAR_HEIGHT, hWnd, 0, hInst, 0); // Assign the edit window's WNDPROC to this function so that we can // capture the enter key editWndOldProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC)); SetWindowLongPtr(editWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc)); g_handler->SetEditHwnd(editWnd); g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd); rect.top += URLBAR_HEIGHT; #endif // SHOW_TOOLBAR_UI CefWindowInfo info; CefBrowserSettings settings; // Populate the settings based on command line arguments. AppGetBrowserSettings(settings); settings.file_access_from_file_urls_allowed = true; settings.universal_access_from_file_urls_allowed = true; // Initialize window info to the defaults for a child window info.SetAsChild(hWnd, rect); // Creat the new child browser window CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(g_handler), szInitialUrl, settings); return 0; } case WM_COMMAND: { CefRefPtr<CefBrowser> browser; if (g_handler.get()) browser = g_handler->GetBrowser(); wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_EXIT: if (g_handler.get()) { g_handler->QuittingApp(true); g_handler->DispatchCloseToNextBrowser(); } else { DestroyWindow(hWnd); } return 0; case ID_WARN_CONSOLEMESSAGE: if (g_handler.get()) { std::wstringstream ss; ss << L"Console messages will be written to " << std::wstring(CefString(g_handler->GetLogFile())); MessageBox(hWnd, ss.str().c_str(), L"Console Messages", MB_OK | MB_ICONINFORMATION); } return 0; case ID_WARN_DOWNLOADCOMPLETE: case ID_WARN_DOWNLOADERROR: if (g_handler.get()) { std::wstringstream ss; ss << L"File \"" << std::wstring(CefString(g_handler->GetLastDownloadFile())) << L"\" "; if (wmId == ID_WARN_DOWNLOADCOMPLETE) ss << L"downloaded successfully."; else ss << L"failed to download."; MessageBox(hWnd, ss.str().c_str(), L"File Download", MB_OK | MB_ICONINFORMATION); } return 0; #ifdef SHOW_TOOLBAR_UI case IDC_NAV_BACK: // Back button if (browser.get()) browser->GoBack(); return 0; case IDC_NAV_FORWARD: // Forward button if (browser.get()) browser->GoForward(); return 0; case IDC_NAV_RELOAD: // Reload button if (browser.get()) browser->Reload(); return 0; case IDC_NAV_STOP: // Stop button if (browser.get()) browser->StopLoad(); return 0; #endif // SHOW_TOOLBAR_UI } break; } case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_SETFOCUS: if (g_handler.get() && g_handler->GetBrowser()) { // Pass focus to the browser window CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) PostMessage(hwnd, WM_SETFOCUS, wParam, NULL); } return 0; case WM_SIZE: // Minimizing resizes the window to 0x0 which causes our layout to go all // screwy, so we just ignore it. if (wParam != SIZE_MINIMIZED && g_handler.get() && g_handler->GetBrowser()) { CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Resize the browser window and address bar to match the new frame // window size RECT rect; GetClientRect(hWnd, &rect); #ifdef SHOW_TOOLBAR_UI rect.top += URLBAR_HEIGHT; int urloffset = rect.left + BUTTON_WIDTH * 4; #endif // SHOW_TOOLBAR_UI HDWP hdwp = BeginDeferWindowPos(1); #ifdef SHOW_TOOLBAR_UI hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); #endif // SHOW_TOOLBAR_UI hdwp = DeferWindowPos(hdwp, hwnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER); EndDeferWindowPos(hdwp); } } break; case WM_ERASEBKGND: if (g_handler.get() && g_handler->GetBrowser()) { CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 0; } } break; case WM_CLOSE: if (g_handler.get()) { // If we already initiated the browser closing, then let default window proc handle it. HWND browserHwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); HANDLE closing = GetProp(browserHwnd, CLOSING_PROP); if (closing) { RemoveProp(browserHwnd, CLOSING_PROP); break; } g_handler->QuittingApp(true); g_handler->DispatchCloseToNextBrowser(); return 0; } break; case WM_DESTROY: // The frame window has exited PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } }
void FinalizeInitNUI() { if (getenv("CitizenFX_ToolMode")) { return; } std::wstring cachePath = MakeRelativeCitPath(L"cache\\browser\\"); CreateDirectory(cachePath.c_str(), nullptr); // delete any old CEF logs DeleteFile(MakeRelativeCitPath(L"debug.log").c_str()); auto selfApp = Instance<NUIApp>::Get(); CefMainArgs args(GetModuleHandle(NULL)); CefRefPtr<CefApp> app(selfApp); CefSettings cSettings; cSettings.multi_threaded_message_loop = true; cSettings.remote_debugging_port = 13172; cSettings.pack_loading_disabled = false; // true; cSettings.windowless_rendering_enabled = false; // true; cSettings.log_severity = LOGSEVERITY_DISABLE; CefString(&cSettings.browser_subprocess_path).FromWString(MakeCfxSubProcess(L"ChromeBrowser")); CefString(&cSettings.locale).FromASCII("en-US"); std::wstring resPath = MakeRelativeCitPath(L"bin/cef/"); CefString(&cSettings.resources_dir_path).FromWString(resPath); CefString(&cSettings.locales_dir_path).FromWString(resPath); CefString(&cSettings.cache_path).FromWString(cachePath); // 2014-06-30: sandbox disabled as it breaks scheme handler factories (results in blank page being loaded) CefInitialize(args, cSettings, app.get(), /*cefSandbox*/ nullptr); CefRegisterSchemeHandlerFactory("nui", "", Instance<NUISchemeHandlerFactory>::Get()); CefAddCrossOriginWhitelistEntry("nui://game", "http", "", true); CefAddCrossOriginWhitelistEntry("nui://game", "nui", "", true); HookFunctionBase::RunAll(); #if defined(GTA_NY) OnGrcBeginScene.Connect([] () { Instance<NUIWindowManager>::Get()->ForAllWindows([] (fwRefContainer<NUIWindow> window) { window->UpdateFrame(); }); }); #else #endif //g_hooksDLL->SetHookCallback(StringHash("d3dCreate"), [] (void*) OnGrcCreateDevice.Connect([]() { //int resX = *(int*)0xFDCEAC; //int resY = *(int*)0xFDCEB0; int resX, resY; GetGameResolution(resX, resY); auto rootWindow = NUIWindow::Create(true, resX, resY, "nui://game/ui/root.html"); rootWindow->SetPaintType(NUIPaintTypePostRender); Instance<NUIWindowManager>::Get()->SetRootWindow(rootWindow); }); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, stopWnd = NULL, editWnd = NULL; static WNDPROC editWndOldProc = NULL; // Static members used for the find dialog. static FINDREPLACE fr; static WCHAR szFindWhat[80] = {0}; static WCHAR szLastFindWhat[80] = {0}; static bool findNext = false; static bool lastMatchCase = false; int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; if (hWnd == editWnd) { // Callback for the edit window switch (message) { case WM_CHAR: if (wParam == VK_RETURN && g_handler.get()) { // When the user hits the enter key load the URL CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); wchar_t strPtr[MAX_URL_LENGTH+1] = {0}; *((LPWORD)strPtr) = MAX_URL_LENGTH; LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr); if (strLen > 0) { strPtr[strLen] = 0; browser->GetMainFrame()->LoadURL(strPtr); } return 0; } } return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam); } else if (message == uFindMsg) { // Find event. LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam; if (lpfr->Flags & FR_DIALOGTERM) { // The find dialog box has been dismissed so invalidate the handle and // reset the search results. hFindDlg = NULL; if (g_handler.get()) { g_handler->GetBrowser()->GetHost()->StopFinding(true); szLastFindWhat[0] = 0; findNext = false; } return 0; } if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get()) { // Search for the requested string. bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false); if (matchCase != lastMatchCase || (matchCase && wcsncmp(szFindWhat, szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) || (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) { // The search string has changed, so reset the search results. if (szLastFindWhat[0] != 0) { g_handler->GetBrowser()->GetHost()->StopFinding(true); findNext = false; } lastMatchCase = matchCase; wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), szFindWhat); } g_handler->GetBrowser()->GetHost()->Find(0, lpfr->lpstrFindWhat, (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext); if (!findNext) findNext = true; } return 0; } else { // Callback for the main window switch (message) { case WM_CREATE: { // Create the single static handler class instance g_handler = new ClientHandler(); g_handler->SetMainHwnd(hWnd); // Create the child windows used for navigation RECT rect; int x = 0; GetClientRect(hWnd, &rect); backWnd = CreateWindow(L"BUTTON", L"Back", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_BACK, hInst, 0); x += BUTTON_WIDTH; forwardWnd = CreateWindow(L"BUTTON", L"Forward", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD, hInst, 0); x += BUTTON_WIDTH; reloadWnd = CreateWindow(L"BUTTON", L"Reload", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD, hInst, 0); x += BUTTON_WIDTH; stopWnd = CreateWindow(L"BUTTON", L"Stop", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_STOP, hInst, 0); x += BUTTON_WIDTH; editWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED, x, 0, rect.right - BUTTON_WIDTH * 4, URLBAR_HEIGHT, hWnd, 0, hInst, 0); // Assign the edit window's WNDPROC to this function so that we can // capture the enter key editWndOldProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC)); SetWindowLongPtr(editWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc)); g_handler->SetEditHwnd(editWnd); g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd); rect.top += URLBAR_HEIGHT; CefWindowInfo info; CefBrowserSettings settings; if (1||AppIsOffScreenRenderingEnabled()) { CefRefPtr<CefCommandLine> cmd_line = AppGetCommandLine(); bool transparent = cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled); transparent=true; CefRefPtr<OSRWindow> osr_window = OSRWindow::Create(&g_main_browser_provider, transparent); osr_window->CreateWidget(hWnd, rect, hInst, szOSRWindowClass); info.SetAsOffScreen(osr_window->hwnd()); // info.SetTransparentPainting(transparent ? TRUE : FALSE); info.SetTransparentPainting(TRUE); g_handler->SetOSRHandler(osr_window.get()); } else { // Initialize window info to the defaults for a child window. info.SetAsChild(hWnd, rect); } // Creat the new child browser window CefBrowserHost::CreateBrowser(info, g_handler.get(), "http://htzs.jiyoutang.com/source/upgrade/client/description.html", settings, NULL); return 0; } case WM_COMMAND: { CefRefPtr<CefBrowser> browser; if (g_handler.get()) browser = g_handler->GetBrowser(); wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); return 0; case IDM_EXIT: if (g_handler.get()) g_handler->CloseAllBrowsers(false); return 0; case ID_WARN_CONSOLEMESSAGE: if (g_handler.get()) { std::wstringstream ss; ss << L"Console messages will be written to " << std::wstring(CefString(g_handler->GetLogFile())); MessageBox(hWnd, ss.str().c_str(), L"Console Messages", MB_OK | MB_ICONINFORMATION); } return 0; case ID_WARN_DOWNLOADCOMPLETE: case ID_WARN_DOWNLOADERROR: if (g_handler.get()) { std::wstringstream ss; ss << L"File \"" << std::wstring(CefString(g_handler->GetLastDownloadFile())) << L"\" "; if (wmId == ID_WARN_DOWNLOADCOMPLETE) ss << L"downloaded successfully."; else ss << L"failed to download."; MessageBox(hWnd, ss.str().c_str(), L"File Download", MB_OK | MB_ICONINFORMATION); } return 0; case ID_FIND: if (!hFindDlg) { // Create the find dialog. ZeroMemory(&fr, sizeof(fr)); fr.lStructSize = sizeof(fr); fr.hwndOwner = hWnd; fr.lpstrFindWhat = szFindWhat; fr.wFindWhatLen = sizeof(szFindWhat); fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN; hFindDlg = FindText(&fr); } else { // Give focus to the existing find dialog. ::SetFocus(hFindDlg); } return 0; case IDC_NAV_BACK: // Back button if (browser.get()) browser->GoBack(); return 0; case IDC_NAV_FORWARD: // Forward button if (browser.get()) browser->GoForward(); return 0; case IDC_NAV_RELOAD: // Reload button if (browser.get()) browser->Reload(); return 0; case IDC_NAV_STOP: // Stop button if (browser.get()) browser->StopLoad(); return 0; case ID_TESTS_GETSOURCE: // Test the GetSource function if (browser.get()) RunGetSourceTest(browser); return 0; case ID_TESTS_GETTEXT: // Test the GetText function if (browser.get()) RunGetTextTest(browser); return 0; case ID_TESTS_POPUP: // Test a popup window if (browser.get()) RunPopupTest(browser); return 0; case ID_TESTS_REQUEST: // Test a request if (browser.get()) RunRequestTest(browser); return 0; case ID_TESTS_PLUGIN_INFO: // Test plugin info if (browser.get()) RunPluginInfoTest(browser); return 0; case ID_TESTS_ZOOM_IN: if (browser.get()) ModifyZoom(browser, 0.5); return 0; case ID_TESTS_ZOOM_OUT: if (browser.get()) ModifyZoom(browser, -0.5); return 0; case ID_TESTS_ZOOM_RESET: if (browser.get()) browser->GetHost()->SetZoomLevel(0.0); return 0; case ID_TESTS_TRACING_BEGIN: g_handler->BeginTracing(); return 0; case ID_TESTS_TRACING_END: g_handler->EndTracing(); return 0; case ID_TESTS_PRINT: if(browser.get()) browser->GetHost()->Print(); return 0; case ID_TESTS_OTHER_TESTS: if (browser.get()) RunOtherTests(browser); return 0; } break; } case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_SETFOCUS: if (g_handler.get() && g_handler->GetBrowser()) { // Pass focus to the browser window CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) PostMessage(hwnd, WM_SETFOCUS, wParam, NULL); } return 0; case WM_SIZE: // Minimizing resizes the window to 0x0 which causes our layout to go all // screwy, so we just ignore it. if (wParam != SIZE_MINIMIZED && g_handler.get() && g_handler->GetBrowser()) { CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Resize the browser window and address bar to match the new frame // window size RECT rect; GetClientRect(hWnd, &rect); rect.top += URLBAR_HEIGHT; int urloffset = rect.left + BUTTON_WIDTH * 4; HDWP hdwp = BeginDeferWindowPos(1); hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); hdwp = DeferWindowPos(hdwp, hwnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER); EndDeferWindowPos(hdwp); } } break; case WM_ERASEBKGND: if (g_handler.get() && g_handler->GetBrowser()) { CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 1; } } break; case WM_ENTERMENULOOP: if (!wParam) { // Entering the menu loop for the application menu. CefSetOSModalLoop(true); } break; case WM_EXITMENULOOP: if (!wParam) { // Exiting the menu loop for the application menu. CefSetOSModalLoop(false); } break; case WM_CLOSE: if (g_handler.get() && !g_handler->IsClosing()) { CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); if (browser.get()) { // Notify the browser window that we would like to close it. This // will result in a call to ClientHandler::DoClose() if the // JavaScript 'onbeforeunload' event handler allows it. browser->GetHost()->CloseBrowser(false); // Cancel the close. return 0; } } // Allow the close. break; case WM_DESTROY: // Quitting CEF is handled in ClientHandler::OnBeforeClose(). return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, stopWnd = NULL, editWnd = NULL; static WNDPROC editWndOldProc = NULL; // Static members used for the find dialog. static FINDREPLACE fr; static WCHAR szFindWhat[80] = {0}; static WCHAR szLastFindWhat[80] = {0}; static bool findNext = false; static bool lastMatchCase = false; int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; if(hWnd == editWnd) { // Callback for the edit window switch (message) { case WM_CHAR: if (wParam == VK_RETURN && g_handler.get()) { // When the user hits the enter key load the URL CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); wchar_t strPtr[MAX_URL_LENGTH] = {0}; *((LPWORD)strPtr) = MAX_URL_LENGTH; LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr); if (strLen > 0) { strPtr[strLen] = 0; browser->GetMainFrame()->LoadURL(strPtr); } return 0; } } return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam); } else if (message == uFindMsg) { // Find event. LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam; if (lpfr->Flags & FR_DIALOGTERM) { // The find dialog box has been dismissed so invalidate the handle and // reset the search results. hFindDlg = NULL; if(g_handler.get()) { g_handler->GetBrowser()->StopFinding(true); szLastFindWhat[0] = 0; findNext = false; } return 0; } if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get()) { // Search for the requested string. bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false); if(matchCase != lastMatchCase || (matchCase && wcsncmp(szFindWhat, szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) || (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) { // The search string has changed, so reset the search results. if(szLastFindWhat[0] != 0) { g_handler->GetBrowser()->StopFinding(true); findNext = false; } lastMatchCase = matchCase; wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), szFindWhat); } g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat, (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext); if(!findNext) findNext = true; } return 0; } else { // Callback for the main window switch (message) { case WM_CREATE: { // Create the single static handler class instance g_handler = new ClientHandler(); g_handler->SetMainHwnd(hWnd); // Create the child windows used for navigation RECT rect; int x = 0; GetClientRect(hWnd, &rect); backWnd = CreateWindow(L"BUTTON", L"Back", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_BACK, hInst, 0); x += BUTTON_WIDTH; forwardWnd = CreateWindow(L"BUTTON", L"Forward", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD, hInst, 0); x += BUTTON_WIDTH; reloadWnd = CreateWindow(L"BUTTON", L"Reload", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD, hInst, 0); x += BUTTON_WIDTH; stopWnd = CreateWindow(L"BUTTON", L"Stop", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_STOP, hInst, 0); x += BUTTON_WIDTH; editWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED, x, 0, rect.right - BUTTON_WIDTH * 4, URLBAR_HEIGHT, hWnd, 0, hInst, 0); // Assign the edit window's WNDPROC to this function so that we can // capture the enter key editWndOldProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC)); SetWindowLongPtr(editWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc)); g_handler->SetEditHwnd(editWnd); g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd); rect.top += URLBAR_HEIGHT; CefWindowInfo info; CefBrowserSettings settings; // Populate the settings based on command line arguments. AppGetBrowserSettings(settings); // Initialize window info to the defaults for a child window info.SetAsChild(hWnd, rect); // Creat the new child browser window CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(g_handler), "http://www.google.com", settings); } return 0; case WM_COMMAND: { CefRefPtr<CefBrowser> browser; if(g_handler.get()) browser = g_handler->GetBrowser(); wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); return 0; case IDM_EXIT: DestroyWindow(hWnd); return 0; case ID_WARN_CONSOLEMESSAGE: if(g_handler.get()) { std::wstringstream ss; ss << L"Console messages will be written to " << std::wstring(CefString(g_handler->GetLogFile())); MessageBox(hWnd, ss.str().c_str(), L"Console Messages", MB_OK | MB_ICONINFORMATION); } return 0; case ID_WARN_DOWNLOADCOMPLETE: case ID_WARN_DOWNLOADERROR: if(g_handler.get()) { std::wstringstream ss; ss << L"File \"" << std::wstring(CefString(g_handler->GetLastDownloadFile())) << L"\" "; if(wmId == ID_WARN_DOWNLOADCOMPLETE) ss << L"downloaded successfully."; else ss << L"failed to download."; MessageBox(hWnd, ss.str().c_str(), L"File Download", MB_OK | MB_ICONINFORMATION); } return 0; case ID_FIND: if(!hFindDlg) { // Create the find dialog. ZeroMemory(&fr, sizeof(fr)); fr.lStructSize = sizeof(fr); fr.hwndOwner = hWnd; fr.lpstrFindWhat = szFindWhat; fr.wFindWhatLen = sizeof(szFindWhat); fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN; hFindDlg = FindText(&fr); } else { // Give focus to the existing find dialog. ::SetFocus(hFindDlg); } return 0; case ID_PRINT: if(browser.get()) browser->GetMainFrame()->Print(); return 0; case IDC_NAV_BACK: // Back button if(browser.get()) browser->GoBack(); return 0; case IDC_NAV_FORWARD: // Forward button if(browser.get()) browser->GoForward(); return 0; case IDC_NAV_RELOAD: // Reload button if(browser.get()) browser->Reload(); return 0; case IDC_NAV_STOP: // Stop button if(browser.get()) browser->StopLoad(); return 0; case ID_TESTS_GETSOURCE: // Test the GetSource function if(browser.get()) RunGetSourceTest(browser); return 0; case ID_TESTS_GETTEXT: // Test the GetText function if(browser.get()) RunGetTextTest(browser); return 0; case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler if(browser.get()) RunBindingTest(browser); return 0; case ID_TESTS_JAVASCRIPT_EXTENSION: // Test the V8 extension handler if(browser.get()) RunExtensionTest(browser); return 0; case ID_TESTS_JAVASCRIPT_PERFORMANCE: // Test the V8 performance if(browser.get()) RunExtensionPerfTest(browser); return 0; case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript if(browser.get()) RunJavaScriptExecuteTest(browser); return 0; case ID_TESTS_JAVASCRIPT_INVOKE: if(browser.get()) RunJavaScriptInvokeTest(browser); return 0; case ID_TESTS_PLUGIN: // Test the custom plugin if(browser.get()) RunPluginTest(browser); return 0; case ID_TESTS_POPUP: // Test a popup window if(browser.get()) RunPopupTest(browser); return 0; case ID_TESTS_TRANSPARENT_POPUP: // Test a transparent popup window if(browser.get()) RunTransparentPopupTest(browser); return 0; case ID_TESTS_REQUEST: // Test a request if(browser.get()) RunRequestTest(browser); return 0; case ID_TESTS_SCHEME_HANDLER: // Test the scheme handler if(browser.get()) RunSchemeTest(browser); return 0; case ID_TESTS_UIAPP: // Test the UI app if(browser.get()) RunUIPluginTest(browser); return 0; case ID_TESTS_OSRAPP: // Test the OSR app if(browser.get()) RunOSRPluginTest(browser, false); return 0; case ID_TESTS_TRANSPARENT_OSRAPP: // Test the OSR app with transparency if(browser.get()) RunOSRPluginTest(browser, true); return 0; case ID_TESTS_DOMACCESS: // Test DOM access if(browser.get()) RunDOMAccessTest(browser); return 0; case ID_TESTS_LOCALSTORAGE: // Test localStorage if(browser.get()) RunLocalStorageTest(browser); return 0; case ID_TESTS_ACCELERATED2DCANVAS: // Test accelerated 2d canvas if(browser.get()) RunAccelerated2DCanvasTest(browser); return 0; case ID_TESTS_ACCELERATEDLAYERS: // Test accelerated layers if(browser.get()) RunAcceleratedLayersTest(browser); return 0; case ID_TESTS_WEBGL: // Test WebGL if(browser.get()) RunWebGLTest(browser); return 0; case ID_TESTS_HTML5VIDEO: // Test HTML5 video if(browser.get()) RunHTML5VideoTest(browser); return 0; case ID_TESTS_DRAGDROP: // Test drag & drop if(browser.get()) RunDragDropTest(browser); return 0; case ID_TESTS_XMLHTTPREQUEST: // Test XMLHttpRequest if(browser.get()) RunXMLHTTPRequestTest(browser); return 0; case ID_TESTS_WEBURLREQUEST: if (browser.get()) RunWebURLRequestTest(browser); return 0; case ID_TESTS_ZOOM_IN: if(browser.get()) browser->SetZoomLevel(browser->GetZoomLevel() + 0.5); return 0; case ID_TESTS_ZOOM_OUT: if(browser.get()) browser->SetZoomLevel(browser->GetZoomLevel() - 0.5); return 0; case ID_TESTS_ZOOM_RESET: if(browser.get()) browser->SetZoomLevel(0.0); return 0; case ID_TESTS_DEVTOOLS_SHOW: if (browser.get()) browser->ShowDevTools(); return 0; case ID_TESTS_DEVTOOLS_CLOSE: if (browser.get()) browser->CloseDevTools(); return 0; case ID_TESTS_MODALDIALOG: if(browser.get()) RunModalDialogTest(browser); return 0; case ID_TESTS_GETIMAGE: if(browser.get()) RunGetImageTest(browser); return 0; } } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_SETFOCUS: if(g_handler.get() && g_handler->GetBrowserHwnd()) { // Pass focus to the browser window PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL); } return 0; case WM_SIZE: if(g_handler.get() && g_handler->GetBrowserHwnd()) { // Resize the browser window and address bar to match the new frame // window size RECT rect; GetClientRect(hWnd, &rect); rect.top += URLBAR_HEIGHT; int urloffset = rect.left + BUTTON_WIDTH * 4; HDWP hdwp = BeginDeferWindowPos(1); hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER); EndDeferWindowPos(hdwp); } break; case WM_ERASEBKGND: if(g_handler.get() && g_handler->GetBrowserHwnd()) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 0; } break; case WM_CLOSE: if (g_handler.get()) { CefRefPtr<CefBrowser> browser = g_handler->GetBrowser(); if (browser.get()) { // Let the browser window know we are about to destroy it. browser->ParentWindowWillClose(); } } break; case WM_DESTROY: // The frame window has exited PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } }