diff --git a/.gitattributes b/.gitattributes index 7273f65..9a623f7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,3 @@ -* text=auto - *.txt text eol=crlf *.cpp text eol=crlf *.h text eol=crlf diff --git a/phpdesktop-chrome/defines.h b/phpdesktop-chrome/defines.h index 929ebf1..ca86649 100644 --- a/phpdesktop-chrome/defines.h +++ b/phpdesktop-chrome/defines.h @@ -8,3 +8,6 @@ #define _WIN32_WINNT 0x0501 #define _WIN32_IE _WIN32_IE_IE60SP2 #define _RICHEDIT_VER 0x0200 + +// Win messages +#define WM_TRAY_MESSAGE (WM_USER + 1) diff --git a/phpdesktop-chrome/main.cpp b/phpdesktop-chrome/main.cpp index 77c3e6f..e00f963 100644 --- a/phpdesktop-chrome/main.cpp +++ b/phpdesktop-chrome/main.cpp @@ -43,6 +43,25 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, HWND childHandle = 0; HWND shellBrowserHandle = 0; + json_value* appSettings = GetApplicationSettings(); + std::string main_window_title = (*appSettings)["main_window"]["title"]; + + // Minimize to system tray + bool minimize_to_tray = (*appSettings)["main_window"]["minimize_to_tray"]; + std::string minimize_to_tray_message = (*appSettings)["main_window"]["minimize_to_tray_message"]; + NOTIFYICONDATA tray = {0}; + tray.cbSize = sizeof(tray); + tray.hWnd = hwnd; + tray.uID = 1; + tray.uCallbackMessage = WM_TRAY_MESSAGE; + tray.hIcon = (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDR_MAINWINDOW), IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), + LR_DEFAULTCOLOR); + wcscpy_s(tray.szInfo, 256, Utf8ToWide(minimize_to_tray_message).c_str()); + wcscpy_s(tray.szInfoTitle, 64, Utf8ToWide(main_window_title).c_str()); + tray.uFlags = NIF_ICON | NIF_INFO | NIF_MESSAGE; + tray.dwInfoFlags = NIIF_NONE; + switch (uMsg) { case WM_SIZE: browser = GetBrowserWindow(hwnd); @@ -70,7 +89,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, // Debugging mongoose, see InitializeLogging(). printf("----------------------------------------"); printf("----------------------------------------\n"); -#endif +#endif + Shell_NotifyIcon(NIM_DELETE, &tray); PostQuitMessage(0); } break; @@ -108,6 +128,26 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, } } break; + case WM_SYSCOMMAND: + if (wParam == SC_MINIMIZE && minimize_to_tray && !GetBrowserWindow(hwnd)->IsPopup()) { + LOG_DEBUG << "Minimize to tray"; + ShowWindow(hwnd, SW_MINIMIZE); + Sleep(200); + ShowWindow(hwnd, SW_HIDE); + Shell_NotifyIcon(NIM_ADD, &tray); + 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, &tray); + break; + } + break; } return DefWindowProc(hwnd, uMsg, wParam, lParam); } diff --git a/phpdesktop-chrome/resource.rc b/phpdesktop-chrome/resource.rc index 835751c..6c6f4c6 100644 --- a/phpdesktop-chrome/resource.rc +++ b/phpdesktop-chrome/resource.rc @@ -47,8 +47,8 @@ IDR_MAINWINDOW ICON "icon.ico" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 31,9,0,0 - PRODUCTVERSION 31,9,0,0 + FILEVERSION 31,10,0,0 + PRODUCTVERSION 31,10,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -65,12 +65,12 @@ BEGIN BEGIN VALUE "CompanyName", "PHP Desktop" VALUE "FileDescription", "PHP Desktop Chrome" - VALUE "FileVersion", "31.9.0.0" + VALUE "FileVersion", "31.10.0.0" VALUE "InternalName", "phpdesktop" VALUE "LegalCopyright", "(c) Czarek Tomczak 2012" VALUE "OriginalFilename", "phpdesktop-chrome.exe" VALUE "ProductName", "PHP Desktop Chrome" - VALUE "ProductVersion", "31.9.0.0" + VALUE "ProductVersion", "31.10.0.0" END END BLOCK "VarFileInfo" diff --git a/phpdesktop-chrome/settings.json b/phpdesktop-chrome/settings.json index cbabe7a..ffe55c4 100644 --- a/phpdesktop-chrome/settings.json +++ b/phpdesktop-chrome/settings.json @@ -19,7 +19,9 @@ "center_on_screen": true, "start_maximized": false, "start_fullscreen": false, - "always_on_top": false + "always_on_top": false, + "minimize_to_tray": false, + "minimize_to_tray_message": "Minimized to tray" }, "popup_window": { "icon": "",