rainmeter-studio/Library/TrayWindow.cpp

737 lines
17 KiB
C++
Raw Normal View History

2009-02-10 18:37:48 +00:00
/*
Copyright (C) 2004 Kimmo Pekkola
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2009-02-10 18:37:48 +00:00
*/
#include "StdAfx.h"
2009-02-10 18:37:48 +00:00
#include "TrayWindow.h"
#include "Measure.h"
#include "resource.h"
2009-02-10 18:37:48 +00:00
#include "Litestep.h"
#include "Rainmeter.h"
#include "DialogAbout.h"
#include "DialogManage.h"
#include "System.h"
2009-02-10 18:37:48 +00:00
#include "Error.h"
#include "RainmeterQuery.h"
2012-05-05 11:43:48 +00:00
#include "resource.h"
#include "../Version.h"
2009-02-10 18:37:48 +00:00
#define RAINMETER_OFFICIAL L"http://rainmeter.net/cms/"
#define RAINMETER_HELP L"http://docs.rainmeter.net/"
2011-09-03 21:51:25 +00:00
#define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING)
enum TIMER
{
TIMER_ADDTRAYICON = 1,
TIMER_TRAYMEASURE = 3
};
enum INTERVAL
{
INTERVAL_ADDTRAYICON = 3000,
INTERVAL_TRAYMEASURE = 1000
};
const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated");
2009-02-10 18:37:48 +00:00
using namespace Gdiplus;
2013-05-31 14:18:52 +00:00
TrayWindow::TrayWindow() :
2012-05-05 11:49:22 +00:00
m_Icon(),
m_Measure(),
m_MeterType(TRAY_METER_TYPE_HISTOGRAM),
2012-05-05 11:49:22 +00:00
m_Color1(0, 100, 0),
m_Color2(0, 255, 0),
m_Bitmap(),
2012-05-05 11:49:22 +00:00
m_Values(),
m_Pos(),
2012-05-05 11:43:48 +00:00
m_Notification(TRAY_NOTIFICATION_NONE),
2012-10-25 09:26:46 +00:00
m_TrayContextMenuEnabled(true),
2012-05-05 11:49:22 +00:00
m_IconEnabled(true)
2012-05-05 12:59:35 +00:00
{
}
2013-05-31 14:18:52 +00:00
TrayWindow::~TrayWindow()
2012-05-05 12:59:35 +00:00
{
KillTimer(m_Window, TIMER_ADDTRAYICON);
KillTimer(m_Window, TIMER_TRAYMEASURE);
2012-05-05 12:59:35 +00:00
RemoveTrayIcon();
delete m_Bitmap;
delete m_Measure;
for (size_t i = 0, isize = m_Icons.size(); i < isize; ++i)
{
DestroyIcon(m_Icons[i]);
}
m_Icons.clear();
if (m_Window) DestroyWindow(m_Window);
}
2013-05-31 14:18:52 +00:00
void TrayWindow::Initialize()
2009-02-10 18:37:48 +00:00
{
2011-10-01 06:27:20 +00:00
WNDCLASS wc = {0};
2009-02-10 18:37:48 +00:00
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hInstance = GetRainmeter().GetModuleInstance();
2009-02-10 18:37:48 +00:00
wc.lpszClassName = L"RainmeterTrayClass";
wc.hIcon = GetIcon(IDI_RAINMETER);
2009-02-10 18:37:48 +00:00
RegisterClass(&wc);
2011-03-29 19:21:57 +00:00
2009-02-10 18:37:48 +00:00
m_Window = CreateWindowEx(
WS_EX_TOOLWINDOW,
L"RainmeterTrayClass",
2013-05-31 14:28:39 +00:00
nullptr,
2011-09-03 21:51:25 +00:00
WS_POPUP | WS_DISABLED,
2009-02-10 18:37:48 +00:00
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
2013-05-31 14:28:39 +00:00
nullptr,
nullptr,
2012-05-05 12:59:35 +00:00
wc.hInstance,
2009-02-10 18:37:48 +00:00
this);
2011-09-03 21:51:25 +00:00
SetWindowPos(m_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
2009-02-10 18:37:48 +00:00
}
2013-05-31 14:18:52 +00:00
bool TrayWindow::AddTrayIcon()
2011-03-29 19:21:57 +00:00
{
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
tnid.hWnd = m_Window;
tnid.uID = IDI_TRAY;
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_TRAY_NOTIFYICON;
tnid.hIcon = m_Icon;
wcsncpy_s(tnid.szTip, APPNAME, _TRUNCATE);
return (Shell_NotifyIcon(NIM_ADD, &tnid) || GetLastError() != ERROR_TIMEOUT);
}
2013-05-31 14:18:52 +00:00
bool TrayWindow::IsTrayIconReady()
{
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
tnid.hWnd = m_Window;
tnid.uID = IDI_TRAY;
2013-12-23 19:42:31 +00:00
return Shell_NotifyIcon(NIM_MODIFY, &tnid) != FALSE;
}
2013-05-31 14:18:52 +00:00
void TrayWindow::TryAddTrayIcon()
{
if (IsTrayIconReady())
{
ModifyTrayIcon(0);
return;
}
2012-05-05 11:49:22 +00:00
if (m_Icon)
2009-02-10 18:37:48 +00:00
{
2012-05-05 11:49:22 +00:00
DestroyIcon(m_Icon);
2013-05-31 14:28:39 +00:00
m_Icon = nullptr;
2009-02-10 18:37:48 +00:00
}
2012-05-05 11:49:22 +00:00
m_Icon = CreateTrayIcon(0);
2009-02-10 18:37:48 +00:00
if (!AddTrayIcon())
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:28:39 +00:00
SetTimer(m_Window, TIMER_ADDTRAYICON, INTERVAL_ADDTRAYICON, nullptr);
2009-02-10 18:37:48 +00:00
}
}
2013-05-31 14:18:52 +00:00
void TrayWindow::CheckTrayIcon()
2011-03-29 19:21:57 +00:00
{
if (IsTrayIconReady() || AddTrayIcon())
2009-02-10 18:37:48 +00:00
{
KillTimer(m_Window, TIMER_ADDTRAYICON);
}
}
2011-03-29 19:21:57 +00:00
2013-05-31 14:18:52 +00:00
void TrayWindow::RemoveTrayIcon()
{
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
tnid.hWnd = m_Window;
tnid.uID = IDI_TRAY;
tnid.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE, &tnid);
2009-02-10 18:37:48 +00:00
if (m_Icon)
{
2012-05-05 11:49:22 +00:00
DestroyIcon(m_Icon);
2013-05-31 14:28:39 +00:00
m_Icon = nullptr;
2009-02-10 18:37:48 +00:00
}
}
2013-05-31 14:18:52 +00:00
void TrayWindow::ModifyTrayIcon(double value)
2011-03-29 19:21:57 +00:00
{
2012-05-05 11:49:22 +00:00
if (m_Icon)
2009-02-10 18:37:48 +00:00
{
2012-05-05 11:49:22 +00:00
DestroyIcon(m_Icon);
2013-05-31 14:28:39 +00:00
m_Icon = nullptr;
2009-02-10 18:37:48 +00:00
}
2012-05-05 11:49:22 +00:00
m_Icon = CreateTrayIcon(value);
2011-03-29 19:21:57 +00:00
2010-11-25 22:00:34 +00:00
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
2011-03-29 19:21:57 +00:00
tnid.hWnd = m_Window;
2009-02-10 18:37:48 +00:00
tnid.uID = IDI_TRAY;
2011-03-29 19:21:57 +00:00
tnid.uFlags = NIF_ICON;
2012-05-05 11:49:22 +00:00
tnid.hIcon = m_Icon;
2009-02-10 18:37:48 +00:00
Shell_NotifyIcon(NIM_MODIFY, &tnid);
2009-02-10 18:37:48 +00:00
}
2013-05-31 14:18:52 +00:00
HICON TrayWindow::CreateTrayIcon(double value)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:28:39 +00:00
if (m_Measure != nullptr)
2009-02-10 18:37:48 +00:00
{
2011-03-29 19:21:57 +00:00
if (m_MeterType == TRAY_METER_TYPE_HISTOGRAM)
2009-02-10 18:37:48 +00:00
{
2012-05-05 11:49:22 +00:00
m_Values[m_Pos] = value;
m_Pos = (m_Pos + 1) % TRAYICON_SIZE;
2009-02-10 18:37:48 +00:00
Bitmap trayBitmap(TRAYICON_SIZE, TRAYICON_SIZE);
Graphics graphics(&trayBitmap);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
Point points[TRAYICON_SIZE + 2];
points[0].X = 0;
points[0].Y = TRAYICON_SIZE;
points[TRAYICON_SIZE + 1].X = TRAYICON_SIZE - 1;
points[TRAYICON_SIZE + 1].Y = TRAYICON_SIZE;
2010-03-30 22:37:05 +00:00
for (int i = 0; i < TRAYICON_SIZE; ++i)
2009-02-10 18:37:48 +00:00
{
points[i + 1].X = i;
2012-05-05 11:49:22 +00:00
points[i + 1].Y = (int)(TRAYICON_SIZE * (1.0 - m_Values[(m_Pos + i) % TRAYICON_SIZE]));
2009-02-10 18:37:48 +00:00
}
2012-05-05 11:49:22 +00:00
SolidBrush brush(m_Color1);
2009-02-10 18:37:48 +00:00
graphics.FillRectangle(&brush, 0, 0, TRAYICON_SIZE, TRAYICON_SIZE);
2012-05-05 11:49:22 +00:00
SolidBrush brush2(m_Color2);
2009-02-10 18:37:48 +00:00
graphics.FillPolygon(&brush2, points, TRAYICON_SIZE + 2);
2013-05-31 14:28:39 +00:00
HICON icon = nullptr;
2009-02-10 18:37:48 +00:00
trayBitmap.GetHICON(&icon);
return icon;
}
2012-05-05 11:49:22 +00:00
else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || !m_Icons.empty()))
2009-02-10 18:37:48 +00:00
{
2012-05-05 11:49:22 +00:00
if (!m_Icons.empty())
2009-02-10 18:37:48 +00:00
{
size_t frame = 0;
2012-05-05 11:49:22 +00:00
size_t frameCount = m_Icons.size();
2009-02-10 18:37:48 +00:00
// Select the correct frame linearly
frame = (size_t)(value * frameCount);
frame = min((frameCount - 1), frame);
2012-05-05 11:49:22 +00:00
return CopyIcon(m_Icons[frame]);
2009-02-10 18:37:48 +00:00
}
else
{
int frame = 0;
int frameCount = 0;
int newX, newY;
2011-03-29 19:21:57 +00:00
if (m_Bitmap->GetWidth() > m_Bitmap->GetHeight())
2009-02-10 18:37:48 +00:00
{
frameCount = m_Bitmap->GetWidth() / TRAYICON_SIZE;
}
else
{
frameCount = m_Bitmap->GetHeight() / TRAYICON_SIZE;
}
// Select the correct frame linearly
frame = (int)(value * frameCount);
frame = min((frameCount - 1), frame);
2011-03-29 19:21:57 +00:00
if (m_Bitmap->GetWidth() > m_Bitmap->GetHeight())
2009-02-10 18:37:48 +00:00
{
newX = frame * TRAYICON_SIZE;
newY = 0;
}
else
{
newX = 0;
newY = frame * TRAYICON_SIZE;
}
Bitmap trayBitmap(TRAYICON_SIZE, TRAYICON_SIZE);
Graphics graphics(&trayBitmap);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
// Blit the image
Rect r(0, 0, TRAYICON_SIZE, TRAYICON_SIZE);
graphics.DrawImage(m_Bitmap, r, newX, newY, TRAYICON_SIZE, TRAYICON_SIZE, UnitPixel);
2011-03-29 19:21:57 +00:00
2013-05-31 14:28:39 +00:00
HICON icon = nullptr;
2009-02-10 18:37:48 +00:00
trayBitmap.GetHICON(&icon);
return icon;
}
}
}
// Return the default icon if there is no valid measure
return GetIcon(IDI_TRAY);
2009-02-10 18:37:48 +00:00
}
2013-05-31 14:18:52 +00:00
void TrayWindow::ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text)
2012-05-05 11:43:48 +00:00
{
if (m_Notification == TRAY_NOTIFICATION_NONE)
{
NOTIFYICONDATA nid = {sizeof(NOTIFYICONDATA)};
nid.hWnd = m_Window;
nid.uID = IDI_TRAY;
nid.uFlags = NIF_INFO;
nid.uTimeout = 30000;
nid.dwInfoFlags = NIIF_USER;
wcsncpy_s(nid.szInfoTitle, title, _TRUNCATE);
wcsncpy_s(nid.szInfo, text, _TRUNCATE);
2012-05-05 12:48:41 +00:00
if (IsWindows7OrGreater())
{
nid.dwInfoFlags |= NIIF_LARGE_ICON;
nid.hBalloonIcon = GetIcon(IDI_RAINMETER, true);
}
2012-05-05 12:48:41 +00:00
if (Shell_NotifyIcon(NIM_MODIFY, &nid))
{
m_Notification = id;
}
2012-05-05 11:43:48 +00:00
}
}
2013-05-31 14:18:52 +00:00
void TrayWindow::ShowWelcomeNotification()
2012-05-05 11:43:48 +00:00
{
ShowNotification(TRAY_NOTIFICATION_WELCOME, GetString(ID_STR_WELCOME), GetString(ID_STR_CLICKTOMANAGE));
}
2013-05-31 14:18:52 +00:00
void TrayWindow::ShowUpdateNotification(const WCHAR* newVersion)
2012-05-05 11:43:48 +00:00
{
std::wstring text = GetFormattedString(ID_STR_CLICKTODOWNLOAD, newVersion);
ShowNotification(TRAY_NOTIFICATION_UPDATE, GetString(ID_STR_UPDATEAVAILABLE), text.c_str());
}
2013-05-31 14:18:52 +00:00
void TrayWindow::SetTrayIcon(bool enabled)
{
2012-11-13 14:11:43 +00:00
enabled ? TryAddTrayIcon() : RemoveTrayIcon();
m_IconEnabled = enabled;
2012-11-13 14:11:43 +00:00
// Save to Rainmeter.ini.
const std::wstring& iniFile = GetRainmeter().GetIniFile();
2013-05-31 14:28:39 +00:00
WritePrivateProfileString(L"Rainmeter", L"TrayIcon", enabled ? nullptr : L"0", iniFile.c_str());
}
2013-05-31 14:18:52 +00:00
void TrayWindow::ReadOptions(ConfigParser& parser)
2009-02-10 18:37:48 +00:00
{
2011-07-15 16:54:47 +00:00
// Clear old Settings
KillTimer(m_Window, TIMER_ADDTRAYICON);
KillTimer(m_Window, TIMER_TRAYMEASURE);
2010-12-21 04:49:01 +00:00
delete m_Measure;
2013-05-31 14:28:39 +00:00
m_Measure = nullptr;
2011-07-15 16:54:47 +00:00
delete m_Bitmap;
2013-05-31 14:28:39 +00:00
m_Bitmap = nullptr;
2011-07-15 16:54:47 +00:00
2012-05-05 11:49:22 +00:00
std::vector<HICON>::const_iterator iter = m_Icons.begin();
for ( ; iter != m_Icons.end(); ++iter)
2009-02-10 18:37:48 +00:00
{
DestroyIcon((*iter));
2009-02-10 18:37:48 +00:00
}
2012-05-05 11:49:22 +00:00
m_Icons.clear();
2009-02-10 18:37:48 +00:00
2011-07-15 16:54:47 +00:00
m_MeterType = TRAY_METER_TYPE_NONE;
2009-02-10 18:37:48 +00:00
2011-07-15 16:54:47 +00:00
// Read tray settings
m_IconEnabled = parser.ReadBool(L"Rainmeter", L"TrayIcon", true);
2012-05-05 11:49:22 +00:00
if (m_IconEnabled)
2009-02-10 18:37:48 +00:00
{
2011-11-16 16:47:20 +00:00
const std::wstring& measureName = parser.ReadString(L"TrayMeasure", L"Measure", L"");
2011-07-15 16:54:47 +00:00
if (!measureName.empty())
{
ConfigParser* oldParser = GetRainmeter().GetCurrentParser();
GetRainmeter().SetCurrentParser(&parser);
2011-07-15 16:54:47 +00:00
2013-05-31 14:28:39 +00:00
m_Measure = Measure::Create(measureName.c_str(), nullptr, L"TrayMeasure");
2012-08-12 14:02:08 +00:00
if (m_Measure)
2011-07-15 16:54:47 +00:00
{
2012-08-12 14:02:08 +00:00
m_Measure->ReadOptions(parser);
}
2011-07-15 16:54:47 +00:00
GetRainmeter().SetCurrentParser(oldParser);
}
2011-07-15 16:54:47 +00:00
2011-11-16 16:47:20 +00:00
const WCHAR* type = parser.ReadString(L"TrayMeasure", L"TrayMeter", m_Measure ? L"HISTOGRAM" : L"NONE").c_str();
if (_wcsicmp(type, L"NONE") == 0)
{
2011-07-15 16:54:47 +00:00
// Use main icon
}
2011-11-16 16:47:20 +00:00
else if (_wcsicmp(type, L"HISTOGRAM") == 0)
2011-07-15 16:54:47 +00:00
{
m_MeterType = TRAY_METER_TYPE_HISTOGRAM;
2012-05-05 11:49:22 +00:00
m_Color1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color::MakeARGB(255, 0, 100, 0));
m_Color2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color::MakeARGB(255, 0, 255, 0));
2011-07-15 16:54:47 +00:00
}
2011-11-16 16:47:20 +00:00
else if (_wcsicmp(type, L"BITMAP") == 0)
2011-07-15 16:54:47 +00:00
{
m_MeterType = TRAY_METER_TYPE_BITMAP;
2011-07-15 16:54:47 +00:00
std::wstring imageName = parser.ReadString(L"TrayMeasure", L"TrayBitmap", L"");
2009-02-10 18:37:48 +00:00
2011-07-15 16:54:47 +00:00
// Load the bitmaps if defined
if (!imageName.empty())
2009-02-10 18:37:48 +00:00
{
imageName.insert(0, GetRainmeter().GetSkinPath());
const WCHAR* imagePath = imageName.c_str();
if (_wcsicmp(imagePath + (imageName.size() - 4), L".ico") == 0)
2009-02-10 18:37:48 +00:00
{
2011-11-16 16:47:20 +00:00
int count = 1;
2013-05-31 14:28:39 +00:00
HICON hIcon = nullptr;
2011-11-16 16:47:20 +00:00
// Load the icons
do
2009-02-10 18:37:48 +00:00
{
2011-11-16 16:47:20 +00:00
WCHAR buffer[MAX_PATH];
_snwprintf_s(buffer, _TRUNCATE, imagePath, count++);
2011-11-16 16:47:20 +00:00
2013-05-31 14:28:39 +00:00
hIcon = (HICON)LoadImage(nullptr, buffer, IMAGE_ICON, TRAYICON_SIZE, TRAYICON_SIZE, LR_LOADFROMFILE);
2012-05-05 11:49:22 +00:00
if (hIcon) m_Icons.push_back(hIcon);
if (wcscmp(imagePath, buffer) == 0) break;
2011-07-15 16:54:47 +00:00
}
2013-05-31 14:28:39 +00:00
while(hIcon != nullptr);
2009-02-10 18:37:48 +00:00
}
2012-05-05 11:49:22 +00:00
if (m_Icons.empty())
2009-02-10 18:37:48 +00:00
{
2011-07-15 16:54:47 +00:00
// No icons found so load as bitmap
2009-02-10 18:37:48 +00:00
delete m_Bitmap;
m_Bitmap = new Bitmap(imagePath);
2011-07-15 16:54:47 +00:00
Status status = m_Bitmap->GetLastStatus();
if (Ok != status)
{
delete m_Bitmap;
2013-05-31 14:28:39 +00:00
m_Bitmap = nullptr;
2013-05-30 14:19:42 +00:00
LogWarningF(L"Bitmap image not found: %s", imagePath);
2011-07-15 16:54:47 +00:00
}
2009-02-10 18:37:48 +00:00
}
}
}
2011-07-15 16:54:47 +00:00
else
{
2013-05-30 14:19:42 +00:00
LogErrorF(L"No such TrayMeter: %s", type);
2011-07-15 16:54:47 +00:00
}
2009-02-10 18:37:48 +00:00
TryAddTrayIcon();
2010-12-21 04:49:01 +00:00
if (m_Measure)
{
2013-05-31 14:28:39 +00:00
SetTimer(m_Window, TIMER_TRAYMEASURE, INTERVAL_TRAYMEASURE, nullptr); // Update the tray once per sec
2010-12-21 04:49:01 +00:00
}
2009-02-10 18:37:48 +00:00
}
else
{
RemoveTrayIcon();
}
2009-02-10 18:37:48 +00:00
}
2013-05-31 14:18:52 +00:00
LRESULT CALLBACK TrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2009-02-10 18:37:48 +00:00
{
TrayWindow* tray = GetRainmeter().GetTrayWindow();
2009-02-10 18:37:48 +00:00
switch (uMsg)
2009-02-10 18:37:48 +00:00
{
case WM_COMMAND:
switch (wParam)
2009-02-10 18:37:48 +00:00
{
case IDM_MANAGE:
2013-05-31 14:18:52 +00:00
DialogManage::Open();
break;
case IDM_ABOUT:
2013-05-31 14:18:52 +00:00
DialogAbout::Open();
break;
case IDM_SHOW_HELP:
2013-05-31 14:18:52 +00:00
CommandHandler::RunFile(RAINMETER_HELP);
break;
case IDM_NEW_VERSION:
2013-05-31 14:18:52 +00:00
CommandHandler::RunFile(RAINMETER_OFFICIAL);
break;
case IDM_REFRESH:
PostMessage(GetRainmeter().GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)nullptr, (LPARAM)nullptr);
break;
case IDM_SHOWLOGFILE:
GetRainmeter().ShowLogFile();
break;
case IDM_STARTLOG:
2013-06-13 14:22:42 +00:00
GetLogger().StartLogFile();
break;
case IDM_STOPLOG:
2013-06-13 14:22:42 +00:00
GetLogger().StopLogFile();
break;
case IDM_DELETELOGFILE:
2013-06-13 14:22:42 +00:00
GetLogger().DeleteLogFile();
break;
case IDM_DEBUGLOG:
GetRainmeter().SetDebug(!GetRainmeter().GetDebug());
break;
case IDM_DISABLEDRAG:
GetRainmeter().SetDisableDragging(!GetRainmeter().GetDisableDragging());
break;
case IDM_EDITCONFIG:
GetRainmeter().EditSettings();
break;
case IDM_QUIT:
2012-05-05 12:59:35 +00:00
PostQuitMessage(0);
break;
case IDM_OPENSKINSFOLDER:
GetRainmeter().OpenSkinFolder();
break;
2012-05-05 12:59:35 +00:00
default:
2009-02-10 18:37:48 +00:00
{
UINT mID = wParam & 0x0FFFF;
if (mID >= ID_THEME_FIRST && mID <= ID_THEME_LAST)
{
int pos = mID - ID_THEME_FIRST;
const std::vector<std::wstring>& layouts = GetRainmeter().GetAllLayouts();
if (pos >= 0 && pos < (int)layouts.size())
{
GetRainmeter().LoadLayout(layouts[pos]);
}
}
else if (mID >= ID_CONFIG_FIRST && mID <= ID_CONFIG_LAST)
{
GetRainmeter().ToggleSkinWithID(mID);
}
else
2009-02-10 18:37:48 +00:00
{
// Forward the message to correct window
int index = (int)(wParam >> 16);
const std::map<std::wstring, MeterWindow*>& windows = GetRainmeter().GetAllMeterWindows();
if (index < (int)windows.size())
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
std::map<std::wstring, MeterWindow*>::const_iterator iter = windows.begin();
for ( ; iter != windows.end(); ++iter)
{
--index;
if (index < 0)
{
2013-05-31 14:18:52 +00:00
MeterWindow* meterWindow = (*iter).second;
2013-05-31 14:28:39 +00:00
SendMessage(meterWindow->GetWindow(), WM_COMMAND, mID, 0);
break;
}
}
2009-02-10 18:37:48 +00:00
}
}
}
break;
2009-02-10 18:37:48 +00:00
}
2012-10-25 09:26:46 +00:00
break; // Don't send WM_COMMANDS any further
2009-02-10 18:37:48 +00:00
case WM_TRAY_NOTIFYICON:
2009-02-10 18:37:48 +00:00
{
2011-03-29 19:21:57 +00:00
UINT uMouseMsg = (UINT)lParam;
LPCWSTR bang;
2009-02-10 18:37:48 +00:00
// Check TrayExecute actions
switch (uMouseMsg)
2009-02-10 18:37:48 +00:00
{
case WM_MBUTTONDOWN:
bang = GetRainmeter().GetTrayExecuteM().c_str();
2009-02-10 18:37:48 +00:00
break;
case WM_RBUTTONDOWN:
bang = GetRainmeter().GetTrayExecuteR().c_str();
2009-02-10 18:37:48 +00:00
break;
case WM_MBUTTONDBLCLK:
bang = GetRainmeter().GetTrayExecuteDM().c_str();
2009-02-10 18:37:48 +00:00
break;
case WM_RBUTTONDBLCLK:
bang = GetRainmeter().GetTrayExecuteDR().c_str();
break;
default:
bang = L"";
2009-02-10 18:37:48 +00:00
break;
}
if (*bang &&
2012-10-25 09:26:46 +00:00
!IsCtrlKeyDown()) // Ctrl is pressed, so only run default action
2009-02-10 18:37:48 +00:00
{
GetRainmeter().ExecuteCommand(bang, nullptr);
2012-10-25 09:26:46 +00:00
tray->m_TrayContextMenuEnabled = (uMouseMsg != WM_RBUTTONDOWN);
break;
2009-02-10 18:37:48 +00:00
}
// Run default UI action
switch (uMouseMsg)
2009-02-10 18:37:48 +00:00
{
case WM_RBUTTONDOWN:
2012-10-25 09:26:46 +00:00
tray->m_TrayContextMenuEnabled = true;
break;
case WM_RBUTTONUP:
2012-10-25 09:26:46 +00:00
if (tray->m_TrayContextMenuEnabled)
{
2013-05-31 14:18:52 +00:00
POINT pos = System::GetCursorPosition();
GetRainmeter().ShowContextMenu(pos, nullptr);
2012-10-25 09:26:46 +00:00
}
break;
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
2013-05-31 14:18:52 +00:00
DialogManage::Open();
break;
case NIN_BALLOONUSERCLICK:
2012-05-05 11:43:48 +00:00
if (tray->m_Notification == TRAY_NOTIFICATION_WELCOME)
{
2013-05-31 14:18:52 +00:00
DialogManage::Open();
2012-05-05 11:43:48 +00:00
}
else if (tray->m_Notification == TRAY_NOTIFICATION_UPDATE)
{
2013-05-31 14:18:52 +00:00
CommandHandler::RunFile(RAINMETER_OFFICIAL);
2012-05-05 11:43:48 +00:00
}
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;
case NIN_BALLOONHIDE:
case NIN_BALLOONTIMEOUT:
2012-05-05 11:43:48 +00:00
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;
2012-05-05 11:43:48 +00:00
}
2009-02-10 18:37:48 +00:00
}
break;
case WM_QUERY_RAINMETER:
if (IsWindow((HWND)lParam))
{
2012-02-03 12:48:33 +00:00
auto sendCopyData = [&](const std::wstring& data)
{
2012-02-03 12:48:33 +00:00
COPYDATASTRUCT cds;
cds.dwData = wParam;
cds.cbData = (DWORD)((data.length() + 1) * sizeof(WCHAR));
2012-02-03 12:48:33 +00:00
cds.lpData = (PVOID)data.c_str();
SendMessage((HWND)lParam, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds);
2012-02-03 12:48:33 +00:00
};
2011-03-29 19:21:57 +00:00
switch (wParam)
2012-02-03 12:48:33 +00:00
{
case RAINMETER_QUERY_ID_SKINS_PATH:
sendCopyData(GetRainmeter().GetSkinPath());
return 0;
case RAINMETER_QUERY_ID_SETTINGS_PATH:
sendCopyData(GetRainmeter().GetSettingsPath());
return 0;
case RAINMETER_QUERY_ID_PLUGINS_PATH:
sendCopyData(GetRainmeter().GetPluginPath());
return 0;
case RAINMETER_QUERY_ID_PROGRAM_PATH:
sendCopyData(GetRainmeter().GetPath());
return 0;
case RAINMETER_QUERY_ID_LOG_PATH:
2013-06-13 14:22:42 +00:00
sendCopyData(GetLogger().GetLogFilePath());
return 0;
case RAINMETER_QUERY_ID_CONFIG_EDITOR:
sendCopyData(GetRainmeter().GetSkinEditor());
return 0;
case RAINMETER_QUERY_ID_IS_DEBUGGING:
{
BOOL debug = GetRainmeter().GetDebug();
SendMessage((HWND)lParam, WM_QUERY_RAINMETER_RETURN, (WPARAM)hWnd, (LPARAM)debug);
}
return 0;
}
}
return 1;
case WM_COPYDATA:
{
2011-12-09 08:40:19 +00:00
COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
2011-03-29 19:21:57 +00:00
if (cds->dwData == RAINMETER_QUERY_ID_SKIN_WINDOWHANDLE)
{
LPCWSTR folderPath = (LPCWSTR)cds->lpData;
MeterWindow* mw = GetRainmeter().GetMeterWindow(folderPath);
2013-05-31 14:28:39 +00:00
return (mw) ? (LRESULT)mw->GetWindow() : 0;
}
}
return 1;
2009-02-10 18:37:48 +00:00
case WM_TIMER:
if (wParam == TIMER_TRAYMEASURE)
{
if (tray->m_Measure)
{
tray->m_Measure->Update();
tray->ModifyTrayIcon(tray->m_Measure->GetRelativeValue());
}
}
else if (wParam == TIMER_ADDTRAYICON)
2009-02-10 18:37:48 +00:00
{
tray->CheckTrayIcon();
2009-02-10 18:37:48 +00:00
}
break;
case WM_DESTROY:
PostQuitMessage(0);
2009-02-10 18:37:48 +00:00
break;
2011-12-09 08:40:19 +00:00
default:
if (uMsg == WM_TASKBARCREATED)
{
2012-05-05 12:59:35 +00:00
if (tray->IsTrayIconEnabled())
2011-12-09 08:40:19 +00:00
{
tray->RemoveTrayIcon();
tray->TryAddTrayIcon();
2011-12-09 08:40:19 +00:00
}
}
2012-10-25 09:26:46 +00:00
return DefWindowProc(hWnd, uMsg, wParam, lParam);
2009-02-10 18:37:48 +00:00
}
2012-10-25 09:26:46 +00:00
return 0;
2009-02-10 18:37:48 +00:00
}