Skip to content

Commit 0d59c89

Browse files
committed
Implement Tray Icon right click menu
1 parent bcd4424 commit 0d59c89

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed
168 Bytes
Binary file not shown.

audio-router-gui/resource.h

86 Bytes
Binary file not shown.

audio-router-gui/window.cpp

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "window.h"
22

33
telemetry* telemetry_m = NULL;
4+
HMENU trayIconMenu;
45

56
window::window(/*bootstrapper* bootstrap*/) : dlg_main_b(true)/*, license(NULL)*//*, bootstrap(bootstrap)*/
67
{
@@ -81,28 +82,41 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
8182

8283
LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
8384
{
85+
if (trayIconMenu != NULL) {
86+
DestroyMenu(trayIconMenu);
87+
trayIconMenu = NULL;
88+
}
89+
8490
switch (LOWORD(lParam))
8591
{
86-
case WM_LBUTTONDBLCLK:
92+
case WM_LBUTTONUP:
8793
if (bIsVisible) {
8894
this->ShowWindow(SW_HIDE);
8995
bIsVisible = false;
90-
} else {
96+
}
97+
else {
9198
this->ShowWindow(SW_SHOW);
9299
this->BringWindowToTop();
93100
bIsVisible = true;
94101
}
95102
break;
96103
case WM_RBUTTONUP:
97-
98-
/*POINT lpClickPoint;
104+
trayIconMenu = CreatePopupMenu();
105+
106+
UINT menuFlags = MF_BYPOSITION | MF_STRING;
107+
InsertMenuW(trayIconMenu, -1, menuFlags, ID_TRAYMENU_SHOWHIDE, _T("Show/hide"));
108+
InsertMenuW(trayIconMenu, -1, menuFlags, ID_FILE_EXIT, _T("Exit"));
99109

100-
UINT uFlag = MF_BYPOSITION | MF_STRING;
110+
POINT lpClickPoint;
101111
GetCursorPos(&lpClickPoint);
102-
103-
HMENU hPopMenu = CreatePopupMenu();
104-
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, ID_POPUP_EXIT, _T("Exit");
105-
*/
112+
113+
int nReserved = 0;
114+
115+
TrackPopupMenu(trayIconMenu,
116+
TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON,
117+
lpClickPoint.x, lpClickPoint.y,
118+
nReserved, this->m_hWnd, NULL
119+
);
106120
break;
107121
}
108122
return 0;
@@ -166,3 +180,33 @@ LRESULT window::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/,
166180
PostQuitMessage(0);
167181
return 0;
168182
}
183+
184+
LRESULT window::OnTrayMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
185+
{
186+
if (trayIconMenu != NULL) {
187+
DestroyMenu(trayIconMenu);
188+
trayIconMenu = NULL;
189+
}
190+
191+
PostQuitMessage(0);
192+
return 0;
193+
}
194+
195+
LRESULT window::OnTrayMenuShowHide(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
196+
{
197+
if (trayIconMenu != NULL) {
198+
DestroyMenu(trayIconMenu);
199+
trayIconMenu = NULL;
200+
}
201+
202+
if (bIsVisible) {
203+
this->ShowWindow(SW_HIDE);
204+
bIsVisible = false;
205+
}
206+
else {
207+
this->ShowWindow(SW_SHOW);
208+
this->BringWindowToTop();
209+
bIsVisible = true;
210+
}
211+
return 0;
212+
}

audio-router-gui/window.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class window : public CFrameWindowImpl<window>
4141
COMMAND_ID_HANDLER(ID_ABOUT, OnAbout)
4242
COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview)
4343
COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit)
44+
COMMAND_ID_HANDLER(ID_TRAYMENU_SHOWHIDE, OnTrayMenuShowHide)
45+
COMMAND_ID_HANDLER(ID_TRAYMENU_EXIT, OnTrayMenuExit)
4446
/*MSG_WM_NCHITTEST(OnNcHitTest)*/
4547
END_MSG_MAP()
4648

@@ -52,5 +54,5 @@ class window : public CFrameWindowImpl<window>
5254
LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
5355
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
5456
LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
55-
57+
5658
};

0 commit comments

Comments
 (0)