mirror of
				https://github.com/gnif/LookingGlass.git
				synced 2025-10-30 20:21:56 +00:00 
			
		
		
		
	[idd] helper: add icon context menu with log directory open
This commit is contained in:
		| @@ -100,7 +100,8 @@ inline static void iso8601(wchar_t *buf, size_t count) | ||||
|   wcsftime(buf, count, L"%Y-%m-%d %H:%M:%SZ", &utc); | ||||
| } | ||||
|  | ||||
| inline static std::wstring getLogPath() { | ||||
| inline static std::wstring getLogPath() | ||||
| { | ||||
|   PWSTR pszPath; | ||||
|   if (FAILED(SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &pszPath))) | ||||
|   { | ||||
|   | ||||
| @@ -1,7 +1,10 @@ | ||||
| #include "CWindow.h" | ||||
| #include <windowsx.h> | ||||
| #include <strsafe.h> | ||||
| #include <CDebug.h> | ||||
|  | ||||
| #define ID_MENU_SHOW_LOG 3000 | ||||
|  | ||||
| ATOM CWindow::s_atom = 0; | ||||
| UINT CWindow::s_taskbarCreated = 0; | ||||
| static HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); | ||||
| @@ -26,10 +29,15 @@ bool CWindow::registerClass() | ||||
|   return s_atom; | ||||
| } | ||||
|  | ||||
| CWindow::CWindow() : m_iconData({ 0 }) | ||||
| CWindow::CWindow() : m_iconData({ 0 }), m_menu(CreatePopupMenu()) | ||||
| { | ||||
|   CreateWindowEx(0, MAKEINTATOM(s_atom), NULL, | ||||
|     0, 0, 0, 0, 0, NULL, NULL, hInstance, this); | ||||
|  | ||||
|   if (m_menu) | ||||
|   { | ||||
|     AppendMenu(m_menu, MF_STRING, ID_MENU_SHOW_LOG, L"Open log directory"); | ||||
|   } | ||||
| } | ||||
|  | ||||
| LRESULT CWindow::wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | ||||
| @@ -58,11 +66,12 @@ LRESULT CWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) | ||||
|   switch (uMsg) | ||||
|   { | ||||
|   case WM_CREATE: | ||||
|     onCreate(); | ||||
|     return 0; | ||||
|     return onCreate(); | ||||
|   case WM_NCDESTROY: | ||||
|     PostQuitMessage(0); | ||||
|     return 0; | ||||
|   case WM_NOTIFY_ICON: | ||||
|     return onNotifyIcon(LOWORD(lParam), HIWORD(lParam), GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam)); | ||||
|   default: | ||||
|     if (s_taskbarCreated && uMsg == s_taskbarCreated) | ||||
|     { | ||||
| @@ -79,6 +88,22 @@ LRESULT CWindow::onCreate() | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| LRESULT CWindow::onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y) | ||||
| { | ||||
|   switch (uEvent) | ||||
|   { | ||||
|   case WM_CONTEXTMENU: | ||||
|     switch (TrackPopupMenu(m_menu, TPM_RETURNCMD | TPM_NONOTIFY, x, y, 0, m_hwnd, NULL)) | ||||
|     { | ||||
|     case ID_MENU_SHOW_LOG: | ||||
|       ShellExecute(m_hwnd, L"open", g_debug.logDir(), NULL, NULL, SW_NORMAL); | ||||
|       break; | ||||
|     } | ||||
|     break; | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| void CWindow::registerIcon() | ||||
| { | ||||
|   m_iconData.cbSize = sizeof m_iconData; | ||||
| @@ -86,12 +111,15 @@ void CWindow::registerIcon() | ||||
|   m_iconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; | ||||
|   m_iconData.uCallbackMessage = WM_NOTIFY_ICON; | ||||
|   m_iconData.hIcon = LoadIcon(hInstance, IDI_APPLICATION); | ||||
|   m_iconData.uVersion = NOTIFYICON_VERSION_4; | ||||
|   StringCbCopy(m_iconData.szTip, sizeof m_iconData.szTip, L"Looking Glass (IDD)"); | ||||
|  | ||||
|   if (!Shell_NotifyIcon(NIM_ADD, &m_iconData)) | ||||
|     DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_ADD)"); | ||||
| } | ||||
|  | ||||
|   if (!Shell_NotifyIcon(NIM_SETVERSION, &m_iconData)) | ||||
|     DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_SETVERSION)"); | ||||
| } | ||||
|  | ||||
| void CWindow::destroy() | ||||
| { | ||||
| @@ -102,8 +130,8 @@ void CWindow::destroy() | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| CWindow::~CWindow() | ||||
| { | ||||
|   destroy(); | ||||
|   DestroyMenu(m_menu); | ||||
| } | ||||
|   | ||||
| @@ -13,8 +13,11 @@ class CWindow { | ||||
|  | ||||
|   HWND m_hwnd = NULL; | ||||
|   NOTIFYICONDATA m_iconData; | ||||
|   HMENU m_menu; | ||||
|  | ||||
|   LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); | ||||
|   LRESULT onCreate(); | ||||
|   LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y); | ||||
|   void registerIcon(); | ||||
|  | ||||
| public: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Quantum
					Quantum