@@ -42,6 +42,29 @@ HCURSOR g_appStartingCursor = 0;
4242extern std::map<HWND, BrowserWindow*> g_browserWindows; // browser_window.cpp
4343std::string g_cgiEnvironmentFromArgv = " " ;
4444
45+ NOTIFYICONDATA GetTrayData (HWND hwnd)
46+ {
47+ static NOTIFYICONDATA tray = {0 };
48+ tray.hWnd = hwnd;
49+ if (tray.cbSize ) {
50+ return tray;
51+ }
52+ json_value* appSettings = GetApplicationSettings ();
53+ std::string main_window_title = (*appSettings)[" main_window" ][" title" ];
54+ std::string minimize_to_tray_message = (*appSettings)[" main_window" ][" minimize_to_tray_message" ];
55+ tray.cbSize = sizeof (tray);
56+ tray.uID = 1 ;
57+ tray.uCallbackMessage = WM_TRAY_MESSAGE;
58+ tray.hIcon = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE (IDR_MAINWINDOW), IMAGE_ICON,
59+ GetSystemMetrics (SM_CXSMICON), GetSystemMetrics (SM_CYSMICON),
60+ LR_DEFAULTCOLOR);
61+ wcscpy_s (tray.szInfo , 256 , Utf8ToWide (minimize_to_tray_message).c_str ());
62+ wcscpy_s (tray.szInfoTitle , 64 , Utf8ToWide (main_window_title).c_str ());
63+ tray.uFlags = NIF_ICON | NIF_INFO | NIF_MESSAGE;
64+ tray.dwInfoFlags = NIIF_NONE;
65+ return tray;
66+ }
67+
4568LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam,
4669 LPARAM lParam) {
4770 BrowserWindow* browser = 0 ;
@@ -55,19 +78,9 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
5578
5679 // Minimize to system tray
5780 bool minimize_to_tray = (*appSettings)[" main_window" ][" minimize_to_tray" ];
58- std::string minimize_to_tray_message = (*appSettings)[" main_window" ][" minimize_to_tray_message" ];
59- NOTIFYICONDATA tray = {0 };
60- tray.cbSize = sizeof (tray);
61- tray.hWnd = hwnd;
62- tray.uID = 1 ;
63- tray.uCallbackMessage = WM_TRAY_MESSAGE;
64- tray.hIcon = (HICON) LoadImage (g_hInstance, MAKEINTRESOURCE (IDR_MAINWINDOW), IMAGE_ICON,
65- GetSystemMetrics (SM_CXSMICON), GetSystemMetrics (SM_CYSMICON),
66- LR_DEFAULTCOLOR);
67- wcscpy_s (tray.szInfo , 256 , Utf8ToWide (minimize_to_tray_message).c_str ());
68- wcscpy_s (tray.szInfoTitle , 64 , Utf8ToWide (main_window_title).c_str ());
69- tray.uFlags = NIF_ICON | NIF_INFO | NIF_MESSAGE;
70- tray.dwInfoFlags = NIIF_NONE;
81+ if (CountBrowserWindows () > 1 ) {
82+ minimize_to_tray = false ;
83+ }
7184
7285 switch (uMsg) {
7386 case WM_SIZE:
@@ -79,6 +92,17 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
7992 " could not fetch BrowserWindow" ;
8093 }
8194 break ;
95+ case WM_MOVE:
96+ case WM_MOVING:
97+ case WM_SIZING:
98+ browser = GetBrowserWindow (hwnd);
99+ if (browser) {
100+ browser->GetCefBrowser ()->GetHost ()->NotifyMoveOrResizeStarted ();
101+ } else {
102+ LOG_WARNING << " WindowProc(): event WM_MOVING/WM_MOVE/WM_SIZING: "
103+ " could not fetch BrowserWindow" ;
104+ }
105+ return 0 ;
82106 case WM_CREATE:
83107 if (GetWindow (hwnd, GW_OWNER)) {
84108 browser = new BrowserWindow (hwnd, true );
@@ -92,13 +116,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
92116 RemoveBrowserWindow (hwnd);
93117 if (g_browserWindows.empty ()) {
94118 StopWebServer ();
95- #ifdef DEBUG
96- // Debugging mongoose, see InitializeLogging().
97- printf (" ----------------------------------------" );
98- printf (" ----------------------------------------\n " );
119+ Shell_NotifyIcon (NIM_DELETE, &GetTrayData (hwnd));
99120
100- Shell_NotifyIcon (NIM_DELETE, &tray);
101- #endif
102121 // Cannot call PostQuitMessage as cookies won't be flushed to disk
103122 // if application is closed immediately. See comment #2:
104123 // https://code.google.com/p/phpdesktop/issues/detail?id=146
@@ -108,6 +127,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
108127 // -------------------
109128 // PostQuitMessage(0);
110129 // -------------------
130+
131+ #ifdef DEBUG
132+ // Debugging mongoose, see InitializeLogging().
133+ printf (" ----------------------------------------" );
134+ printf (" ----------------------------------------\n " );
135+ #endif
111136 }
112137 return 0 ;
113138 case WM_GETMINMAXINFO:
@@ -133,24 +158,30 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
133158 }
134159 break ;
135160 case WM_ERASEBKGND:
161+ // Erase the background when the browser does not exist.
136162 browser = GetBrowserWindow (hwnd);
137163 if (browser && browser->GetCefBrowser ().get ()) {
138164 CefWindowHandle hwnd = \
139165 browser->GetCefBrowser ()->GetHost ()->GetWindowHandle ();
140166 if (hwnd) {
141167 // Dont erase the background if the browser window has been loaded
142168 // (this avoids flashing)
143- return 1 ;
169+ return 0 ;
144170 }
145171 }
146172 break ;
173+ case WM_PAINT:
174+ PAINTSTRUCT ps;
175+ BeginPaint (hwnd, &ps);
176+ EndPaint (hwnd, &ps);
177+ return 0 ;
147178 case WM_SYSCOMMAND:
148- if (wParam == SC_MINIMIZE && minimize_to_tray && ! GetBrowserWindow (hwnd)-> IsPopup () ) {
179+ if (wParam == SC_MINIMIZE && minimize_to_tray) {
149180 LOG_DEBUG << " Minimize to tray" ;
150181 ShowWindow (hwnd, SW_MINIMIZE);
151182 Sleep (200 );
152183 ShowWindow (hwnd, SW_HIDE);
153- Shell_NotifyIcon (NIM_ADD, &tray );
184+ Shell_NotifyIcon (NIM_ADD, &GetTrayData (hwnd) );
154185 break ;
155186 }
156187 break ;
@@ -160,7 +191,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
160191 ShowWindow (hwnd, SW_SHOW);
161192 ShowWindow (hwnd, SW_RESTORE);
162193 SetForegroundWindow (hwnd);
163- Shell_NotifyIcon (NIM_DELETE, &tray );
194+ Shell_NotifyIcon (NIM_DELETE, &GetTrayData (hwnd) );
164195 break ;
165196 }
166197 break ;
0 commit comments