Skip to content

Commit

Permalink
Minimize to system tray - Issue #25
Browse files Browse the repository at this point in the history
Added "minimize_to_tray" and "minimize_to_tray_message" options.
  • Loading branch information
cztomczak committed Jan 25, 2016
1 parent c1ba05c commit e9e1b07
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
@@ -1,5 +1,3 @@
* text=auto

*.txt text eol=crlf
*.cpp text eol=crlf
*.h text eol=crlf
Expand Down
3 changes: 3 additions & 0 deletions phpdesktop-chrome/defines.h
Expand Up @@ -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)
42 changes: 41 additions & 1 deletion phpdesktop-chrome/main.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions phpdesktop-chrome/resource.rc
Expand Up @@ -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
Expand All @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion phpdesktop-chrome/settings.json
Expand Up @@ -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": "",
Expand Down

0 comments on commit e9e1b07

Please sign in to comment.