Skip to content

Commit

Permalink
Implement Tray Icon right click menu
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfreak99 committed Jul 2, 2017
1 parent 50e3638 commit cc97f1c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 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.
66 changes: 55 additions & 11 deletions audio-router-gui/window.cpp
Original file line number Diff line number Diff line change
@@ -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)*/
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
8 changes: 6 additions & 2 deletions audio-router-gui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class window : public CFrameWindowImpl<window>
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()

Expand All @@ -49,8 +51,10 @@ class window : public CFrameWindowImpl<window>
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);

};

0 comments on commit cc97f1c

Please sign in to comment.