Skip to content

Commit

Permalink
Minimize to tray
Browse files Browse the repository at this point in the history
  • Loading branch information
charlessuh authored and a-sync committed Jun 6, 2017
1 parent 97eb927 commit ebc8347
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 12 deletions.
Binary file modified audio-router-gui/audio-router-gui.rc
Binary file not shown.
Binary file modified audio-router-gui/resource.h
Binary file not shown.
101 changes: 89 additions & 12 deletions audio-router-gui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,55 @@ int window::OnCreate(LPCREATESTRUCT lpcs)

return 0;
}
LRESULT window::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{

if (m_NotifyIconData.cbSize)
{
Shell_NotifyIcon(NIM_DELETE, &m_NotifyIconData);
}

return 0;
}

LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if(wParam == SC_MINIMIZE)
if (wParam == SC_MINIMIZE || IsWindowVisible() && wParam == SC_CLOSE)
{
for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin();
it != this->dlg_main->dialog_arrays.end();
it++)
/* for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin();
it != this->dlg_main->dialog_arrays.end();
it++)
{
for(dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin();
jt != (*it)->dialog_controls.end();
jt++)
{
(*jt)->set_display_name(false, true);
}
}*/

if (!m_NotifyIconData.cbSize)
{
for(dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin();
jt != (*it)->dialog_controls.end();
jt++)
{
(*jt)->set_display_name(false, true);
}
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);
ShowWindow(SW_HIDE);

bHandled = TRUE;
return 0;
}
else if(wParam == SC_RESTORE)
{
for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin();
/*for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin();
it != this->dlg_main->dialog_arrays.end();
it++)
{
Expand All @@ -58,13 +87,47 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
{
(*jt)->set_display_name(false, false);
}
}
}*/

}

bHandled = FALSE;
return 0;
}

LRESULT window::OnSystemTrayIcon(UINT, WPARAM wParam, LPARAM lParam) {

ATLASSERT(wParam == 1);
switch (lParam)
{
case WM_LBUTTONDBLCLK:
SendMessage(WM_COMMAND, SC_RESTORE);
break;

case WM_RBUTTONUP:
{
SetForegroundWindow(m_hWnd);

CPoint pos;
ATLVERIFY(GetCursorPos(&pos));

CMenu menu;
menu.LoadMenuW(IDR_SYSTRAY_MENU);
CMenuHandle popupMenu = menu.GetSubMenu(0);

popupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_BOTTOMALIGN, pos.x, pos.y, this->m_hWnd);
}
break;
}
return 0;
}

LRESULT window::OnSystemTrayExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
SendMessage(WM_SYSCOMMAND, SC_CLOSE);
return 0;
}

LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if(!this->dlg_main_b)
Expand Down Expand Up @@ -119,4 +182,18 @@ LRESULT window::OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd
LRESULT window::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return HTCLOSE;
}


LRESULT window::OnRestore(UINT, INT, HWND)
{
if (m_NotifyIconData.cbSize)
{
Shell_NotifyIcon(NIM_DELETE, &m_NotifyIconData);
}

ShowWindow(SW_SHOW);
BringWindowToTop();

return 0;
}
17 changes: 17 additions & 0 deletions audio-router-gui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "bootstrapper.h"
#include "licensing.h"
#include <memory>
#include <shellapi.h>

#define WIN_WIDTH 970//400
#define WIN_HEIGHT 670//360
Expand All @@ -14,6 +15,7 @@ class window : public CFrameWindowImpl<window>
{
private:
bool dlg_main_b;
NOTIFYICONDATA m_NotifyIconData;
public:
dialog_main* dlg_main;
formview* form_view;
Expand All @@ -29,17 +31,32 @@ class window : public CFrameWindowImpl<window>
MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
MSG_WM_CREATE(OnCreate)
/*MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)*/
MESSAGE_HANDLER_EX(WM_SYSTEMTRAYICON, OnSystemTrayIcon)
CHAIN_MSG_MAP(CFrameWindowImpl<window>)
COMMAND_ID_HANDLER(ID_FILE_REFRESHLIST, OnFileRefreshlist)
COMMAND_ID_HANDLER(ID_ABOUT, OnAbout)
COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview)
COMMAND_ID_HANDLER(ID_SYSTRAY_EXIT, OnSystemTrayExit)
COMMAND_ID_HANDLER_EX(SC_RESTORE, OnRestore)

/*MSG_WM_NCHITTEST(OnNcHitTest)*/
END_MSG_MAP()

enum
{
WM_FIRST = WM_APP,
WM_SYSTEMTRAYICON,
};

int OnCreate(LPCREATESTRUCT);
LRESULT OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnSystemTrayExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
LRESULT OnSystemTrayIcon(UINT, WPARAM wParam, LPARAM lParam);
LRESULT OnRestore(UINT, INT, HWND);
};

5 comments on commit ebc8347

@RobertPaulson90
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Too bad the original developer doesn't seem to be actively working on this.

@SierraJC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you upload a binary?

@a-sync
Copy link
Owner

@a-sync a-sync commented on ebc8347 Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SierraJC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, but the lack of a 32-bit dll results in an error message displaying any time a 32-bit application is opened, such as Spotify.

Error code 0x00000002: The system cannot find the file specified.
Routing functionality couldn't be initialized in the starting process.

@a-sync
Copy link
Owner

@a-sync a-sync commented on ebc8347 Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your right. Sorry about that.
I replaced the zip, please try again after re-downloading it.

Please sign in to comment.