forked from winsiderss/systeminformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysinfo.c
More file actions
2058 lines (1760 loc) · 57 KB
/
Copy pathsysinfo.c
File metadata and controls
2058 lines (1760 loc) · 57 KB
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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Process Hacker -
* System Information window
*
* Copyright (C) 2011-2016 wj32
* Copyright (C) 2017 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker 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 3 of the License, or
* (at your option) any later version.
*
* Process Hacker 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 Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* This file contains the System Information framework. The "framework" handles creation, layout and
* events for the top-level window itself. It manages the list of sections.
*
* A section is an object that provides information to the user about a type of system resource. The
* CPU, Memory and I/O sections are added automatically to every System Information window. Plugins
* can also add sections to the window. There are two views: summary and section. In summary view,
* rows of graphs are displayed in the window, one graph for each section. The section is
* responsible for providing the graph data and any text to draw on the left-hand side of the graph.
* In section view, the graphs become mini-graphs on the left-hand side of the window. The section
* displays its own embedded dialog in the remaining space. Any controls contained in this dialog,
* including graphs, are the responsibility of the section.
*
* Users can enter section view by:
* * Clicking on a graph or mini-graph.
* * Pressing a number from 1 to 9.
* * Using the tab or arrow keys to select a graph and pressing space or enter.
*
* Users can return to summary view by:
* * Clicking "Back" on the left-hand side of the window.
* * Pressing Backspace.
* * Using the tab or arrow keys to select "Back" and pressing space or enter.
*/
#include <phapp.h>
#include <settings.h>
#include <sysinfo.h>
#include <sysinfop.h>
#include <uxtheme.h>
#include <vssym32.h>
#include <windowsx.h>
#include <mainwnd.h>
#include <phplug.h>
#include <phsettings.h>
#include <procprv.h>
static HANDLE PhSipThread = NULL;
HWND PhSipWindow = NULL;
static PPH_LIST PhSipDialogList = NULL;
static PH_EVENT InitializedEvent = PH_EVENT_INIT;
static PWSTR InitialSectionName;
static PH_LAYOUT_MANAGER WindowLayoutManager;
static RECT MinimumSize;
static PH_CALLBACK_REGISTRATION ProcessesUpdatedRegistration;
static PPH_LIST SectionList;
static PH_SYSINFO_PARAMETERS CurrentParameters;
static PH_SYSINFO_VIEW_TYPE CurrentView;
static PPH_SYSINFO_SECTION CurrentSection;
static HWND ContainerControl;
static HWND SeparatorControl;
static HWND RestoreSummaryControl;
static BOOLEAN RestoreSummaryControlHot;
static BOOLEAN RestoreSummaryControlHasFocus;
static HTHEME ThemeData;
static BOOLEAN ThemeHasItemBackground;
static BOOLEAN AlwaysOnTop;
VOID PhShowSystemInformationDialog(
_In_opt_ PWSTR SectionName
)
{
InitialSectionName = SectionName;
if (!PhSipWindow)
{
if (!(PhSipThread = PhCreateThread(0, PhSipSysInfoThreadStart, NULL)))
{
PhShowStatus(PhMainWndHandle, L"Unable to create the system information window", 0, GetLastError());
return;
}
PhWaitForEvent(&InitializedEvent, NULL);
}
SendMessage(PhSipWindow, SI_MSG_SYSINFO_ACTIVATE, (WPARAM)SectionName, 0);
}
NTSTATUS PhSipSysInfoThreadStart(
_In_ PVOID Parameter
)
{
PH_AUTO_POOL autoPool;
BOOL result;
MSG message;
HACCEL acceleratorTable;
BOOLEAN processed;
PhInitializeAutoPool(&autoPool);
PhSipWindow = CreateDialog(
PhInstanceHandle,
MAKEINTRESOURCE(IDD_SYSINFO),
NULL,
PhSipSysInfoDialogProc
);
PhSetEvent(&InitializedEvent);
acceleratorTable = LoadAccelerators(PhInstanceHandle, MAKEINTRESOURCE(IDR_SYSINFO_ACCEL));
while (result = GetMessage(&message, NULL, 0, 0))
{
if (result == -1)
break;
processed = FALSE;
if (
message.hwnd == PhSipWindow ||
IsChild(PhSipWindow, message.hwnd)
)
{
if (TranslateAccelerator(PhSipWindow, acceleratorTable, &message))
processed = TRUE;
}
if (!processed && PhSipDialogList)
{
ULONG i;
for (i = 0; i < PhSipDialogList->Count; i++)
{
if (IsDialogMessage((HWND)PhSipDialogList->Items[i], &message))
{
processed = TRUE;
break;
}
}
}
if (!processed)
{
if (!IsDialogMessage(PhSipWindow, &message))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}
PhDrainAutoPool(&autoPool);
}
PhDeleteAutoPool(&autoPool);
PhResetEvent(&InitializedEvent);
NtClose(PhSipThread);
PhSipWindow = NULL;
PhSipThread = NULL;
if (PhSipDialogList)
{
PhDereferenceObject(PhSipDialogList);
PhSipDialogList = NULL;
}
return STATUS_SUCCESS;
}
INT_PTR CALLBACK PhSipSysInfoDialogProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
PhSipWindow = hwndDlg;
PhSipOnInitDialog();
}
break;
case WM_DESTROY:
{
PhSipOnDestroy();
}
break;
case WM_NCDESTROY:
{
PhSipOnNcDestroy();
}
break;
case WM_SHOWWINDOW:
{
PhSipOnShowWindow(!!wParam, (ULONG)lParam);
}
break;
case WM_SYSCOMMAND:
{
if (PhSipOnSysCommand((ULONG)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)))
return 0;
}
break;
case WM_SIZE:
{
PhSipOnSize();
}
break;
case WM_SIZING:
{
PhSipOnSizing((ULONG)wParam, (PRECT)lParam);
}
break;
case WM_THEMECHANGED:
{
PhSipOnThemeChanged();
}
break;
case WM_COMMAND:
{
PhSipOnCommand(LOWORD(wParam), HIWORD(wParam));
}
break;
case WM_NOTIFY:
{
LRESULT result;
if (PhSipOnNotify((NMHDR *)lParam, &result))
{
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, result);
return TRUE;
}
}
break;
case WM_DRAWITEM:
{
if (PhSipOnDrawItem(wParam, (DRAWITEMSTRUCT *)lParam))
return TRUE;
}
break;
}
if (uMsg >= SI_MSG_SYSINFO_FIRST && uMsg <= SI_MSG_SYSINFO_LAST)
{
PhSipOnUserMessage(uMsg, wParam, lParam);
}
return FALSE;
}
INT_PTR CALLBACK PhSipContainerDialogProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
return FALSE;
}
VOID PhSipOnInitDialog(
VOID
)
{
SendMessage(PhSipWindow, WM_SETICON, ICON_SMALL, (LPARAM)PH_LOAD_SHARED_ICON_SMALL(PhInstanceHandle, MAKEINTRESOURCE(IDI_PROCESSHACKER)));
SendMessage(PhSipWindow, WM_SETICON, ICON_BIG, (LPARAM)PH_LOAD_SHARED_ICON_LARGE(PhInstanceHandle, MAKEINTRESOURCE(IDI_PROCESSHACKER)));
PhInitializeLayoutManager(&WindowLayoutManager, PhSipWindow);
PhAddLayoutItem(&WindowLayoutManager, GetDlgItem(PhSipWindow, IDC_INSTRUCTION), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_BOTTOM);
PhAddLayoutItem(&WindowLayoutManager, GetDlgItem(PhSipWindow, IDC_ALWAYSONTOP), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
PhAddLayoutItem(&WindowLayoutManager, GetDlgItem(PhSipWindow, IDOK), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
PhRegisterCallback(
&PhProcessesUpdatedEvent,
PhSipSysInfoUpdateHandler,
NULL,
&ProcessesUpdatedRegistration
);
ContainerControl = CreateDialog(
PhInstanceHandle,
MAKEINTRESOURCE(IDD_CONTAINER),
PhSipWindow,
PhSipContainerDialogProc
);
PhSetControlTheme(PhSipWindow, L"explorer");
PhSipUpdateThemeData();
}
VOID PhSipOnDestroy(
VOID
)
{
PhUnregisterCallback(
&PhProcessesUpdatedEvent,
&ProcessesUpdatedRegistration
);
if (CurrentSection)
PhSetStringSetting2(L"SysInfoWindowSection", &CurrentSection->Name);
else
PhSetStringSetting(L"SysInfoWindowSection", L"");
PhSetIntegerSetting(L"SysInfoWindowAlwaysOnTop", AlwaysOnTop);
PhSaveWindowPlacementToSetting(L"SysInfoWindowPosition", L"SysInfoWindowSize", PhSipWindow);
PhSipSaveWindowState();
}
VOID PhSipOnNcDestroy(
VOID
)
{
ULONG i;
PPH_SYSINFO_SECTION section;
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
PhSipDestroySection(section);
}
PhDereferenceObject(SectionList);
SectionList = NULL;
PhSipDeleteParameters();
if (ThemeData)
{
CloseThemeData(ThemeData);
ThemeData = NULL;
}
PhDeleteLayoutManager(&WindowLayoutManager);
PostQuitMessage(0);
}
VOID PhSipOnShowWindow(
_In_ BOOLEAN Showing,
_In_ ULONG State
)
{
RECT buttonRect;
RECT clientRect;
PH_STRINGREF sectionName;
PPH_SYSINFO_SECTION section;
if (SectionList)
return;
SectionList = PhCreateList(8);
PhSipInitializeParameters();
CurrentView = SysInfoSummaryView;
CurrentSection = NULL;
PhSipCreateInternalSection(L"CPU", 0, PhSipCpuSectionCallback);
PhSipCreateInternalSection(L"Memory", 0, PhSipMemorySectionCallback);
PhSipCreateInternalSection(L"I/O", 0, PhSipIoSectionCallback);
if (PhPluginsEnabled)
{
PH_PLUGIN_SYSINFO_POINTERS pointers;
pointers.WindowHandle = PhSipWindow;
pointers.CreateSection = PhSipCreateSection;
pointers.FindSection = PhSipFindSection;
pointers.EnterSectionView = PhSipEnterSectionView;
pointers.RestoreSummaryView = PhSipRestoreSummaryView;
PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackSystemInformationInitializing), &pointers);
}
SeparatorControl = CreateWindow(
L"STATIC",
NULL,
WS_CHILD | SS_OWNERDRAW,
0,
0,
3,
3,
PhSipWindow,
(HMENU)IDC_SEPARATOR,
PhInstanceHandle,
NULL
);
RestoreSummaryControl = CreateWindow(
L"STATIC",
NULL,
WS_CHILD | WS_TABSTOP | SS_OWNERDRAW | SS_NOTIFY,
0,
0,
3,
3,
PhSipWindow,
(HMENU)IDC_RESET,
PhInstanceHandle,
NULL
);
SetWindowSubclass(RestoreSummaryControl, PhSipPanelHookWndProc, 0, 0);
RestoreSummaryControlHot = FALSE;
EnableThemeDialogTexture(ContainerControl, ETDT_ENABLETAB);
GetWindowRect(GetDlgItem(PhSipWindow, IDOK), &buttonRect);
MapWindowPoints(NULL, PhSipWindow, (POINT *)&buttonRect, 2);
GetClientRect(PhSipWindow, &clientRect);
MinimumSize.left = 0;
MinimumSize.top = 0;
MinimumSize.right = 430;
MinimumSize.bottom = 290;
MapDialogRect(PhSipWindow, &MinimumSize);
MinimumSize.right += CurrentParameters.PanelWidth;
MinimumSize.right += GetSystemMetrics(SM_CXFRAME) * 2;
MinimumSize.bottom += GetSystemMetrics(SM_CYFRAME) * 2;
if (SectionList->Count != 0)
{
ULONG newMinimumHeight;
newMinimumHeight =
GetSystemMetrics(SM_CYCAPTION) +
CurrentParameters.WindowPadding +
CurrentParameters.MinimumGraphHeight * SectionList->Count +
CurrentParameters.MinimumGraphHeight + // Back button
CurrentParameters.GraphPadding * SectionList->Count +
CurrentParameters.WindowPadding +
clientRect.bottom - buttonRect.top +
GetSystemMetrics(SM_CYFRAME) * 2;
if (newMinimumHeight > (ULONG)MinimumSize.bottom)
MinimumSize.bottom = newMinimumHeight;
}
PhLoadWindowPlacementFromSetting(L"SysInfoWindowPosition", L"SysInfoWindowSize", PhSipWindow);
if (PhGetIntegerSetting(L"SysInfoWindowState") == SW_MAXIMIZE)
ShowWindow(PhSipWindow, SW_MAXIMIZE);
if (InitialSectionName)
PhInitializeStringRefLongHint(§ionName, InitialSectionName);
else
sectionName = PhaGetStringSetting(L"SysInfoWindowSection")->sr;
if (sectionName.Length != 0 && (section = PhSipFindSection(§ionName)))
{
PhSipEnterSectionView(section);
}
AlwaysOnTop = (BOOLEAN)PhGetIntegerSetting(L"SysInfoWindowAlwaysOnTop");
Button_SetCheck(GetDlgItem(PhSipWindow, IDC_ALWAYSONTOP), AlwaysOnTop ? BST_CHECKED : BST_UNCHECKED);
PhSipSetAlwaysOnTop();
PhSipOnSize();
PhSipOnUserMessage(SI_MSG_SYSINFO_UPDATE, 0, 0);
}
BOOLEAN PhSipOnSysCommand(
_In_ ULONG Type,
_In_ LONG CursorScreenX,
_In_ LONG CursorScreenY
)
{
switch (Type)
{
case SC_MINIMIZE:
{
// Save the current window state because we may not have a chance to later.
PhSipSaveWindowState();
}
break;
}
return FALSE;
}
VOID PhSipOnSize(
VOID
)
{
PhLayoutManagerLayout(&WindowLayoutManager);
if (SectionList && SectionList->Count != 0)
{
if (CurrentView == SysInfoSummaryView)
PhSipLayoutSummaryView();
else if (CurrentView == SysInfoSectionView)
PhSipLayoutSectionView();
}
}
VOID PhSipOnSizing(
_In_ ULONG Edge,
_In_ PRECT DragRectangle
)
{
PhResizingMinimumSize(DragRectangle, Edge, MinimumSize.right, MinimumSize.bottom);
}
VOID PhSipOnThemeChanged(
VOID
)
{
PhSipUpdateThemeData();
}
VOID PhSipOnCommand(
_In_ ULONG Id,
_In_ ULONG Code
)
{
switch (Id)
{
case IDCANCEL:
case IDOK:
DestroyWindow(PhSipWindow);
break;
case IDC_ALWAYSONTOP:
{
AlwaysOnTop = Button_GetCheck(GetDlgItem(PhSipWindow, IDC_ALWAYSONTOP)) == BST_CHECKED;
PhSipSetAlwaysOnTop();
}
break;
case IDC_RESET:
{
if (Code == STN_CLICKED)
{
PhSipRestoreSummaryView();
}
}
break;
case IDC_BACK:
{
PhSipRestoreSummaryView();
}
break;
case IDC_REFRESH:
{
ProcessHacker_Refresh(PhMainWndHandle);
}
break;
case IDC_PAUSE:
{
ProcessHacker_SetUpdateAutomatically(PhMainWndHandle, !ProcessHacker_GetUpdateAutomatically(PhMainWndHandle));
}
break;
case IDC_MAXSCREEN:
{
static WINDOWPLACEMENT windowLayout = { sizeof(WINDOWPLACEMENT) };
ULONG windowStyle = (ULONG)GetWindowLongPtr(PhSipWindow, GWL_STYLE);
if (windowStyle & WS_OVERLAPPEDWINDOW)
{
MONITORINFO info = { sizeof(MONITORINFO) };
if (
GetWindowPlacement(PhSipWindow, &windowLayout) &&
GetMonitorInfo(MonitorFromWindow(PhSipWindow, MONITOR_DEFAULTTOPRIMARY), &info)
)
{
ULONG padding = CurrentParameters.WindowPadding / 2;
PhSetWindowStyle(PhSipWindow, WS_OVERLAPPEDWINDOW, 0);
SetWindowPos(
PhSipWindow,
HWND_TOPMOST,
info.rcMonitor.left - padding,
info.rcMonitor.top - padding,
(info.rcMonitor.right - info.rcMonitor.left) + padding * 2,
(info.rcMonitor.bottom - info.rcMonitor.top) + padding * 2,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED
);
}
}
else
{
PhSetWindowStyle(PhSipWindow, WS_OVERLAPPEDWINDOW, WS_OVERLAPPEDWINDOW);
SetWindowPlacement(PhSipWindow, &windowLayout);
SetWindowPos(PhSipWindow, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
}
break;
}
if (SectionList && Id >= ID_DIGIT1 && Id <= ID_DIGIT9)
{
ULONG index;
index = Id - ID_DIGIT1;
if (index < SectionList->Count)
PhSipEnterSectionView(SectionList->Items[index]);
}
if (SectionList && Code == STN_CLICKED)
{
ULONG i;
PPH_SYSINFO_SECTION section;
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
if (Id == section->PanelId)
{
PhSipEnterSectionView(section);
break;
}
}
}
}
BOOLEAN PhSipOnNotify(
_In_ NMHDR *Header,
_Out_ LRESULT *Result
)
{
switch (Header->code)
{
case GCN_GETDRAWINFO:
{
PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header;
PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;
ULONG i;
PPH_SYSINFO_SECTION section;
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
if (getDrawInfo->Header.hwndFrom == section->GraphHandle)
{
section->Callback(section, SysInfoGraphGetDrawInfo, drawInfo, 0);
if (CurrentView == SysInfoSectionView)
{
drawInfo->Flags &= ~(PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y);
}
else
{
ULONG badWidth = CurrentParameters.PanelWidth;
// Try not to draw max data point labels that will get covered by the
// fade-out part of the graph.
if (badWidth < drawInfo->Width)
drawInfo->LabelMaxYIndexLimit = (drawInfo->Width - badWidth) / 2;
else
drawInfo->LabelMaxYIndexLimit = -1;
}
break;
}
}
}
break;
case GCN_GETTOOLTIPTEXT:
{
PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header;
ULONG i;
PPH_SYSINFO_SECTION section;
if (getTooltipText->Index < getTooltipText->TotalCount)
{
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
if (getTooltipText->Header.hwndFrom == section->GraphHandle)
{
PH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT graphGetTooltipText;
graphGetTooltipText.Index = getTooltipText->Index;
PhInitializeEmptyStringRef(&graphGetTooltipText.Text);
section->Callback(section, SysInfoGraphGetTooltipText, &graphGetTooltipText, 0);
getTooltipText->Text = graphGetTooltipText.Text;
break;
}
}
}
}
break;
case GCN_DRAWPANEL:
{
PPH_GRAPH_DRAWPANEL drawPanel = (PPH_GRAPH_DRAWPANEL)Header;
ULONG i;
PPH_SYSINFO_SECTION section;
if (CurrentView == SysInfoSummaryView)
{
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
if (drawPanel->Header.hwndFrom == section->GraphHandle)
{
PhSipDrawPanel(section, drawPanel->hdc, &drawPanel->Rect);
break;
}
}
}
}
break;
case GCN_MOUSEEVENT:
{
PPH_GRAPH_MOUSEEVENT mouseEvent = (PPH_GRAPH_MOUSEEVENT)Header;
ULONG i;
PPH_SYSINFO_SECTION section;
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
if (mouseEvent->Header.hwndFrom == section->GraphHandle)
{
if (mouseEvent->Message == WM_LBUTTONDOWN)
{
PhSipEnterSectionView(section);
}
break;
}
}
}
break;
}
return FALSE;
}
BOOLEAN PhSipOnDrawItem(
_In_ ULONG_PTR Id,
_In_ DRAWITEMSTRUCT *DrawItemStruct
)
{
ULONG i;
PPH_SYSINFO_SECTION section;
if (Id == IDC_RESET)
{
PhSipDrawRestoreSummaryPanel(DrawItemStruct->hDC, &DrawItemStruct->rcItem);
return TRUE;
}
else if (Id == IDC_SEPARATOR)
{
PhSipDrawSeparator(DrawItemStruct->hDC, &DrawItemStruct->rcItem);
return TRUE;
}
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
if (Id == section->PanelId)
{
PhSipDrawPanel(section, DrawItemStruct->hDC, &DrawItemStruct->rcItem);
return TRUE;
}
}
return FALSE;
}
VOID PhSipOnUserMessage(
_In_ ULONG Message,
_In_ ULONG_PTR WParam,
_In_ ULONG_PTR LParam
)
{
switch (Message)
{
case SI_MSG_SYSINFO_ACTIVATE:
{
PWSTR sectionName = (PWSTR)WParam;
if (SectionList && sectionName)
{
PH_STRINGREF sectionNameSr;
PPH_SYSINFO_SECTION section;
PhInitializeStringRefLongHint(§ionNameSr, sectionName);
section = PhSipFindSection(§ionNameSr);
if (section)
PhSipEnterSectionView(section);
else
PhSipRestoreSummaryView();
}
if (IsIconic(PhSipWindow))
ShowWindow(PhSipWindow, SW_RESTORE);
else
ShowWindow(PhSipWindow, SW_SHOW);
SetForegroundWindow(PhSipWindow);
}
break;
case SI_MSG_SYSINFO_UPDATE:
{
ULONG i;
PPH_SYSINFO_SECTION section;
if (SectionList)
{
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
section->Callback(section, SysInfoTick, NULL, NULL);
section->GraphState.Valid = FALSE;
section->GraphState.TooltipIndex = -1;
Graph_MoveGrid(section->GraphHandle, 1);
Graph_Draw(section->GraphHandle);
Graph_UpdateTooltip(section->GraphHandle);
InvalidateRect(section->GraphHandle, NULL, FALSE);
InvalidateRect(section->PanelHandle, NULL, FALSE);
}
}
}
break;
case SI_MSG_SYSINFO_CHANGE_SETTINGS:
{
ULONG i;
PPH_SYSINFO_SECTION section;
PH_GRAPH_OPTIONS options;
if (SectionList)
{
for (i = 0; i < SectionList->Count; i++)
{
section = SectionList->Items[i];
Graph_GetOptions(section->GraphHandle, &options);
options.FadeOutBackColor = CurrentParameters.GraphBackColor;
Graph_SetOptions(section->GraphHandle, &options);
}
}
InvalidateRect(PhSipWindow, NULL, TRUE);
}
break;
}
}
VOID PhSiNotifyChangeSettings(
VOID
)
{
HWND window;
PhSipUpdateColorParameters();
window = PhSipWindow;
if (window)
PostMessage(window, SI_MSG_SYSINFO_CHANGE_SETTINGS, 0, 0);
}
VOID PhSiSetColorsGraphDrawInfo(
_Out_ PPH_GRAPH_DRAW_INFO DrawInfo,
_In_ COLORREF Color1,
_In_ COLORREF Color2
)
{
static PH_QUEUED_LOCK lock = PH_QUEUED_LOCK_INIT;
static ULONG lastDpi = -1;
static HFONT iconTitleFont;
// Get the appropriate fonts.
if (DrawInfo->Flags & PH_GRAPH_LABEL_MAX_Y)
{
PhAcquireQueuedLockExclusive(&lock);
if (lastDpi != PhGlobalDpi)
{
LOGFONT logFont;
if (SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &logFont, 0))
{
logFont.lfHeight += PhMultiplyDivide(1, PhGlobalDpi, 72);
iconTitleFont = CreateFontIndirect(&logFont);
}
if (!iconTitleFont)
iconTitleFont = PhApplicationFont;
lastDpi = PhGlobalDpi;
}
DrawInfo->LabelYFont = iconTitleFont;
PhReleaseQueuedLockExclusive(&lock);
}
DrawInfo->TextFont = PhApplicationFont;
// Set up the colors.
switch (PhCsGraphColorMode)
{
case 0: // New colors
DrawInfo->BackColor = RGB(0xef, 0xef, 0xef);
DrawInfo->LineColor1 = PhHalveColorBrightness(Color1);
DrawInfo->LineBackColor1 = PhMakeColorBrighter(Color1, 125);
DrawInfo->LineColor2 = PhHalveColorBrightness(Color2);
DrawInfo->LineBackColor2 = PhMakeColorBrighter(Color2, 125);
DrawInfo->GridColor = RGB(0xc7, 0xc7, 0xc7);
DrawInfo->LabelYColor = RGB(0xa0, 0x60, 0x20);
DrawInfo->TextColor = RGB(0x00, 0x00, 0x00);
DrawInfo->TextBoxColor = RGB(0xe7, 0xe7, 0xe7);
break;
case 1: // Old colors
DrawInfo->BackColor = RGB(0x00, 0x00, 0x00);
DrawInfo->LineColor1 = Color1;
DrawInfo->LineBackColor1 = PhHalveColorBrightness(Color1);
DrawInfo->LineColor2 = Color2;
DrawInfo->LineBackColor2 = PhHalveColorBrightness(Color2);
DrawInfo->GridColor = RGB(0x00, 0x57, 0x00);
DrawInfo->LabelYColor = RGB(0xd0, 0xa0, 0x70);
DrawInfo->TextColor = RGB(0x00, 0xff, 0x00);
DrawInfo->TextBoxColor = RGB(0x00, 0x22, 0x00);
break;
}
}
PPH_STRING PhSiSizeLabelYFunction(
_In_ PPH_GRAPH_DRAW_INFO DrawInfo,
_In_ ULONG DataIndex,
_In_ FLOAT Value,
_In_ FLOAT Parameter
)
{
ULONG64 size;
size = (ULONG64)(Value * Parameter);
if (size != 0)
{
PH_FORMAT format;
format.Type = SizeFormatType | FormatUsePrecision | FormatUseRadix;
format.Precision = 0;
format.Radix = -1;
format.u.Size = size;
return PhFormat(&format, 1, 0);
}
else
{
return PhReferenceEmptyString();
}
}
VOID PhSipRegisterDialog(
_In_ HWND DialogWindowHandle
)
{
if (!PhSipDialogList)
PhSipDialogList = PhCreateList(4);
PhAddItemList(PhSipDialogList, DialogWindowHandle);
}
VOID PhSipUnregisterDialog(
_In_ HWND DialogWindowHandle
)
{
ULONG index;
if ((index = PhFindItemList(PhSipDialogList, DialogWindowHandle)) != -1)
PhRemoveItemList(PhSipDialogList, index);
}
VOID PhSipInitializeParameters(
VOID