diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 39176733..2c22b58b 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -171,7 +171,13 @@ void Initialize(bool DummyLS, LPCTSTR CmdLine) */ void ExecuteBang(LPCTSTR szBang) { - if (Rainmeter) Rainmeter->ExecuteCommand(szBang, NULL); + if (Rainmeter && szBang) + { + // ExecuteBang needs to be delayed since it crashes if done during processing. + // The receiver must free a given string buffer (lParam) by using free(). + WCHAR* bang = _wcsdup(szBang); + PostMessage(Rainmeter->GetTrayWindow()->GetWindow(), WM_TRAY_DELAYED_EXECUTE, (WPARAM)NULL, (LPARAM)bang); + } } /* @@ -1318,7 +1324,7 @@ void RainmeterRefreshAppWide() if (Rainmeter) { // Refresh needs to be delayed since it crashes if done during Update() - PostMessage(Rainmeter->GetTrayWindow()->GetWindow(), WM_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL); + PostMessage(Rainmeter->GetTrayWindow()->GetWindow(), WM_TRAY_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL); } } diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index 3b89a76b..a73918b1 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -119,7 +119,7 @@ BOOL CTrayWindow::AddTrayIcon() tnid.hWnd = m_Window; tnid.uID = IDI_TRAY; tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; - tnid.uCallbackMessage = WM_NOTIFYICON; + tnid.uCallbackMessage = WM_TRAY_NOTIFYICON; tnid.hIcon = m_TrayIcon; wcsncpy_s(tnid.szTip, L"Rainmeter", _TRUNCATE); @@ -410,7 +410,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } else if(wParam == ID_CONTEXT_REFRESH) { - PostMessage(tray->GetWindow(), WM_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL); + PostMessage(tray->GetWindow(), WM_TRAY_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL); } else if(wParam == ID_CONTEXT_SHOWLOGFILE) { @@ -538,7 +538,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } return 0; // Don't send WM_COMMANDS any further - case WM_NOTIFYICON: + case WM_TRAY_NOTIFYICON: { UINT uMouseMsg = (UINT)lParam; @@ -810,7 +810,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } break; - case WM_DELAYED_REFRESH_ALL: + case WM_TRAY_DELAYED_REFRESH_ALL: if (Rainmeter) { // Refresh all @@ -818,6 +818,16 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } return 0; + case WM_TRAY_DELAYED_EXECUTE: + if (Rainmeter && lParam) + { + // Execute bang + WCHAR* bang = (WCHAR*)lParam; + Rainmeter->ExecuteCommand(bang, NULL); + free(bang); // _wcsdup() + } + return 0; + case WM_DESTROY: if (Rainmeter->GetDummyLitestep()) PostQuitMessage(0); break; diff --git a/Library/TrayWindow.h b/Library/TrayWindow.h index 39b8ddaf..e671acb4 100644 --- a/Library/TrayWindow.h +++ b/Library/TrayWindow.h @@ -23,9 +23,10 @@ #include #include -#define WM_DELAYED_REFRESH_ALL WM_APP + 0 +#define WM_TRAY_DELAYED_REFRESH_ALL WM_APP + 0 +#define WM_TRAY_DELAYED_EXECUTE WM_APP + 1 -#define WM_NOTIFYICON WM_USER + 101 +#define WM_TRAY_NOTIFYICON WM_USER + 101 #define TRAYICON_SIZE 16 enum TRAY_METER_TYPE