forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrayIcon.cpp
831 lines (702 loc) · 19.5 KB
/
TrayIcon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
/* Copyright (C) 2004 Rainmeter Project Developers
*
* This Source Code Form is subject to the terms of the GNU General Public
* License; either version 2 of the License, or (at your option) any later
* version. If a copy of the GPL was not distributed with this file, You can
* obtain one at <https://www.gnu.org/licenses/gpl-2.0.html>. */
#include "StdAfx.h"
#include "TrayIcon.h"
#include "Measure.h"
#include "resource.h"
#include "Util.h"
#include "Rainmeter.h"
#include "DialogAbout.h"
#include "DialogManage.h"
#include "GameMode.h"
#include "System.h"
#include "RainmeterQuery.h"
#include "resource.h"
#include "../Version.h"
#define RAINMETER_OFFICIAL L"https://www.rainmeter.net"
#define RAINMETER_HELP L"https://docs.rainmeter.net"
#define RAINMETER_LOCALIZATION L"https://www.rainmeter.net/localization"
#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");
using namespace Gdiplus;
TrayIcon::TrayIcon() :
m_Window(nullptr),
m_Icon(),
m_Measure(),
m_MeterType(TRAY_METER_TYPE_HISTOGRAM),
m_Color1(0, 100, 0),
m_Color2(0, 255, 0),
m_Bitmap(),
m_Values(),
m_Pos(),
m_Notification(TRAY_NOTIFICATION_NONE),
m_TrayContextMenuEnabled(true),
m_IconEnabled(true)
{
}
TrayIcon::~TrayIcon()
{
KillTimer(m_Window, TIMER_ADDTRAYICON);
KillTimer(m_Window, TIMER_TRAYMEASURE);
RemoveTrayIcon();
delete m_Bitmap;
m_Bitmap = nullptr;
delete m_Measure;
m_Measure = nullptr;
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);
m_Window = nullptr;
}
}
void TrayIcon::Initialize()
{
WNDCLASS wc = {0};
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hInstance = GetRainmeter().GetModuleInstance();
wc.lpszClassName = L"RainmeterTrayClass";
wc.hIcon = GetIcon(IDI_RAINMETER);
RegisterClass(&wc);
m_Window = CreateWindowEx(
WS_EX_TOOLWINDOW,
L"RainmeterTrayClass",
nullptr,
WS_POPUP | WS_DISABLED,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
nullptr,
nullptr,
wc.hInstance,
this);
SetWindowPos(m_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
}
bool TrayIcon::AddTrayIcon()
{
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
tnid.hWnd = m_Window;
tnid.uID = IDI_RAINMETER;
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);
}
bool TrayIcon::IsTrayIconReady()
{
NOTIFYICONIDENTIFIER nii = { sizeof(NOTIFYICONIDENTIFIER) };
nii.hWnd = m_Window;
nii.uID = IDI_RAINMETER;
RECT rect;
HRESULT hr = Shell_NotifyIconGetRect(&nii, &rect);
if (FAILED(hr)) return false;
return true;
}
void TrayIcon::TryAddTrayIcon()
{
if (IsTrayIconReady())
{
ModifyTrayIcon(0);
return;
}
if (m_Icon)
{
DestroyIcon(m_Icon);
m_Icon = nullptr;
}
m_Icon = CreateTrayIcon(0);
if (!AddTrayIcon())
{
SetTimer(m_Window, TIMER_ADDTRAYICON, INTERVAL_ADDTRAYICON, nullptr);
}
}
void TrayIcon::CheckTrayIcon()
{
if (IsTrayIconReady() || AddTrayIcon())
{
KillTimer(m_Window, TIMER_ADDTRAYICON);
}
}
void TrayIcon::RemoveTrayIcon()
{
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
tnid.hWnd = m_Window;
tnid.uID = IDI_RAINMETER;
tnid.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE, &tnid);
if (m_Icon)
{
DestroyIcon(m_Icon);
m_Icon = nullptr;
}
}
void TrayIcon::ModifyTrayIcon(double value)
{
if (m_Icon)
{
DestroyIcon(m_Icon);
m_Icon = nullptr;
}
m_Icon = CreateTrayIcon(value);
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
tnid.hWnd = m_Window;
tnid.uID = IDI_RAINMETER;
tnid.uFlags = NIF_ICON;
tnid.hIcon = m_Icon;
Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
HICON TrayIcon::CreateTrayIcon(double value)
{
if (m_Measure != nullptr)
{
if (m_MeterType == TRAY_METER_TYPE_HISTOGRAM)
{
m_Values[m_Pos] = value;
m_Pos = (m_Pos + 1) % TRAYICON_SIZE;
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;
for (int i = 0; i < TRAYICON_SIZE; ++i)
{
points[i + 1].X = i;
points[i + 1].Y = (int)(TRAYICON_SIZE * (1.0 - m_Values[(m_Pos + i) % TRAYICON_SIZE]));
}
SolidBrush brush(m_Color1);
graphics.FillRectangle(&brush, 0, 0, TRAYICON_SIZE, TRAYICON_SIZE);
SolidBrush brush2(m_Color2);
graphics.FillPolygon(&brush2, points, TRAYICON_SIZE + 2);
HICON icon = nullptr;
trayBitmap.GetHICON(&icon);
return icon;
}
else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || !m_Icons.empty()))
{
if (!m_Icons.empty())
{
size_t frame = 0;
size_t frameCount = m_Icons.size();
// Select the correct frame linearly
frame = (size_t)(value * frameCount);
frame = min((frameCount - 1), frame);
return CopyIcon(m_Icons[frame]);
}
else
{
int frame = 0;
int frameCount = 0;
int newX, newY;
if (m_Bitmap->GetWidth() > m_Bitmap->GetHeight())
{
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);
if (m_Bitmap->GetWidth() > m_Bitmap->GetHeight())
{
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);
HICON icon = nullptr;
trayBitmap.GetHICON(&icon);
return icon;
}
}
}
// Return the default icon if there is no valid measure
return GetIcon(IDI_RAINMETER);
}
void TrayIcon::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_RAINMETER;
nid.uFlags = NIF_INFO;
nid.uTimeout = 30000;
nid.dwInfoFlags = NIIF_USER;
wcsncpy_s(nid.szInfoTitle, title, _TRUNCATE);
wcsncpy_s(nid.szInfo, text, _TRUNCATE);
nid.dwInfoFlags |= NIIF_LARGE_ICON;
nid.hBalloonIcon = GetIcon(IDI_RAINMETER, true);
if (Shell_NotifyIcon(NIM_MODIFY, &nid))
{
m_Notification = id;
}
}
}
void TrayIcon::ShowWelcomeNotification()
{
ShowNotification(TRAY_NOTIFICATION_WELCOME, GetString(ID_STR_WELCOME), GetString(ID_STR_CLICKTOMANAGE));
}
void TrayIcon::ShowUpdateNotification(LPCWSTR newVersion)
{
std::wstring text = GetFormattedString(ID_STR_CLICKTODOWNLOAD, newVersion);
ShowNotification(TRAY_NOTIFICATION_UPDATE, GetString(ID_STR_UPDATEAVAILABLE), text.c_str());
}
void TrayIcon::ShowInstallUpdateNotification(LPCWSTR newVersion)
{
std::wstring text = GetFormattedString(ID_STR_CLICK_TO_INSTALL, newVersion);
ShowNotification(TRAY_NOTIFICATION_INSTALL_UPDATE, GetString(ID_STR_INSTALL_NEW_VERSION), text.c_str());
}
void TrayIcon::SetTrayIcon(bool enabled, bool setTemporarily)
{
enabled ? TryAddTrayIcon() : RemoveTrayIcon();
// The tray icon should only be set if TrayIcon=1 in
// Rainmeter.ini, or if there are no skins currently active.
if (!setTemporarily)
{
m_IconEnabled = enabled;
// Save to Rainmeter.ini.
const std::wstring& iniFile = GetRainmeter().GetIniFile();
WritePrivateProfileString(L"Rainmeter", L"TrayIcon", enabled ? nullptr : L"0", iniFile.c_str());
}
}
void TrayIcon::ReadOptions(ConfigParser& parser)
{
// Clear old Settings
KillTimer(m_Window, TIMER_ADDTRAYICON);
KillTimer(m_Window, TIMER_TRAYMEASURE);
delete m_Measure;
m_Measure = nullptr;
delete m_Bitmap;
m_Bitmap = nullptr;
std::vector<HICON>::const_iterator iter = m_Icons.begin();
for ( ; iter != m_Icons.end(); ++iter)
{
DestroyIcon((*iter));
}
m_Icons.clear();
m_MeterType = TRAY_METER_TYPE_NONE;
// Read tray settings
m_IconEnabled = parser.ReadBool(L"Rainmeter", L"TrayIcon", true);
if (m_IconEnabled)
{
const std::wstring& measureName = parser.ReadString(L"TrayMeasure", L"Measure", L"");
if (!measureName.empty())
{
ConfigParser* oldParser = GetRainmeter().GetCurrentParser();
GetRainmeter().SetCurrentParser(&parser);
m_Measure = Measure::Create(measureName.c_str(), nullptr, L"TrayMeasure");
if (m_Measure)
{
m_Measure->ReadOptions(parser);
}
GetRainmeter().SetCurrentParser(oldParser);
}
const WCHAR* type = parser.ReadString(L"TrayMeasure", L"TrayMeter", m_Measure ? L"HISTOGRAM" : L"NONE").c_str();
if (_wcsicmp(type, L"NONE") == 0)
{
// Use main icon
}
else if (_wcsicmp(type, L"HISTOGRAM") == 0)
{
m_MeterType = TRAY_METER_TYPE_HISTOGRAM;
auto toARGB = [](const D2D1_COLOR_F& color)
{
return Gdiplus::Color::MakeARGB((BYTE)(255 * color.a), (BYTE)(255 * color.r), (BYTE)(255 * color.g), (BYTE)(255 * color.b));
};
m_Color1 = toARGB(parser.ReadColor(L"TrayMeasure", L"TrayColor1", D2D1::ColorF(0.0f, 100.0f / 255.0f, 0.0f, 1.0f)));
m_Color2 = toARGB(parser.ReadColor(L"TrayMeasure", L"TrayColor2", D2D1::ColorF(0.0f, 1.0f, 0.0f, 1.0f) ));
}
else if (_wcsicmp(type, L"BITMAP") == 0)
{
m_MeterType = TRAY_METER_TYPE_BITMAP;
std::wstring imageName = parser.ReadString(L"TrayMeasure", L"TrayBitmap", L"");
// Load the bitmaps if defined
if (!imageName.empty())
{
imageName.insert(0, GetRainmeter().GetSkinPath());
const WCHAR* imagePath = imageName.c_str();
if (_wcsicmp(imagePath + (imageName.size() - 4), L".ico") == 0)
{
int count = 1;
HICON hIcon = nullptr;
// Load the icons
do
{
WCHAR buffer[MAX_PATH];
_snwprintf_s(buffer, _TRUNCATE, imagePath, count++);
hIcon = (HICON)LoadImage(nullptr, buffer, IMAGE_ICON, TRAYICON_SIZE, TRAYICON_SIZE, LR_LOADFROMFILE);
if (hIcon) m_Icons.push_back(hIcon);
if (wcscmp(imagePath, buffer) == 0) break;
}
while (hIcon != nullptr);
}
if (m_Icons.empty())
{
// No icons found so load as bitmap
delete m_Bitmap;
m_Bitmap = new Bitmap(imagePath);
Status status = m_Bitmap->GetLastStatus();
if (Ok != status)
{
delete m_Bitmap;
m_Bitmap = nullptr;
LogWarningF(L"Bitmap image not found: %s", imagePath);
}
}
}
}
else
{
LogErrorF(L"No such TrayMeter: %s", type);
}
TryAddTrayIcon();
if (m_Measure)
{
SetTimer(m_Window, TIMER_TRAYMEASURE, INTERVAL_TRAYMEASURE, nullptr); // Update the tray once per sec
}
}
else
{
RemoveTrayIcon();
}
}
LRESULT CALLBACK TrayIcon::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TrayIcon* tray = GetRainmeter().GetTrayIcon();
// When in non-layout enabled "Game mode", only process
// the toggling of game mode and exit.
if (GetGameMode().IsEnabled())
{
switch (uMsg)
{
case WM_COMMAND:
switch (wParam)
{
case IDM_GAMEMODE_STOP:
GetGameMode().ChangeStateManual(true);
break;
case IDM_QUIT:
PostQuitMessage(0);
break;
}
break;
case WM_TRAY_NOTIFYICON:
{
UINT uMouseMsg = (UINT)lParam;
switch (uMouseMsg)
{
case WM_RBUTTONDOWN:
tray->m_TrayContextMenuEnabled = true;
break;
case WM_RBUTTONUP:
if (tray->m_TrayContextMenuEnabled)
{
POINT pos = System::GetCursorPosition();
GetRainmeter().ShowContextMenu(pos, nullptr);
}
break;
}
}
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
switch (uMsg)
{
case WM_COMMAND:
switch (wParam)
{
case IDM_MANAGE:
DialogManage::Open();
break;
case IDM_ABOUT:
DialogAbout::Open();
break;
case IDM_SHOW_HELP:
CommandHandler::RunFile(RAINMETER_HELP);
break;
case IDM_NEW_VERSION:
CommandHandler::RunFile(RAINMETER_OFFICIAL);
break;
case IDM_INSTALL_NEW_VERSION:
GetRainmeter().RestartRainmeter();
break;
case IDM_LANGUAGEOBSOLETE:
CommandHandler::RunFile(RAINMETER_LOCALIZATION);
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:
GetLogger().StartLogFile();
break;
case IDM_STOPLOG:
GetLogger().StopLogFile();
break;
case IDM_DELETELOGFILE:
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:
PostQuitMessage(0);
break;
case IDM_OPENSKINSFOLDER:
GetRainmeter().OpenSkinFolder();
break;
case IDM_GAMEMODE_START:
GetGameMode().ChangeStateManual(false);
break;
case IDM_GAMEMODE_STOP:
GetGameMode().ChangeStateManual(true);
break;
case IDM_GAMEMODE_FULLSCREEN:
GetGameMode().SetFullScreenMode(!GetGameMode().GetFullScreenMode());
break;
case IDM_GAMEMODE_PROCESSLIST:
GetGameMode().SetProcessListMode(!GetGameMode().GetProcessListMode());
break;
default:
{
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 if (mID >= ID_GAMEMODE_ONSTART_FIRST && mID <= ID_GAMEMODE_ONSTART_LAST)
{
UINT index = mID - ID_GAMEMODE_ONSTART_FIRST;
GetGameMode().SetOnStartAction(index);
}
else if (mID >= ID_GAMEMODE_ONSTOP_FIRST && mID <= ID_GAMEMODE_ONSTOP_LAST)
{
UINT index = mID - ID_GAMEMODE_ONSTOP_FIRST;
GetGameMode().SetOnStopAction(index);
}
else
{
// Forward the message to correct window
int index = (int)(wParam >> 16);
const std::map<std::wstring, Skin*>& windows = GetRainmeter().GetAllSkins();
if (index < (int)windows.size())
{
std::map<std::wstring, Skin*>::const_iterator iter = windows.begin();
for ( ; iter != windows.end(); ++iter)
{
--index;
if (index < 0)
{
Skin* skin = (*iter).second;
SendMessage(skin->GetWindow(), WM_COMMAND, mID, 0);
break;
}
}
}
}
}
break;
}
break; // Don't send WM_COMMANDS any further
case WM_TRAY_NOTIFYICON:
{
UINT uMouseMsg = (UINT)lParam;
LPCWSTR bang;
// Check TrayExecute actions
switch (uMouseMsg)
{
case WM_MBUTTONDOWN:
bang = GetRainmeter().GetTrayExecuteM().c_str();
break;
case WM_RBUTTONDOWN:
bang = GetRainmeter().GetTrayExecuteR().c_str();
break;
case WM_MBUTTONDBLCLK:
bang = GetRainmeter().GetTrayExecuteDM().c_str();
break;
case WM_RBUTTONDBLCLK:
bang = GetRainmeter().GetTrayExecuteDR().c_str();
break;
default:
bang = L"";
break;
}
if (*bang &&
!IsCtrlKeyDown()) // Ctrl is pressed, so only run default action
{
GetRainmeter().ExecuteCommand(bang, nullptr);
tray->m_TrayContextMenuEnabled = (uMouseMsg != WM_RBUTTONDOWN);
break;
}
// Run default UI action
switch (uMouseMsg)
{
case WM_RBUTTONDOWN:
tray->m_TrayContextMenuEnabled = true;
break;
case WM_RBUTTONUP:
if (tray->m_TrayContextMenuEnabled)
{
POINT pos = System::GetCursorPosition();
GetRainmeter().ShowContextMenu(pos, nullptr);
}
break;
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
DialogManage::Open();
break;
case NIN_BALLOONUSERCLICK:
if (tray->m_Notification == TRAY_NOTIFICATION_WELCOME)
{
DialogManage::Open();
}
else if (tray->m_Notification == TRAY_NOTIFICATION_UPDATE)
{
CommandHandler::RunFile(RAINMETER_OFFICIAL);
}
else if (tray->m_Notification == TRAY_NOTIFICATION_INSTALL_UPDATE)
{
GetRainmeter().RestartRainmeter();
}
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;
case NIN_BALLOONHIDE:
case NIN_BALLOONTIMEOUT:
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;
}
}
break;
case WM_QUERY_RAINMETER:
if (IsWindow((HWND)lParam))
{
auto sendCopyData = [&](const std::wstring& data)
{
COPYDATASTRUCT cds = { 0 };
cds.dwData = wParam;
cds.cbData = (DWORD)((data.length() + 1) * sizeof(WCHAR));
cds.lpData = (PVOID)data.c_str();
SendMessage((HWND)lParam, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds);
};
switch (wParam)
{
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:
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:
{
COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
if (cds->dwData == RAINMETER_QUERY_ID_SKIN_WINDOWHANDLE)
{
LPCWSTR folderPath = (LPCWSTR)cds->lpData;
Skin* skin = GetRainmeter().GetSkin(folderPath);
return (skin) ? (LRESULT)skin->GetWindow() : 0;
}
}
return 1;
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)
{
tray->CheckTrayIcon();
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
if (uMsg == WM_TASKBARCREATED)
{
if (tray->IsTrayIconEnabled())
{
tray->RemoveTrayIcon();
tray->TryAddTrayIcon();
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}