Added support for custom Context Menu items

This commit is contained in:
Brian Ferguson
2012-10-03 14:52:17 -06:00
parent 940b4ff55e
commit f0dd38000d
4 changed files with 107 additions and 3 deletions

View File

@ -140,7 +140,8 @@ CMeterWindow::CMeterWindow(const std::wstring& folderPath, const std::wstring& f
m_UpdateCounter(),
m_MouseMoveCounter(),
m_FontCollection(),
m_ToolTipHidden(false)
m_ToolTipHidden(false),
m_HasCustomContextMenu(false)
{
if (!c_DwmInstance && CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
{
@ -1925,6 +1926,16 @@ bool CMeterWindow::ReadSkin()
// Read options from Rainmeter.ini.
ReadOptions();
std::wstring context = m_Parser.ReadString(L"Rainmeter", L"ContextTitle", L"");
if (!context.empty())
{
context = m_Parser.ReadString(L"Rainmeter", L"ContextAction", L"");
if (!context.empty())
{
m_HasCustomContextMenu = true;
}
}
// Check the version
UINT appVersion = m_Parser.ReadUInt(L"Rainmeter", L"AppVersion", 0);
if (appVersion > RAINMETER_VERSION)
@ -3326,6 +3337,28 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
WriteOptions(OPTION_POSITION | OPTION_AUTOSELECTSCREEN);
}
}
else if (wParam >= IDM_SKIN_CUSTOMCONTEXTMENU_FIRST && wParam <= IDM_SKIN_CUSTOMCONTEXTMENU_LAST)
{
std::wstring action;
int position = (int)wParam - IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + 1;
if (position == 1)
{
action = m_Parser.ReadString(L"Rainmeter", L"ContextAction", L"");
}
else
{
WCHAR buffer[128];
_snwprintf_s(buffer, _TRUNCATE, L"ContextAction%i", position);
action = m_Parser.ReadString(L"Rainmeter", buffer, L"");
}
if (!action.empty())
{
Rainmeter->ExecuteCommand(action.c_str(), this);
}
}
else
{
// Forward to tray window, which handles all the other commands