Skip to content

Commit

Permalink
only show notification icon when starting minimized
Browse files Browse the repository at this point in the history
 * also added /min argument for command line usage
  • Loading branch information
smith committed Feb 3, 2018
1 parent 518fa50 commit ae18b94
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
12 changes: 10 additions & 2 deletions audio-router-gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
MessageBox(NULL, L"Could not create window. Audio Router will close.", NULL, MB_ICONERROR);
goto cleanup;
}
win.ShowWindow(nCmdShow);
win.UpdateWindow();

if (SW_SHOWMINNOACTIVE == nCmdShow || strcmp(lpCmdLine, "/min") == 0) {
win.ShowWindow(SW_HIDE);
win.addTrayIcon();
win.UpdateWindow();
}
else {
win.ShowWindow(nCmdShow);
win.UpdateWindow();
}

while(GetMessage(&msg, NULL, 0, 0) > 0)
{
Expand Down
37 changes: 22 additions & 15 deletions audio-router-gui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,7 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
}
}*/

if (!m_NotifyIconData.cbSize)
{
m_NotifyIconData.cbSize = NOTIFYICONDATAA_V1_SIZE;
m_NotifyIconData.hWnd = m_hWnd;
m_NotifyIconData.uID = 1;
m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
m_NotifyIconData.uCallbackMessage = WM_SYSTEMTRAYICON;
m_NotifyIconData.hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
ATL::CString sWindowText;
GetWindowText(sWindowText);
_tcscpy_s(m_NotifyIconData.szTip, sWindowText);
}

Shell_NotifyIcon(NIM_ADD, &m_NotifyIconData);
this->addTrayIcon();
ShowWindow(SW_HIDE);

bHandled = TRUE;
Expand Down Expand Up @@ -119,6 +106,26 @@ LRESULT window::OnSystemTrayExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd
return 0;
}

int window::addTrayIcon()
{
if (!m_NotifyIconData.cbSize)
{
m_NotifyIconData.cbSize = NOTIFYICONDATAA_V1_SIZE;
m_NotifyIconData.hWnd = m_hWnd;
m_NotifyIconData.uID = 1;
m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
m_NotifyIconData.uCallbackMessage = WM_SYSTEMTRAYICON;
m_NotifyIconData.hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
ATL::CString sWindowText;
GetWindowText(sWindowText);
_tcscpy_s(m_NotifyIconData.szTip, sWindowText);
}

Shell_NotifyIcon(NIM_ADD, &m_NotifyIconData);

return 0;
}

LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if(!this->dlg_main_b)
Expand All @@ -132,7 +139,7 @@ LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWn
LRESULT window::OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
this->MessageBoxW(
L"Audio Router version 0.10.4.\n" \
L"Audio Router version 0.10.5.\n" \
L"\nIf you come across any bugs(especially relating to routing or duplicating), " \
L"or just have an idea for a new feature, " \
L"please open an issue on github: github.com/a-sync/audio-router/",
Expand Down
1 change: 1 addition & 0 deletions audio-router-gui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ class window : public CFrameWindowImpl<window>
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
LRESULT OnSystemTrayIcon(UINT, WPARAM wParam, LPARAM lParam);
LRESULT OnRestore(UINT, INT, HWND);
int addTrayIcon();
};

0 comments on commit ae18b94

Please sign in to comment.