rainmeter-studio/Library/TrayWindow.cpp

678 lines
16 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://rainmeter.net/cms/Support"
2011-09-03 21:51:25 +00:00
#define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING)
enum TIMER
{
TIMER_TRAY = 3
};
enum INTERVAL
{
INTERVAL_TRAY = 1000
};
const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated");
2009-02-10 18:37:48 +00:00
extern CRainmeter* Rainmeter;
using namespace Gdiplus;
2012-05-05 12:59:35 +00:00
CTrayWindow::CTrayWindow() :
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-05-05 11:49:22 +00:00
m_IconEnabled(true)
2012-05-05 12:59:35 +00:00
{
}
CTrayWindow::~CTrayWindow()
{
KillTimer(m_Window, TIMER_TRAY);
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);
}
void CTrayWindow::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;
2012-05-05 12:59:35 +00:00
wc.hInstance = Rainmeter->GetInstance();
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",
NULL,
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,
NULL,
NULL,
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
}
void CTrayWindow::AddTrayIcon()
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);
m_Icon = NULL;
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
2012-05-05 11:49:22 +00:00
if (m_Icon)
2009-02-10 18:37:48 +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_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_TRAY_NOTIFYICON;
2012-05-05 11:49:22 +00:00
tnid.hIcon = m_Icon;
2011-03-29 19:21:57 +00:00
wcsncpy_s(tnid.szTip, L"Rainmeter", _TRUNCATE);
Shell_NotifyIcon(NIM_ADD, &tnid);
2009-02-10 18:37:48 +00:00
}
}
void CTrayWindow::RemoveTrayIcon()
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
{
2010-11-25 22:00:34 +00:00
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
2011-03-29 19:21:57 +00:00
tnid.hWnd = m_Window;
tnid.uID = IDI_TRAY;
tnid.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE, &tnid);
2009-02-10 18:37:48 +00:00
2012-05-05 11:49:22 +00:00
DestroyIcon(m_Icon);
m_Icon = NULL;
2009-02-10 18:37:48 +00:00
}
}
void CTrayWindow::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);
m_Icon = NULL;
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
}
HICON CTrayWindow::CreateTrayIcon(double value)
{
if (m_Measure != NULL)
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);
HICON icon;
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
2009-02-10 18:37:48 +00:00
HICON icon;
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
}
2012-05-05 11:43:48 +00:00
void CTrayWindow::ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text)
{
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 (CSystem::GetOSPlatform() > OSPLATFORM_VISTA)
{
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
}
}
void CTrayWindow::ShowWelcomeNotification()
{
ShowNotification(TRAY_NOTIFICATION_WELCOME, GetString(ID_STR_WELCOME), GetString(ID_STR_CLICKTOMANAGE));
}
void CTrayWindow::ShowUpdateNotification(const WCHAR* newVersion)
{
std::wstring text = GetFormattedString(ID_STR_CLICKTODOWNLOAD, newVersion);
ShowNotification(TRAY_NOTIFICATION_UPDATE, GetString(ID_STR_UPDATEAVAILABLE), text.c_str());
}
2009-02-10 18:37:48 +00:00
void CTrayWindow::ReadConfig(CConfigParser& parser)
{
2011-07-15 16:54:47 +00:00
// Clear old Settings
KillTimer(m_Window, TIMER_TRAY);
2010-12-21 04:49:01 +00:00
delete m_Measure;
m_Measure = NULL;
2011-07-15 16:54:47 +00:00
delete m_Bitmap;
m_Bitmap = NULL;
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
2012-05-05 11:49:22 +00:00
m_IconEnabled = 0!=parser.ReadInt(L"Rainmeter", L"TrayIcon", 1);
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())
{
2011-07-15 16:54:47 +00:00
CConfigParser* oldParser = Rainmeter->GetCurrentParser();
Rainmeter->SetCurrentParser(&parser);
try
{
m_Measure = CMeasure::Create(measureName.c_str(), NULL, L"TrayMeasure");
if (m_Measure)
{
m_Measure->ReadConfig(parser);
}
}
catch (CError& error)
{
2011-07-15 16:54:47 +00:00
delete m_Measure;
m_Measure = NULL;
LogError(error);
}
2011-07-15 16:54:47 +00:00
Rainmeter->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
{
2011-07-15 16:54:47 +00:00
imageName.insert(0, Rainmeter->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;
HICON hIcon = NULL;
// 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
hIcon = (HICON)LoadImage(NULL, 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
}
2011-11-16 16:47:20 +00:00
while(hIcon != NULL);
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;
m_Bitmap = NULL;
LogWithArgs(LOG_WARNING, 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
{
2011-11-16 16:47:20 +00:00
LogWithArgs(LOG_ERROR, L"No such TrayMeter: %s", type);
2011-07-15 16:54:47 +00:00
}
2009-02-10 18:37:48 +00:00
AddTrayIcon();
2010-12-21 04:49:01 +00:00
if (m_Measure)
{
SetTimer(m_Window, TIMER_TRAY, INTERVAL_TRAY, NULL); // 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
}
LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
2011-12-09 08:40:19 +00:00
CTrayWindow* tray = Rainmeter->GetTrayWindow();
2009-02-10 18:37:48 +00:00
switch (uMsg)
2009-02-10 18:37:48 +00:00
{
case WM_COMMAND:
2012-05-05 12:59:35 +00:00
if (wParam == IDM_MANAGE)
2009-02-10 18:37:48 +00:00
{
2012-05-05 12:59:35 +00:00
CDialogManage::Open();
}
else if (wParam == IDM_ABOUT)
{
CDialogAbout::Open();
}
else if (wParam == IDM_SHOW_HELP)
{
RunCommand(NULL, RAINMETER_HELP, SW_SHOWNORMAL);
}
else if (wParam == IDM_NEW_VERSION)
{
RunCommand(NULL, RAINMETER_OFFICIAL, SW_SHOWNORMAL);
}
else if (wParam == IDM_REFRESH)
{
PostMessage(Rainmeter->GetWindow(), WM_RAINMETER_DELAYED_REFRESH_ALL, (WPARAM)NULL, (LPARAM)NULL);
}
else if (wParam == IDM_SHOWLOGFILE)
{
Rainmeter->ShowLogFile();
}
else if (wParam == IDM_STARTLOG)
{
Rainmeter->StartLogging();
}
else if (wParam == IDM_STOPLOG)
{
Rainmeter->StopLogging();
}
else if (wParam == IDM_DELETELOGFILE)
{
Rainmeter->DeleteLogFile();
}
else if (wParam == IDM_DEBUGLOG)
{
Rainmeter->SetDebug(!Rainmeter->GetDebug());
}
else if (wParam == IDM_DISABLEDRAG)
{
Rainmeter->SetDisableDragging(!Rainmeter->GetDisableDragging());
}
else if (wParam == IDM_EDITCONFIG)
{
Rainmeter->EditSettings();
}
else if (wParam == IDM_QUIT)
{
PostQuitMessage(0);
}
else if (wParam == IDM_OPENSKINSFOLDER)
{
Rainmeter->OpenSkinFolder();
}
else if ((wParam & 0x0ffff) >= ID_THEME_FIRST && (wParam & 0x0ffff) <= ID_THEME_LAST)
{
int pos = (wParam & 0x0ffff) - ID_THEME_FIRST;
const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes();
if (pos >= 0 && pos < (int)themes.size())
2009-02-10 18:37:48 +00:00
{
2012-05-05 12:59:35 +00:00
Rainmeter->LoadTheme(themes[pos]);
2009-02-10 18:37:48 +00:00
}
2012-05-05 12:59:35 +00:00
}
else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST)
{
std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex((UINT)(wParam & 0x0ffff));
if (indexes.first != -1 && indexes.second != -1)
{
2012-05-05 12:59:35 +00:00
Rainmeter->ToggleConfig(indexes.first, indexes.second);
}
2012-05-05 12:59:35 +00:00
}
else
{
// Forward the message to correct window
int index = (int)(wParam >> 16);
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
2012-05-05 12:59:35 +00:00
if (index < (int)windows.size())
2009-02-10 18:37:48 +00:00
{
2012-05-05 12:59:35 +00:00
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for ( ; iter != windows.end(); ++iter)
2009-02-10 18:37:48 +00:00
{
2012-05-05 12:59:35 +00:00
--index;
if (index < 0)
2009-02-10 18:37:48 +00:00
{
2012-05-05 12:59:35 +00:00
CMeterWindow* meterWindow = (*iter).second;
SendMessage(meterWindow->GetWindow(), WM_COMMAND, wParam & 0x0FFFF, NULL);
break;
2009-02-10 18:37:48 +00:00
}
}
}
}
return 0; // Don't send WM_COMMANDS any further
case WM_TRAY_NOTIFYICON:
2009-02-10 18:37:48 +00:00
{
2011-03-29 19:21:57 +00:00
UINT uMouseMsg = (UINT)lParam;
2009-02-10 18:37:48 +00:00
std::wstring bang;
switch (uMouseMsg)
2009-02-10 18:37:48 +00:00
{
case WM_MBUTTONDOWN:
bang = Rainmeter->GetTrayExecuteM();
break;
case WM_RBUTTONDOWN:
bang = Rainmeter->GetTrayExecuteR();
break;
case WM_MBUTTONDBLCLK:
bang = Rainmeter->GetTrayExecuteDM();
break;
case WM_RBUTTONDBLCLK:
bang = Rainmeter->GetTrayExecuteDR();
break;
}
2012-02-20 09:37:46 +00:00
if (!IsCtrlKeyDown() && // Ctrl is pressed, so only run default action
!bang.empty())
2009-02-10 18:37:48 +00:00
{
Rainmeter->ExecuteCommand(bang.c_str(), NULL);
2009-02-10 18:37:48 +00:00
}
else if (uMouseMsg == WM_RBUTTONDOWN)
2009-02-10 18:37:48 +00:00
{
POINT point;
GetCursorPos(&point);
Rainmeter->ShowContextMenu(point, NULL);
}
else if (uMouseMsg == WM_LBUTTONDOWN || uMouseMsg == WM_LBUTTONDBLCLK)
{
CDialogManage::Open();
}
2012-05-05 11:43:48 +00:00
else if (uMouseMsg == NIN_BALLOONUSERCLICK)
{
if (tray->m_Notification == TRAY_NOTIFICATION_WELCOME)
{
CDialogManage::Open();
}
else if (tray->m_Notification == TRAY_NOTIFICATION_UPDATE)
{
RunCommand(NULL, RAINMETER_OFFICIAL, SW_SHOWNORMAL);
}
tray->m_Notification = TRAY_NOTIFICATION_NONE;
}
else if (uMouseMsg == NIN_BALLOONHIDE || uMouseMsg == NIN_BALLOONTIMEOUT)
{
tray->m_Notification = TRAY_NOTIFICATION_NONE;
}
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
2012-02-03 12:48:33 +00:00
if (wParam == RAINMETER_QUERY_ID_SKINS_PATH)
{
sendCopyData(Rainmeter->GetSkinPath());
return 0;
}
2011-03-29 19:21:57 +00:00
else if (wParam == RAINMETER_QUERY_ID_SETTINGS_PATH)
{
2012-02-03 12:48:33 +00:00
sendCopyData(Rainmeter->GetSettingsPath());
return 0;
}
2011-03-29 19:21:57 +00:00
else if (wParam == RAINMETER_QUERY_ID_PLUGINS_PATH)
{
2012-02-03 12:48:33 +00:00
sendCopyData(Rainmeter->GetPluginPath());
return 0;
}
2011-03-29 19:21:57 +00:00
else if (wParam == RAINMETER_QUERY_ID_PROGRAM_PATH)
{
2012-02-03 12:48:33 +00:00
sendCopyData(Rainmeter->GetPath());
return 0;
}
2011-03-29 19:21:57 +00:00
else if (wParam == RAINMETER_QUERY_ID_LOG_PATH)
{
2012-02-03 12:48:33 +00:00
sendCopyData(Rainmeter->GetLogFile());
return 0;
}
2011-03-29 19:21:57 +00:00
else if (wParam == RAINMETER_QUERY_ID_CONFIG_EDITOR)
{
2012-02-03 12:48:33 +00:00
sendCopyData(Rainmeter->GetConfigEditor());
return 0;
}
2012-02-03 12:48:33 +00:00
else if (wParam == RAINMETER_QUERY_ID_IS_DEBUGGING)
{
BOOL debug = Rainmeter->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)
{
2012-02-03 12:48:33 +00:00
LPCWSTR configName = (LPCWSTR)cds->lpData;
2012-02-07 08:32:37 +00:00
CMeterWindow* mw = Rainmeter->GetMeterWindow(configName);
return (mw) ? (LRESULT)mw->GetWindow() : NULL;
}
}
return 1;
2009-02-10 18:37:48 +00:00
case WM_TIMER:
2012-05-05 12:59:35 +00:00
if (tray->m_Measure)
2009-02-10 18:37:48 +00:00
{
tray->m_Measure->Update();
tray->ModifyTrayIcon(tray->m_Measure->GetRelativeValue());
}
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->AddTrayIcon();
}
}
break;
2009-02-10 18:37:48 +00:00
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}