From cc97f1c8179d2243f421cf2a76de258ce5b056de Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Sat, 1 Jul 2017 03:12:19 -0400 Subject: [PATCH] Implement Tray Icon right click menu --- audio-router-gui/audio-router-gui.rc | Bin 12264 -> 12432 bytes audio-router-gui/resource.h | Bin 3524 -> 3610 bytes audio-router-gui/window.cpp | 66 ++++++++++++++++++++++----- audio-router-gui/window.h | 8 +++- 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/audio-router-gui/audio-router-gui.rc b/audio-router-gui/audio-router-gui.rc index a1a4718efbd5502e0e09283bdd01a32bf9a114c4..81c35b9f289c84b2c31b3d0f50c3bffc76f54a74 100644 GIT binary patch delta 148 zcmaD6KOu30j52!&LlA=_L*(S$3aXR6lm+;qdiJxgYT3AcI(LlA=_LnMPQgDZm{LnuQ$LokB}gFiz!ko0750g7^h;N<%}@{=9d g_%spfTp1#ODncOg3<^+a!e9V|h787=qq#Gg0Jwq>hyVZp delta 44 rcmbOwb3}TB3HRiE>^#!03=s^T3?U4haA?9{0EC7NMw>TsXEFf**1QNj diff --git a/audio-router-gui/window.cpp b/audio-router-gui/window.cpp index c491d3b..e3320a7 100644 --- a/audio-router-gui/window.cpp +++ b/audio-router-gui/window.cpp @@ -1,6 +1,7 @@ #include "window.h" telemetry* telemetry_m = NULL; +HMENU trayIconMenu; window::window(/*bootstrapper* bootstrap*/) : dlg_main_b(true)/*, license(NULL)*//*, bootstrap(bootstrap)*/ { @@ -81,28 +82,41 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { + if (trayIconMenu != NULL) { + DestroyMenu(trayIconMenu); + trayIconMenu = NULL; + } + switch (LOWORD(lParam)) { - case WM_LBUTTONDBLCLK: + case WM_LBUTTONUP: if (bIsVisible) { this->ShowWindow(SW_HIDE); bIsVisible = false; - } else { + } + else { this->ShowWindow(SW_SHOW); this->BringWindowToTop(); bIsVisible = true; } break; case WM_RBUTTONUP: - - /*POINT lpClickPoint; - - UINT uFlag = MF_BYPOSITION | MF_STRING; - GetCursorPos(&lpClickPoint); - - HMENU hPopMenu = CreatePopupMenu(); - InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, ID_POPUP_EXIT, _T("Exit"); -*/ + trayIconMenu = CreatePopupMenu(); + + UINT menuFlags = MF_BYPOSITION | MF_STRING; + InsertMenuW(trayIconMenu, -1, menuFlags, ID_TRAYMENU_SHOWHIDE, _T("Show/hide")); + InsertMenuW(trayIconMenu, -1, menuFlags, ID_FILE_EXIT, _T("Exit")); + + POINT lpClickPoint; + GetCursorPos(&lpClickPoint); + + int nReserved = 0; + + TrackPopupMenu(trayIconMenu, + TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, + lpClickPoint.x, lpClickPoint.y, + nReserved, this->m_hWnd, NULL + ); break; } return 0; @@ -166,3 +180,33 @@ LRESULT window::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, PostQuitMessage(0); return 0; } + +LRESULT window::OnTrayMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +{ + if (trayIconMenu != NULL) { + DestroyMenu(trayIconMenu); + trayIconMenu = NULL; + } + + PostQuitMessage(0); + return 0; +} + +LRESULT window::OnTrayMenuShowHide(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +{ + if (trayIconMenu != NULL) { + DestroyMenu(trayIconMenu); + trayIconMenu = NULL; + } + + if (bIsVisible) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + } + else { + this->ShowWindow(SW_SHOW); + this->BringWindowToTop(); + bIsVisible = true; + } + return 0; +} diff --git a/audio-router-gui/window.h b/audio-router-gui/window.h index 0d066bc..61984d2 100644 --- a/audio-router-gui/window.h +++ b/audio-router-gui/window.h @@ -41,6 +41,8 @@ class window : public CFrameWindowImpl COMMAND_ID_HANDLER(ID_ABOUT, OnAbout) COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview) COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit) + COMMAND_ID_HANDLER(ID_TRAYMENU_SHOWHIDE, OnTrayMenuShowHide) + COMMAND_ID_HANDLER(ID_TRAYMENU_EXIT, OnTrayMenuExit) /*MSG_WM_NCHITTEST(OnNcHitTest)*/ END_MSG_MAP() @@ -49,8 +51,10 @@ class window : public CFrameWindowImpl LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnTrayMenuShowHide(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnTrayMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - + }; \ No newline at end of file