-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
3455 lines (2705 loc) · 97.4 KB
/
main.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
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
//+-------------------------------------------------------------------------
//
// TaskMan - NT TaskManager
// Copyright (C) Microsoft
//
// File: Main.CPP
//
// History: Nov-10-95 DavePl Created
//
//--------------------------------------------------------------------------
#include "precomp.h"
static UINT g_msgTaskbarCreated = 0;
static const UINT idTrayIcons[] =
{
IDI_TRAY0, IDI_TRAY1, IDI_TRAY2, IDI_TRAY3, IDI_TRAY4, IDI_TRAY5,
IDI_TRAY6, IDI_TRAY7, IDI_TRAY8, IDI_TRAY9, IDI_TRAY10, IDI_TRAY11
};
HICON g_aTrayIcons[ARRAYSIZE(idTrayIcons)];
UINT g_cTrayIcons = ARRAYSIZE(idTrayIcons);
#define MIN_MEMORY_REQUIRED 8 // If the system has less than 8 megs of memory only load the first two tabs.
//
// Control IDs
//
#define IDC_STATUSWND 100
//
// Globals - this app is (effectively) single threaded and these values
// are used by all pages
//
const WCHAR cszStartupMutex[] = L"NTShell Taskman Startup Mutex";
#define FINDME_TIMEOUT 10000 // Wait to to 10 seconds for a response
typedef BOOLEAN (*PFNSETSUSPENDSTATE)(BOOLEAN, BOOLEAN, BOOLEAN);
void MainWnd_OnSize(HWND hwnd, UINT state, int cx, int cy);
HANDLE g_hStartupMutex = NULL;
BOOL g_fMenuTracking = FALSE;
HWND g_hMainWnd = NULL;
HDESK g_hMainDesktop = NULL;
HWND g_hStatusWnd = NULL;
HINSTANCE g_hInstance = NULL;
HACCEL g_hAccel = NULL;
BYTE g_cProcessors = (BYTE) 0;
HMENU g_hMenu = NULL;
BOOL g_fCantHide = FALSE;
BOOL g_fInPopup = FALSE;
DWORD g_idTrayThread = 0;
HANDLE g_hTrayThread = NULL;
LONG g_minWidth = 0;
LONG g_minHeight = 0;
LONG g_DefSpacing = 0;
LONG g_InnerSpacing = 0;
LONG g_TopSpacing = 0;
LONG g_cxEdge = 0;
LONG g_ControlWidthSpacing = 0;
LONG g_ControlHeightSpacing = 0;
HRGN g_hrgnView = NULL;
HRGN g_hrgnClip = NULL;
HBRUSH g_hbrWindow = NULL;
COptions g_Options;
static BOOL fAlreadySetPos = FALSE;
BOOL g_bMirroredOS = FALSE;
//
// Global strings - short strings used too often to be LoadString'd
// every time
//
WCHAR g_szRealtime [SHORTSTRLEN];
WCHAR g_szNormal [SHORTSTRLEN];
WCHAR g_szHigh [SHORTSTRLEN];
WCHAR g_szLow [SHORTSTRLEN];
WCHAR g_szUnknown [SHORTSTRLEN];
WCHAR g_szAboveNormal [SHORTSTRLEN];
WCHAR g_szBelowNormal [SHORTSTRLEN];
WCHAR g_szHung [SHORTSTRLEN];
WCHAR g_szRunning [SHORTSTRLEN];
WCHAR g_szfmtTasks [SHORTSTRLEN];
WCHAR g_szfmtProcs [SHORTSTRLEN];
WCHAR g_szfmtCPU [SHORTSTRLEN];
WCHAR g_szfmtMEM [SHORTSTRLEN];
WCHAR g_szfmtMEMM [SHORTSTRLEN];
WCHAR g_szfmtCPUNum [SHORTSTRLEN];
WCHAR g_szTotalCPU [SHORTSTRLEN];
WCHAR g_szKernelCPU [SHORTSTRLEN];
WCHAR g_szMemUsage [SHORTSTRLEN];
WCHAR g_szBytes [SHORTSTRLEN];
WCHAR g_szPackets [SHORTSTRLEN];
WCHAR g_szBitsPerSec [SHORTSTRLEN];
WCHAR g_szScaleFont [SHORTSTRLEN];
WCHAR g_szPercent [SHORTSTRLEN];
WCHAR g_szZero [SHORTSTRLEN];
WCHAR g_szNonOperational [SHORTSTRLEN];
WCHAR g_szUnreachable [SHORTSTRLEN];
WCHAR g_szDisconnected [SHORTSTRLEN];
WCHAR g_szConnecting [SHORTSTRLEN];
WCHAR g_szConnected [SHORTSTRLEN];
WCHAR g_szOperational [SHORTSTRLEN];
WCHAR g_szUnknownStatus [SHORTSTRLEN];
WCHAR g_szTimeSep [SHORTSTRLEN];
WCHAR g_szGroupThousSep [SHORTSTRLEN];
WCHAR g_szDecimal [SHORTSTRLEN];
ULONG g_ulGroupSep;
WCHAR g_szG[10]; // Localized "G"igabyte symbol
WCHAR g_szM[10]; // Localized "M"egabyte symbol
WCHAR g_szK[10]; // Localized "K"ilobyte symbol
// Page Array
//
// Each of the page objects is delcared here, and g_pPages is an array
// of pointers to those instantiated objects (at global scope). The main
// window code can call through the base members of the CPage class to
// do things like sizing, etc., without worrying about whatever specific
// stuff each page might do
int g_nPageCount = 0;
CPage * g_pPages[NUM_PAGES] = { NULL };
typedef DWORD (WINAPI * PFNCM_REQUEST_EJECT_PC) (void);
PFNCM_REQUEST_EJECT_PC gpfnCM_Request_Eject_PC = NULL;
// Terminal Services
BOOL g_fIsTSEnabled = FALSE;
BOOL g_fIsSingleUserTS = FALSE;
BOOL g_fIsTSServer = FALSE;
DWORD g_dwMySessionId = 0;
/*
Superclass of GROUPBOX
We need to turn on clipchildren for our dialog which contains the
history graphs, so they don't get erased during the repaint cycle.
Unfortunately, group boxes don't erase their backgrounds, so we
have to superclass them and provide a control that does.
This is a lot of extra work, but the painting is several orders of
magnitude nicer with it...
*/
/*++ DavesFrameWndProc
Routine Description:
WndProc for the custom group box class. Primary difference from
standard group box is that this one knows how to erase its own
background, and doesn't rely on the parent to do it for it.
These controls also have CLIPSIBLINGS turn on so as not to stomp
on the ownderdraw graphs they surround.
Arguments:
standard wndproc fare
Revision History:
Nov-29-95 Davepl Created
--*/
WNDPROC oldButtonWndProc = NULL;
LRESULT DavesFrameWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_CREATE)
{
//
// Turn on clipsiblings for the frame
//
DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
dwStyle |= WS_CLIPSIBLINGS;
SetWindowLong(hWnd, GWL_STYLE, dwStyle);
}
else if (msg == WM_ERASEBKGND)
{
return DefWindowProc( hWnd, msg, wParam, lParam );
}
// For anything else, we defer to the standard button class code
return CallWindowProc(oldButtonWndProc, hWnd, msg, wParam, lParam);
}
/*++ COptions::Save
Routine Description:
Saves current options to the registy
Arguments:
Returns:
HRESULT
Revision History:
Jan-01-95 Davepl Created
--*/
const WCHAR szTaskmanKey[] = TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\TaskManager");
const WCHAR szOptionsKey[] = TEXT("Preferences");
HRESULT COptions::Save()
{
DWORD dwDisposition;
HKEY hkSave;
if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER,
szTaskmanKey,
0,
(LPTSTR)TEXT("REG_BINARY"),
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hkSave,
&dwDisposition))
{
return GetLastHRESULT();
}
if (ERROR_SUCCESS != RegSetValueEx(hkSave,
szOptionsKey,
0,
REG_BINARY,
(LPBYTE) this,
sizeof(COptions)))
{
RegCloseKey(hkSave);
return GetLastHRESULT();
}
RegCloseKey(hkSave);
return S_OK;
}
/*++ COptions::Load
Routine Description:
Loads current options to the registy
Arguments:
Returns:
HRESULT
Revision History:
Jan-01-95 Davepl Created
--*/
HRESULT COptions::Load()
{
HKEY hkSave;
// If ctrl-alt-shift is down at startup, "forget" registry settings
if (GetKeyState(VK_SHIFT) < 0 &&
GetKeyState(VK_MENU) < 0 &&
GetKeyState(VK_CONTROL) < 0)
{
SetDefaultValues();
return S_FALSE;
}
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER,
szTaskmanKey,
0,
KEY_READ,
&hkSave))
{
return S_FALSE;
}
DWORD dwType;
DWORD dwSize = sizeof(COptions);
if (ERROR_SUCCESS != RegQueryValueEx(hkSave,
szOptionsKey,
0,
&dwType,
(LPBYTE) this,
&dwSize)
// Validate type and size of options info we got from the registry
|| dwType != REG_BINARY
|| dwSize != sizeof(COptions)
// Validate options, revert to default if any are invalid (like if
// the window would be offscreen)
|| MonitorFromRect(&m_rcWindow, MONITOR_DEFAULTTONULL) == NULL
//number of available pages might be less than NUM_PAGES
|| m_iCurrentPage > g_nPageCount - 1)
{
// Reset to default values
SetDefaultValues();
RegCloseKey(hkSave);
return S_FALSE;
}
RegCloseKey(hkSave);
return S_OK;
}
/*++ COptions::SetDefaultValues
Routine Description:
Used to init the options to a default state when the saved copy
cannot be found, is damaged, or is not the correct version
Arguments:
Returns:
nothing
Revision History:
Dec-06-00 jeffreys Moved from taskmgr.h
--*/
BOOL IsUserAdmin();
// Columns which are visible, by default, in the process view
// i fucking love msvc for making me cast these despite them being
// the exact same type - aubymori
const COLUMNID g_aDefaultCols[] = { (COLUMNID)COL_IMAGENAME, (COLUMNID)COL_USERNAME, (COLUMNID)COL_CPU, (COLUMNID)COL_MEMUSAGE, (COLUMNID)-1 };
const COLUMNID g_aTSCols[] = { (COLUMNID)COL_IMAGENAME, (COLUMNID)COL_USERNAME, (COLUMNID)COL_SESSIONID, (COLUMNID)COL_CPU, (COLUMNID)COL_MEMUSAGE, (COLUMNID)-1 };
const NETCOLUMNID g_aNetDefaultCols[] = { (NETCOLUMNID)COL_ADAPTERNAME, (NETCOLUMNID)COL_NETWORKUTIL, (NETCOLUMNID)COL_LINKSPEED, (NETCOLUMNID)COL_STATE, (NETCOLUMNID)-1 };
void COptions::SetDefaultValues()
{
ZeroMemory(this, sizeof(COptions));
m_cbSize = sizeof(COptions);
BOOL bScreenReader = FALSE;
if (SystemParametersInfo(SPI_GETSCREENREADER, 0, (PVOID) &bScreenReader, 0) && bScreenReader)
{
// No automatic updates for machines with screen readers
m_dwTimerInterval = 0;
}
else
{
m_dwTimerInterval = 1000;
}
m_vmViewMode = VM_DETAILS;
m_cmHistMode = CM_PANES;
m_usUpdateSpeed = US_NORMAL;
m_fMinimizeOnUse = TRUE;
m_fConfirmations = TRUE;
m_fAlwaysOnTop = TRUE;
m_fShow16Bit = TRUE;
m_iCurrentPage = -1;
m_rcWindow.top = 10;
m_rcWindow.left = 10;
m_rcWindow.bottom = 10 + g_minHeight;
m_rcWindow.right = 10 + g_minWidth;
m_bShowAllProcess = (g_fIsTSEnabled && IsUserAdmin());
m_bShutdownMenu = TRUE;
m_mmHistMode = MM_PHYSICAL;
m_bLedNumbers = FALSE;
const COLUMNID *pcol = (g_fIsTSEnabled) ? g_aTSCols : g_aDefaultCols;
for (int i = 0; i < NUM_COLUMN + 1 ; i++, pcol++)
{
m_ActiveProcCol[i] = *pcol;
if ((COLUMNID)-1 == *pcol)
break;
}
// Set all of the columns widths to -1
FillMemory(m_ColumnWidths, sizeof(m_ColumnWidths), 0xFF);
FillMemory(m_ColumnPositions, sizeof(m_ColumnPositions), 0xFF);
// Set the Network default values
//
const NETCOLUMNID *pnetcol = g_aNetDefaultCols;
for (int i = 0; i < NUM_NETCOLUMN + 1 ; i++, pnetcol++)
{
m_ActiveNetCol[i] = *pnetcol;
if ((NETCOLUMNID)-1 == *pnetcol)
break;
}
// Set all of the columns widths to -1
//
FillMemory(m_NetColumnWidths, sizeof(m_NetColumnWidths), 0xFF);
FillMemory(m_NetColumnPositions, sizeof(m_NetColumnPositions), 0xFF);
m_bAutoSize = TRUE;
m_bGraphBytesSent = FALSE;
m_bGraphBytesReceived = FALSE;
m_bGraphBytesTotal = TRUE;
m_bNetShowAll = FALSE;
m_bShowScale = TRUE;
m_bTabAlwaysActive = FALSE;
}
BOOL FPalette(void)
{
HDC hdc = GetDC(NULL);
BOOL fPalette = (GetDeviceCaps(hdc, NUMCOLORS) != -1);
ReleaseDC(NULL, hdc);
return fPalette;
}
/*++ InitDavesControls
Routine Description:
Superclasses GroupBox for better drawing
Note that I'm not very concerned about failure here, since it
something goes wrong the dialog creation will fail awayway, and
it will be handled there
Arguments:
Revision History:
Nov-29-95 Davepl Created
--*/
void InitDavesControls()
{
static const WCHAR szControlName[] = TEXT("DavesFrameClass");
WNDCLASS wndclass;
//
// Get the class info for the Button class (which is what group
// boxes really are) and create a new class based on it
//
if (!GetClassInfo(g_hInstance, TEXT("Button"), &wndclass))
return; // Ungraceful exit, but better than random unit'd lpfnWndProc
oldButtonWndProc = wndclass.lpfnWndProc;
wndclass.hInstance = g_hInstance;
wndclass.lpfnWndProc = DavesFrameWndProc;
wndclass.lpszClassName = szControlName;
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
(ATOM)RegisterClass(&wndclass);
return;
}
/*++ SetTitle
Routine Description:
Sets the app's title in the title bar (we do this on startup and
when coming out of notitle mode).
Arguments:
none
Return Value:
none
Revision History:
Jan-24-95 Davepl Created
--*/
void SetTitle()
{
WCHAR szTitle[MAX_PATH];
LoadString(g_hInstance, IDS_APPTITLE, szTitle, MAX_PATH);
SetWindowText(g_hMainWnd, szTitle);
}
/*++ UpdateMenuStates
Routine Description:
Updates the menu checks / ghosting based on the
current settings and options
Arguments:
Return Value:
Revision History:
Nov-29-95 Davepl Created
--*/
void UpdateMenuStates()
{
HMENU hMenu = GetMenu(g_hMainWnd);
if (hMenu)
{
CheckMenuRadioItem(hMenu, VM_FIRST, VM_LAST, VM_FIRST + (UINT) g_Options.m_vmViewMode, MF_BYCOMMAND);
CheckMenuRadioItem(hMenu, CM_FIRST, CM_LAST, CM_FIRST + (UINT) g_Options.m_cmHistMode, MF_BYCOMMAND);
CheckMenuRadioItem(hMenu, MM_FIRST, MM_LAST, MM_FIRST + (UINT) g_Options.m_mmHistMode, MF_BYCOMMAND);
CheckMenuRadioItem(hMenu, US_FIRST, US_LAST, US_FIRST + (UINT) g_Options.m_usUpdateSpeed, MF_BYCOMMAND);
CheckMenuItem(hMenu, IDM_ALWAYSONTOP, MF_BYCOMMAND | (g_Options.m_fAlwaysOnTop ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_MINIMIZEONUSE, MF_BYCOMMAND | (g_Options.m_fMinimizeOnUse ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_SHOWSHUTDOWN, MF_BYCOMMAND | (g_Options.m_bShutdownMenu ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_LEDNUMBERS, MF_BYCOMMAND | (g_Options.m_bLedNumbers ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_KERNELTIMES, MF_BYCOMMAND | (g_Options.m_fKernelTimes ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_NOTITLE, MF_BYCOMMAND | (g_Options.m_fNoTitle ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_HIDEWHENMIN, MF_BYCOMMAND | (g_Options.m_fHideWhenMin ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_SHOW16BIT, MF_BYCOMMAND | (g_Options.m_fShow16Bit ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_SHOWDOMAINNAMES, MF_BYCOMMAND | (g_Options.m_fShowDomainNames ? MF_CHECKED : MF_UNCHECKED));
// Remove the CPU history style options on single processor machines
if (g_cProcessors < 2)
{
DeleteMenu(hMenu, IDM_ALLCPUS, MF_BYCOMMAND);
}
CheckMenuItem(hMenu,IDM_SHOWSCALE, g_Options.m_bShowScale ? MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_AUTOSIZE, g_Options.m_bAutoSize ? MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_BYTESSENT, g_Options.m_bGraphBytesSent ? MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_BYTESRECEIVED, g_Options.m_bGraphBytesReceived ? MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_BYTESTOTAL, g_Options.m_bGraphBytesTotal ? MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_SHOWALLDATA, g_Options.m_bNetShowAll ? MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_TABALWAYSACTIVE, g_Options.m_bTabAlwaysActive ? MF_CHECKED:MF_UNCHECKED);
}
}
/*++ SizeChildPage
Routine Description:
Size the active child page based on the tab control
Arguments:
hwndMain - Main window
Return Value:
Revision History:
Nov-29-95 Davepl Created
--*/
void SizeChildPage(HWND hwndMain)
{
if (g_Options.m_iCurrentPage >= 0 && g_Options.m_iCurrentPage < g_nPageCount )
{
// If we are in maximum viewing mode, the page gets the whole
// window area
HWND hwndPage = g_pPages[g_Options.m_iCurrentPage]->GetPageWindow();
DWORD dwStyle = GetWindowLong (g_hMainWnd, GWL_STYLE);
if (g_Options.m_fNoTitle)
{
RECT rcMainWnd;
GetClientRect(g_hMainWnd, &rcMainWnd);
SetWindowPos(hwndPage, HWND_TOP, rcMainWnd.left, rcMainWnd.top,
rcMainWnd.right - rcMainWnd.left,
rcMainWnd.bottom - rcMainWnd.top, SWP_NOZORDER | SWP_NOACTIVATE);
// remove caption & menu bar, etc.
dwStyle &= ~(WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
// SetWindowLong (g_hMainWnd, GWL_ID, 0);
SetWindowLong (g_hMainWnd, GWL_STYLE, dwStyle);
SetMenu(g_hMainWnd, NULL);
}
else
{
// If we have a page being displayed, we need to size it also
// put menu bar & caption back in
dwStyle = WS_TILEDWINDOW | dwStyle;
SetWindowLong (g_hMainWnd, GWL_STYLE, dwStyle);
if (g_hMenu)
{
SetMenu(g_hMainWnd, g_hMenu);
UpdateMenuStates();
}
SetTitle();
if (hwndPage)
{
RECT rcCtl;
HWND hwndCtl = GetDlgItem(hwndMain, IDC_TABS);
GetClientRect(hwndCtl, &rcCtl);
MapWindowPoints(hwndCtl, hwndMain, (LPPOINT)&rcCtl, 2);
TabCtrl_AdjustRect(hwndCtl, FALSE, &rcCtl);
SetWindowPos(hwndPage, HWND_TOP, rcCtl.left, rcCtl.top,
rcCtl.right - rcCtl.left, rcCtl.bottom - rcCtl.top, SWP_NOZORDER | SWP_NOACTIVATE);
}
}
if( g_Options.m_iCurrentPage == NET_PAGE )
{
// The network page is dynamic adapters can be added and removed. If taskmgr is minimized and
// a Adapter is added or removed. When taskmgr is maximized/restored again the netpage must be
// resized so the change is reflected. Thus the size change must be reported to the adapter.
//
((CNetPage *)g_pPages[g_Options.m_iCurrentPage])->SizeNetPage();
}
}
}
/*++ UpdateStatusBar
Routine Description:
Draws the status bar with test based on data accumulated by all of
the various pages (basically a summary of most important info)
Arguments:
Return Value:
Revision History:
Nov-29-95 Davepl Created
--*/
void UpdateStatusBar()
{
//
// If we're in menu-tracking mode (sticking help text in the stat
// bar), we don't draw our standard text
//
if (FALSE == g_fMenuTracking)
{
WCHAR szText[MAX_PATH];
StringCchPrintf(szText, ARRAYSIZE(szText), g_szfmtProcs, g_cProcesses);
SendMessage(g_hStatusWnd, SB_SETTEXT, 0, (LPARAM) szText);
StringCchPrintf(szText, ARRAYSIZE(szText), g_szfmtCPU, g_CPUUsage);
SendMessage(g_hStatusWnd, SB_SETTEXT, 1, (LPARAM) szText);
StringCchPrintf(szText, ARRAYSIZE(szText), g_szfmtMEM, (unsigned int)(int)((double)(int)g_PhysMEMUsage / (double)(int)g_PhysMEMMax * 100.0));
SendMessage(g_hStatusWnd, SB_SETTEXT, 2, (LPARAM) szText);
}
}
/*++ MainWnd_OnTimer
Routine Description:
Called when the refresh timer fires, we pass a timer event on to
each of the child pages.
Arguments:
hwnd - window timer was received at
id - id of timer that was received
Return Value:
Revision History:
Nov-30-95 Davepl Created
--*/
void MainWnd_OnTimer(HWND hwnd)
{
static const int cchTipTextSize = (2 * SHORTSTRLEN);
if (GetForegroundWindow() == hwnd && GetKeyState(VK_CONTROL) < 0)
{
// CTRL alone means pause
return;
}
// Notify each of the pages in turn that they need to updatre
for (int i = 0; i < g_nPageCount; i++)
{
g_pPages[i]->TimerEvent();
}
// Update the tray icon
UINT iIconIndex = (g_CPUUsage * g_cTrayIcons) / 100;
if (iIconIndex >= g_cTrayIcons)
{
iIconIndex = g_cTrayIcons - 1; // Handle 100% case
}
LPWSTR pszTipText = (LPWSTR) HeapAlloc( GetProcessHeap( ), 0, cchTipTextSize * sizeof(WCHAR) );
if ( NULL != pszTipText )
{
// UI only - don't care if it gets truncated
StringCchPrintf( pszTipText, cchTipTextSize, g_szfmtCPU, g_CPUUsage );
}
BOOL b = PostThreadMessage( g_idTrayThread, PM_NOTIFYWAITING, iIconIndex, (LPARAM) pszTipText );
if ( !b )
{
HeapFree( GetProcessHeap( ), 0, pszTipText );
}
UpdateStatusBar();
}
/*++ MainWnd_OnInitDialog
Routine Description:
Processes WM_INITDIALOG for the main window (a modeless dialog)
Revision History:
Nov-29-95 Davepl Created
--*/
BOOL MainWnd_OnInitDialog(HWND hwnd)
{
RECT rcMain;
GetWindowRect(hwnd, &rcMain);
g_minWidth = rcMain.right - rcMain.left;
g_minHeight = rcMain.bottom - rcMain.top;
g_DefSpacing = (DEFSPACING_BASE * LOWORD(GetDialogBaseUnits())) / DLG_SCALE_X;
g_InnerSpacing = (INNERSPACING_BASE * LOWORD(GetDialogBaseUnits())) / DLG_SCALE_X;
g_TopSpacing = (TOPSPACING_BASE * HIWORD(GetDialogBaseUnits())) / DLG_SCALE_Y;
g_ControlWidthSpacing = (CONTROL_WIDTH_SPACING * LOWORD(GetDialogBaseUnits())) / DLG_SCALE_X;
g_ControlHeightSpacing = (CONTROL_HEIGHT_SPACING * HIWORD(GetDialogBaseUnits())) / DLG_SCALE_Y;
// Load the user's defaults
g_Options.Load();
//
// On init, save away the window handle for all to see
//
g_hMainWnd = hwnd;
g_hMainDesktop = GetThreadDesktop(GetCurrentThreadId());
// init some globals
g_cxEdge = GetSystemMetrics(SM_CXEDGE);
g_hrgnView = CreateRectRgn(0, 0, 0, 0);
g_hrgnClip = CreateRectRgn(0, 0, 0, 0);
g_hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
// If we're supposed to be TOPMOST, start out that way
if (g_Options.m_fAlwaysOnTop)
{
SetWindowPos(hwnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
}
//
// Create the status window
//
g_hStatusWnd = CreateStatusWindow(WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SBARS_SIZEGRIP,
NULL,
hwnd,
IDC_STATUSWND);
if (NULL == g_hStatusWnd)
{
return FALSE;
}
//
// Base the panes in the status bar off of the LOGPIXELSX system metric
//
HDC hdc = GetDC(NULL);
INT nInch = GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(NULL, hdc);
int ciParts[] = { nInch,
ciParts[0] + (nInch * 5) / 4,
ciParts[1] + (nInch * 5) / 2,
-1};
if (g_hStatusWnd)
{
SendMessage(g_hStatusWnd, SB_SETPARTS, ARRAYSIZE(ciParts), (LPARAM)ciParts);
}
//
// Load our app icon
//
HICON hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAIN));
if (hIcon)
{
SendMessage(hwnd, WM_SETICON, TRUE, LPARAM(hIcon));
}
//
// Add the tray icons using the tray thread.
//
PostThreadMessage( g_idTrayThread, PM_INITIALIZEICONS, 0, 0 );
//
// Turn on TOPMOST for the status bar so it doesn't slide under the
// tab control
//
SetWindowPos(g_hStatusWnd,
HWND_TOPMOST,
0,0,0,0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW);
//
// Intialize each of the the pages in turn
//
HWND hwndTabs = GetDlgItem(hwnd, IDC_TABS);
for (int i = 0; i < g_nPageCount; i++)
{
HRESULT hr;
hr = g_pPages[i]->Initialize(hwndTabs);
if (SUCCEEDED(hr))
{
//
// Get the title of the new page, and use it as the title of
// the page which we insert into the tab control
//
WCHAR szTitle[MAX_PATH];
g_pPages[i]->GetTitle(szTitle, ARRAYSIZE(szTitle));
TC_ITEM tcitem =
{
TCIF_TEXT, // value specifying which members to retrieve or set
NULL, // reserved; do not use
NULL, // reserved; do not use
szTitle, // pointer to string containing tab text
ARRAYSIZE(szTitle), // size of buffer pointed to by the pszText member
0, // index to tab control's image
NULL // application-defined data associated with tab
};
//
// If the item doesn't get inserted, no harm - no foul. He just sits out
// this game.
//
TabCtrl_InsertItem(hwndTabs, i, &tcitem);
}
else
{
//
// Bail! All the tabs must at least initialize.
//
TerminateProcess( GetCurrentProcess(), 0 );
}
}
//
// Set the inital menu states
//
UpdateMenuStates();
//
// Activate a page (pick page 0 if no preference is set)
//
if (g_Options.m_iCurrentPage < 0 || g_Options.m_iCurrentPage >= g_nPageCount )
{
g_Options.m_iCurrentPage = 0;
}
TabCtrl_SetCurSel(GetDlgItem(g_hMainWnd, IDC_TABS), g_Options.m_iCurrentPage);
g_pPages[g_Options.m_iCurrentPage]->Activate();
RECT rcMainClient;
GetClientRect(hwnd, &rcMainClient);
MainWnd_OnSize(g_hMainWnd, 0, rcMainClient.right - rcMainClient.left, rcMainClient.bottom - rcMainClient.top);
//
// Create the update timer
//
if (g_Options.m_dwTimerInterval) // 0 == paused
{
SetTimer(g_hMainWnd, 0, g_Options.m_dwTimerInterval, NULL);
}
// Force at least one intial update so that we don't need to wait
// for the first timed update to come through
MainWnd_OnTimer(g_hMainWnd);
//
// Disable the MP-specific menu items
//
if (g_cProcessors <= 1)
{
HMENU hMenu = GetMenu(g_hMainWnd);
EnableMenuItem(hMenu, IDM_MULTIGRAPH, MF_BYCOMMAND | MF_GRAYED);
}
return TRUE; // have the system set the default focus.
}
//
// Draw an edge just below menu bar
//
void MainWnd_Draw(HWND hwnd, HDC hdc)
{
RECT rc;
GetClientRect(hwnd, &rc);
DrawEdge(hdc, &rc, EDGE_ETCHED, BF_TOP);
}
void MainWnd_OnPrintClient(HWND hwnd, HDC hdc)
{
MainWnd_Draw(hwnd, hdc);
}
/*++ MainWnd_OnPaint
Routine Description:
Just draws a thin edge just below the main menu bar
Arguments:
hwnd - Main window
Return Value:
Revision History:
Nov-29-95 Davepl Created
--*/
void MainWnd_OnPaint(HWND hwnd)
{