Fixed an issue that Rainmeter crashes if bang is executed via exe during initializing the skins.

This commit is contained in:
spx 2011-02-16 14:46:17 +00:00
parent cb3a7d3a75
commit 96f8407c74
3 changed files with 25 additions and 8 deletions

View File

@ -171,7 +171,13 @@ void Initialize(bool DummyLS, LPCTSTR CmdLine)
*/ */
void ExecuteBang(LPCTSTR szBang) 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) if (Rainmeter)
{ {
// Refresh needs to be delayed since it crashes if done during Update() // 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);
} }
} }

View File

@ -119,7 +119,7 @@ BOOL CTrayWindow::AddTrayIcon()
tnid.hWnd = m_Window; tnid.hWnd = m_Window;
tnid.uID = IDI_TRAY; tnid.uID = IDI_TRAY;
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_NOTIFYICON; tnid.uCallbackMessage = WM_TRAY_NOTIFYICON;
tnid.hIcon = m_TrayIcon; tnid.hIcon = m_TrayIcon;
wcsncpy_s(tnid.szTip, L"Rainmeter", _TRUNCATE); 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) 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) 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 return 0; // Don't send WM_COMMANDS any further
case WM_NOTIFYICON: case WM_TRAY_NOTIFYICON:
{ {
UINT uMouseMsg = (UINT)lParam; UINT uMouseMsg = (UINT)lParam;
@ -810,7 +810,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} }
break; break;
case WM_DELAYED_REFRESH_ALL: case WM_TRAY_DELAYED_REFRESH_ALL:
if (Rainmeter) if (Rainmeter)
{ {
// Refresh all // Refresh all
@ -818,6 +818,16 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} }
return 0; 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: case WM_DESTROY:
if (Rainmeter->GetDummyLitestep()) PostQuitMessage(0); if (Rainmeter->GetDummyLitestep()) PostQuitMessage(0);
break; break;

View File

@ -23,9 +23,10 @@
#include <gdiplus.h> #include <gdiplus.h>
#include <vector> #include <vector>
#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 #define TRAYICON_SIZE 16
enum TRAY_METER_TYPE enum TRAY_METER_TYPE