LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { BrowserWindow* browser = 0; BOOL b = 0; WORD childEvent = 0; HWND childHandle = 0; HWND shellBrowserHandle = 0; switch (uMsg) { case WM_SIZE: browser = GetBrowserWindow(hwnd); if (browser) { browser->OnSize(); } else { LOG_WARNING << "WindowProc(): event WM_SIZE: " "could not fetch BrowserWindow"; } break; case WM_CREATE: if (GetWindow(hwnd, GW_OWNER)) { browser = new BrowserWindow(hwnd, true); } else { browser = new BrowserWindow(hwnd, false); } StoreBrowserWindow(hwnd, browser); return 0; case WM_DESTROY: LOG_DEBUG << "WM_DESTROY"; RemoveBrowserWindow(hwnd); if (g_browserWindows.empty()) { StopWebServer(); #ifdef DEBUG // Debugging mongoose, see InitializeLogging(). printf("----------------------------------------"); printf("----------------------------------------\n"); #endif // Cannot call PostQuitMessage as cookies won't be flushed to disk // if application is closed immediately. See comment #2: // https://code.google.com/p/phpdesktop/issues/detail?id=146 // I suppose that this PostQuitMessage was added here so that // application is forced to exit cleanly in case Mongoose // web server hanged while stopping it, as I recall such case. // ------------------- // PostQuitMessage(0); // ------------------- } return 0; case WM_GETMINMAXINFO: browser = GetBrowserWindow(hwnd); if (browser) { browser->OnGetMinMaxInfo(uMsg, wParam, lParam); return 0; } else { // GetMinMaxInfo may fail during window creation, so // log severity is only DEBUG. LOG_DEBUG << "WindowProc(): event WM_GETMINMAXINFO: " "could not fetch BrowserWindow"; } break; case WM_SETFOCUS: browser = GetBrowserWindow(hwnd); if (browser) { browser->SetFocus(); return 0; } else { LOG_DEBUG << "WindowProc(): event WM_SETFOCUS: " "could not fetch BrowserWindow"; } break; case WM_ERASEBKGND: browser = GetBrowserWindow(hwnd); if (browser && browser->GetCefBrowser().get()) { CefWindowHandle hwnd = \ browser->GetCefBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 1; } } break; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { BrowserWindow* browser = 0; BOOL b = 0; WORD childEvent = 0; HWND childHandle = 0; HWND shellBrowserHandle = 0; json_value* appSettings = GetApplicationSettings(); std::string main_window_title = (*appSettings)["main_window"]["title"]; // Settings bool minimize_to_tray = (*appSettings)["main_window"]["minimize_to_tray"]; if (CountBrowserWindows() > 1) { minimize_to_tray = false; } switch (uMsg) { case WM_SIZE: browser = GetBrowserWindow(hwnd); if (browser && browser->GetCefBrowser()) { browser->OnSize(); } else if (!browser) { LOG_WARNING << "WindowProc() WM_SIZE: could not fetch BrowserWindow"; } break; case WM_MOVE: case WM_MOVING: case WM_SIZING: browser = GetBrowserWindow(hwnd); if (browser && browser->GetCefBrowser()) { browser->GetCefBrowser()->GetHost()->NotifyMoveOrResizeStarted(); } else if (!browser) { LOG_WARNING << "WindowProc() WM_MOVE: could not fetch BrowserWindow"; } return 0; case WM_CREATE: if (GetWindow(hwnd, GW_OWNER)) { browser = new BrowserWindow(hwnd, true); } else { browser = new BrowserWindow(hwnd, false); } StoreBrowserWindow(hwnd, browser); return 0; case WM_DESTROY: LOG_DEBUG << "WM_DESTROY"; RemoveBrowserWindow(hwnd); if (g_browserWindows.empty()) { StopWebServer(); Shell_NotifyIcon(NIM_DELETE, &GetTrayData(hwnd)); // Cannot call PostQuitMessage as cookies won't be flushed to disk // if application is closed immediately. See comment #2: // https://code.google.com/p/phpdesktop/issues/detail?id=146 // I suppose that this PostQuitMessage was added here so that // application is forced to exit cleanly in case Mongoose // web server hanged while stopping it, as I recall such case. // ------------------- // PostQuitMessage(0); // ------------------- #ifdef DEBUG // Debugging mongoose, see InitializeLogging(). printf("----------------------------------------"); printf("----------------------------------------\n"); #endif } return 0; case WM_GETMINMAXINFO: browser = GetBrowserWindow(hwnd); if (browser) { browser->OnGetMinMaxInfo(uMsg, wParam, lParam); return 0; } else { // GetMinMaxInfo may fail during window creation, so // log severity is only DEBUG. LOG_DEBUG << "WindowProc(): event WM_GETMINMAXINFO: " "could not fetch BrowserWindow"; } break; case WM_SETFOCUS: browser = GetBrowserWindow(hwnd); if (browser) { browser->SetFocus(); return 0; } else { LOG_DEBUG << "WindowProc(): event WM_SETFOCUS: " "could not fetch BrowserWindow"; } break; case WM_ERASEBKGND: // Erase the background when the browser does not exist. browser = GetBrowserWindow(hwnd); if (browser && browser->GetCefBrowser()) { // Dont erase the background if the browser window has been loaded // (this avoids flashing) return 0; } break; case WM_PAINT: PAINTSTRUCT ps; BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return 0; case WM_SYSCOMMAND: if (wParam == SC_MINIMIZE && minimize_to_tray) { LOG_DEBUG << "Minimize to tray"; ShowWindow(hwnd, SW_MINIMIZE); Sleep(200); ShowWindow(hwnd, SW_HIDE); Shell_NotifyIcon(NIM_ADD, &GetTrayData(hwnd)); break; } break; case WM_TRAY_MESSAGE: if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN) { LOG_DEBUG << "Restore from tray"; ShowWindow(hwnd, SW_SHOW); ShowWindow(hwnd, SW_RESTORE); SetForegroundWindow(hwnd); Shell_NotifyIcon(NIM_DELETE, &GetTrayData(hwnd)); break; } break; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }