diff --git a/configure b/configure index a8231f7d329..1c383e785da 100755 --- a/configure +++ b/configure @@ -20035,7 +20035,7 @@ MAKE_LIB_RULES=libs/Makelib.rules MAKE_PROG_RULES=programs/Makeprog.rules - ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules dlls/Maketest.rules libs/Makelib.rules programs/Makeprog.rules Makefile dlls/Makefile dlls/advapi32/Makefile dlls/advapi32/tests/Makefile dlls/amstream/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/cabinet/Makefile dlls/capi2032/Makefile dlls/cards/Makefile dlls/cfgmgr32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/comctl32/tests/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/ctl3d/Makefile dlls/d3d8/Makefile dlls/d3d9/Makefile dlls/d3dim/Makefile dlls/d3dx8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/ddraw/tests/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dmband/Makefile dlls/dmcompos/Makefile dlls/dmime/Makefile dlls/dmloader/Makefile dlls/dmscript/Makefile dlls/dmstyle/Makefile dlls/dmsynth/Makefile dlls/dmusic/Makefile dlls/dmusic32/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dpnhpast/Makefile dlls/dsound/Makefile dlls/dsound/tests/Makefile dlls/dswave/Makefile dlls/dxerr8/Makefile dlls/dxerr9/Makefile dlls/dxguid/Makefile dlls/gdi/Makefile dlls/gdi/tests/Makefile dlls/glu32/Makefile dlls/glut32/Makefile dlls/iccvid/Makefile dlls/icmp/Makefile dlls/ifsmgr.vxd/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/iphlpapi/Makefile dlls/iphlpapi/tests/Makefile dlls/kernel/Makefile dlls/kernel/tests/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mmdevldr.vxd/Makefile dlls/monodebg.vxd/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/mshtml/Makefile dlls/msi/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt/tests/Makefile dlls/msvcrt20/Makefile dlls/msvcrt40/Makefile dlls/msvcrtd/Makefile dlls/msvidc32/Makefile dlls/msvideo/Makefile dlls/mswsock/Makefile dlls/netapi32/Makefile dlls/netapi32/tests/Makefile dlls/newdev/Makefile dlls/ntdll/Makefile dlls/ntdll/tests/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleacc/Makefile dlls/oleaut32/Makefile dlls/oleaut32/tests/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/rpcrt4/tests/Makefile dlls/rsabase/Makefile dlls/secur32/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shell32/tests/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/shlwapi/tests/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/unicows/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/urlmon/tests/Makefile dlls/user/Makefile dlls/user/tests/Makefile dlls/uuid/Makefile dlls/uxtheme/Makefile dlls/vdhcp.vxd/Makefile dlls/version/Makefile dlls/vmm.vxd/Makefile dlls/vnbt.vxd/Makefile dlls/vnetbios.vxd/Makefile dlls/vtdapi.vxd/Makefile dlls/vwin32.vxd/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/wined3d/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/wininet/tests/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/tests/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineaudioio/Makefile dlls/winmm/winejack/Makefile dlls/winmm/winenas/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winsock/tests/Makefile dlls/winspool/Makefile dlls/winspool/tests/Makefile dlls/wintab32/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile libs/Makefile libs/port/Makefile libs/unicode/Makefile libs/wine/Makefile libs/wpp/Makefile loader/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/progman/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/rpcss/Makefile programs/rundll32/Makefile programs/start/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineboot/Makefile programs/winebrowser/Makefile programs/winecfg/Makefile programs/wineconsole/Makefile programs/winedbg/Makefile programs/winefile/Makefile programs/winemenubuilder/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winevdm/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/widl/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/winegcc/Makefile tools/wmc/Makefile tools/wrc/Makefile" + ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules dlls/Maketest.rules libs/Makelib.rules programs/Makeprog.rules Makefile dlls/Makefile dlls/advapi32/Makefile dlls/advapi32/tests/Makefile dlls/amstream/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/cabinet/Makefile dlls/capi2032/Makefile dlls/cards/Makefile dlls/cfgmgr32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/comctl32/tests/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/ctl3d/Makefile dlls/d3d8/Makefile dlls/d3d9/Makefile dlls/d3dim/Makefile dlls/d3dx8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/ddraw/tests/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dmband/Makefile dlls/dmcompos/Makefile dlls/dmime/Makefile dlls/dmloader/Makefile dlls/dmscript/Makefile dlls/dmstyle/Makefile dlls/dmsynth/Makefile dlls/dmusic/Makefile dlls/dmusic32/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dpnhpast/Makefile dlls/dsound/Makefile dlls/dsound/tests/Makefile dlls/dswave/Makefile dlls/dxerr8/Makefile dlls/dxerr9/Makefile dlls/dxguid/Makefile dlls/gdi/Makefile dlls/gdi/tests/Makefile dlls/glu32/Makefile dlls/glut32/Makefile dlls/iccvid/Makefile dlls/icmp/Makefile dlls/ifsmgr.vxd/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/iphlpapi/Makefile dlls/iphlpapi/tests/Makefile dlls/kernel/Makefile dlls/kernel/tests/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mmdevldr.vxd/Makefile dlls/monodebg.vxd/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/mshtml/Makefile dlls/msi/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt/tests/Makefile dlls/msvcrt20/Makefile dlls/msvcrt40/Makefile dlls/msvcrtd/Makefile dlls/msvidc32/Makefile dlls/msvideo/Makefile dlls/mswsock/Makefile dlls/netapi32/Makefile dlls/netapi32/tests/Makefile dlls/newdev/Makefile dlls/ntdll/Makefile dlls/ntdll/tests/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleacc/Makefile dlls/oleaut32/Makefile dlls/oleaut32/tests/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/rpcrt4/tests/Makefile dlls/rsabase/Makefile dlls/secur32/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shell32/tests/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/shlwapi/tests/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/unicows/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/urlmon/tests/Makefile dlls/user/Makefile dlls/user/tests/Makefile dlls/uuid/Makefile dlls/uxtheme/Makefile dlls/vdhcp.vxd/Makefile dlls/version/Makefile dlls/vmm.vxd/Makefile dlls/vnbt.vxd/Makefile dlls/vnetbios.vxd/Makefile dlls/vtdapi.vxd/Makefile dlls/vwin32.vxd/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/wined3d/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/wininet/tests/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/tests/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineaudioio/Makefile dlls/winmm/winejack/Makefile dlls/winmm/winenas/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winsock/tests/Makefile dlls/winspool/Makefile dlls/winspool/tests/Makefile dlls/wintab32/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile libs/Makefile libs/port/Makefile libs/unicode/Makefile libs/wine/Makefile libs/wpp/Makefile loader/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/progman/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/rpcss/Makefile programs/rundll32/Makefile programs/start/Makefile programs/taskmgr/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineboot/Makefile programs/winebrowser/Makefile programs/winecfg/Makefile programs/wineconsole/Makefile programs/winedbg/Makefile programs/winefile/Makefile programs/winemenubuilder/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winevdm/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/widl/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/winegcc/Makefile tools/wmc/Makefile tools/wrc/Makefile" cat >confcache <<\_ACEOF @@ -20761,6 +20761,7 @@ do "programs/rpcss/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/rpcss/Makefile" ;; "programs/rundll32/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/rundll32/Makefile" ;; "programs/start/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/start/Makefile" ;; + "programs/taskmgr/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/taskmgr/Makefile" ;; "programs/uninstaller/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/uninstaller/Makefile" ;; "programs/view/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/view/Makefile" ;; "programs/wcmd/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/wcmd/Makefile" ;; diff --git a/configure.ac b/configure.ac index 8d6e8bd8438..c7308f3bb0f 100644 --- a/configure.ac +++ b/configure.ac @@ -1679,6 +1679,7 @@ programs/regsvr32/Makefile programs/rpcss/Makefile programs/rundll32/Makefile programs/start/Makefile +programs/taskmgr/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile diff --git a/programs/Makefile.in b/programs/Makefile.in index 3f700d43ebc..ea88b5f6c25 100644 --- a/programs/Makefile.in +++ b/programs/Makefile.in @@ -18,6 +18,7 @@ SUBDIRS = \ rpcss \ rundll32 \ start \ + taskmgr \ uninstaller \ view \ wcmd \ @@ -48,6 +49,7 @@ INSTALLSUBDIRS = \ rpcss \ rundll32 \ start \ + taskmgr \ uninstaller \ wcmd \ wineboot \ @@ -98,6 +100,7 @@ SYMLINKS = \ rpcss.exe \ rundll32.exe \ start.exe \ + taskmgr.exe \ uninstaller.exe \ view.exe \ wcmd.exe \ @@ -200,6 +203,9 @@ rundll32.exe$(DLLEXT): rundll32/rundll32.exe$(DLLEXT) start.exe$(DLLEXT): start/start.exe$(DLLEXT) $(RM) $@ && $(LN_S) start/start.exe$(DLLEXT) $@ +taskmgr.exe$(DLLEXT): taskmgr/taskmgr.exe$(DLLEXT) + $(RM) $@ && $(LN_S) taskmgr/taskmgr.exe$(DLLEXT) $@ + uninstaller.exe$(DLLEXT): uninstaller/uninstaller.exe$(DLLEXT) $(RM) $@ && $(LN_S) uninstaller/uninstaller.exe$(DLLEXT) $@ @@ -262,6 +268,7 @@ regsvr32/regsvr32.exe$(DLLEXT): regsvr32 rpcss/rpcss.exe$(DLLEXT): rpcss rundll32/rundll32.exe$(DLLEXT): rundll32 start/start.exe$(DLLEXT): start +taskmgr/taskmgr.exe$(DLLEXT): taskmgr uninstaller/uninstaller.exe$(DLLEXT): uninstaller view/view.exe$(DLLEXT): view wcmd/wcmd.exe$(DLLEXT): wcmd diff --git a/programs/taskmgr/.cvsignore b/programs/taskmgr/.cvsignore new file mode 100644 index 00000000000..99044848037 --- /dev/null +++ b/programs/taskmgr/.cvsignore @@ -0,0 +1,9 @@ +Makefile +font.bmp +taskmgr.exe.dbg.c +taskmgr.ico +taskmgr.res +trayicon.bmp +traymask.bmp +window.ico +windowsm.ico diff --git a/programs/taskmgr/Makefile.in b/programs/taskmgr/Makefile.in new file mode 100644 index 00000000000..73c0695c7bf --- /dev/null +++ b/programs/taskmgr/Makefile.in @@ -0,0 +1,43 @@ +TOPSRCDIR = @top_srcdir@ +TOPOBJDIR = ../.. +SRCDIR = @srcdir@ +VPATH = @srcdir@ +MODULE = taskmgr.exe +APPMODE = -mwindows +IMPORTS = psapi shell32 comctl32 msvcrt user32 gdi32 advapi32 kernel32 +EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt +EXTRADEFS = -DNO_LIBWINE_PORT + +C_SRCS = \ + about.c \ + affinity.c \ + applpage.c \ + column.c \ + dbgchnl.c \ + debug.c \ + endproc.c \ + graph.c \ + graphctl.c \ + optnmenu.c \ + perfdata.c \ + perfpage.c \ + priority.c \ + proclist.c \ + procpage.c \ + run.c \ + taskmgr.c \ + trayicon.c + +RC_SRCS = taskmgr.rc +RC_BINSRC = taskmgr.rc +RC_BINARIES = \ + font.bmp \ + taskmgr.ico \ + trayicon.bmp \ + traymask.bmp \ + window.ico \ + windowsm.ico + +@MAKE_PROG_RULES@ + +### Dependencies: diff --git a/programs/taskmgr/about.c b/programs/taskmgr/about.c new file mode 100644 index 00000000000..5e1597e332f --- /dev/null +++ b/programs/taskmgr/about.c @@ -0,0 +1,70 @@ +/* + * ReactOS Task Manager + * + * about.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" + +LRESULT CALLBACK AboutDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); + +void OnAbout(void) +{ + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hMainWnd, (DLGPROC)AboutDialogWndProc); +} + +LRESULT CALLBACK AboutDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + HWND hLicenseEditWnd; + TCHAR strLicense[0x1000]; + + switch (message) + { + case WM_INITDIALOG: + + hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE_EDIT); + + LoadString(hInst, IDS_LICENSE, strLicense, 0x1000); + + SetWindowText(hLicenseEditWnd, strLicense); + + return TRUE; + + case WM_COMMAND: + + if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) + { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + + break; + } + + return 0; +} diff --git a/programs/taskmgr/affinity.c b/programs/taskmgr/affinity.c new file mode 100644 index 00000000000..b6911740fc6 --- /dev/null +++ b/programs/taskmgr/affinity.c @@ -0,0 +1,344 @@ +/* + * ReactOS Task Manager + * + * affinity.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" + +HANDLE hProcessAffinityHandle; + +LRESULT CALLBACK AffinityDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); + +void ProcessPage_OnSetAffinity(void) +{ + LV_ITEM lvitem; + ULONG Index; + DWORD dwProcessId; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) { + memset(&lvitem, 0, sizeof(LV_ITEM)); + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + ListView_GetItem(hProcessPageListCtrl, &lvitem); + if (lvitem.state & LVIS_SELECTED) + break; + } + dwProcessId = PerfDataGetProcessId(Index); + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + hProcessAffinityHandle = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION, FALSE, dwProcessId); + if (!hProcessAffinityHandle) { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Access or Set Process Affinity"), MB_OK|MB_ICONSTOP); + return; + } + DialogBox(hInst, MAKEINTRESOURCE(IDD_AFFINITY_DIALOG), hMainWnd, (DLGPROC)AffinityDialogWndProc); + if (hProcessAffinityHandle) { + CloseHandle(hProcessAffinityHandle); + hProcessAffinityHandle = NULL; + } +} + +LRESULT CALLBACK AffinityDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + DWORD dwProcessAffinityMask = 0; + DWORD dwSystemAffinityMask = 0; + TCHAR strErrorText[260]; + + switch (message) { + case WM_INITDIALOG: + + /* + * Get the current affinity mask for the process and + * the number of CPUs present in the system + */ + if (!GetProcessAffinityMask(hProcessAffinityHandle, &dwProcessAffinityMask, &dwSystemAffinityMask)) { + GetLastErrorText(strErrorText, 260); + EndDialog(hDlg, 0); + MessageBox(hMainWnd, strErrorText, _T("Unable to Access or Set Process Affinity"), MB_OK|MB_ICONSTOP); + } + + /* + * Enable a checkbox for each processor present in the system + */ + if (dwSystemAffinityMask & 0x00000001) + EnableWindow(GetDlgItem(hDlg, IDC_CPU0), TRUE); + if (dwSystemAffinityMask & 0x00000002) + EnableWindow(GetDlgItem(hDlg, IDC_CPU1), TRUE); + if (dwSystemAffinityMask & 0x00000004) + EnableWindow(GetDlgItem(hDlg, IDC_CPU2), TRUE); + if (dwSystemAffinityMask & 0x00000008) + EnableWindow(GetDlgItem(hDlg, IDC_CPU3), TRUE); + if (dwSystemAffinityMask & 0x00000010) + EnableWindow(GetDlgItem(hDlg, IDC_CPU4), TRUE); + if (dwSystemAffinityMask & 0x00000020) + EnableWindow(GetDlgItem(hDlg, IDC_CPU5), TRUE); + if (dwSystemAffinityMask & 0x00000040) + EnableWindow(GetDlgItem(hDlg, IDC_CPU6), TRUE); + if (dwSystemAffinityMask & 0x00000080) + EnableWindow(GetDlgItem(hDlg, IDC_CPU7), TRUE); + if (dwSystemAffinityMask & 0x00000100) + EnableWindow(GetDlgItem(hDlg, IDC_CPU8), TRUE); + if (dwSystemAffinityMask & 0x00000200) + EnableWindow(GetDlgItem(hDlg, IDC_CPU9), TRUE); + if (dwSystemAffinityMask & 0x00000400) + EnableWindow(GetDlgItem(hDlg, IDC_CPU10), TRUE); + if (dwSystemAffinityMask & 0x00000800) + EnableWindow(GetDlgItem(hDlg, IDC_CPU11), TRUE); + if (dwSystemAffinityMask & 0x00001000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU12), TRUE); + if (dwSystemAffinityMask & 0x00002000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU13), TRUE); + if (dwSystemAffinityMask & 0x00004000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU14), TRUE); + if (dwSystemAffinityMask & 0x00008000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU15), TRUE); + if (dwSystemAffinityMask & 0x00010000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU16), TRUE); + if (dwSystemAffinityMask & 0x00020000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU17), TRUE); + if (dwSystemAffinityMask & 0x00040000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU18), TRUE); + if (dwSystemAffinityMask & 0x00080000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU19), TRUE); + if (dwSystemAffinityMask & 0x00100000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU20), TRUE); + if (dwSystemAffinityMask & 0x00200000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU21), TRUE); + if (dwSystemAffinityMask & 0x00400000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU22), TRUE); + if (dwSystemAffinityMask & 0x00800000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU23), TRUE); + if (dwSystemAffinityMask & 0x01000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU24), TRUE); + if (dwSystemAffinityMask & 0x02000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU25), TRUE); + if (dwSystemAffinityMask & 0x04000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU26), TRUE); + if (dwSystemAffinityMask & 0x08000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU27), TRUE); + if (dwSystemAffinityMask & 0x10000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU28), TRUE); + if (dwSystemAffinityMask & 0x20000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU29), TRUE); + if (dwSystemAffinityMask & 0x40000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU30), TRUE); + if (dwSystemAffinityMask & 0x80000000) + EnableWindow(GetDlgItem(hDlg, IDC_CPU31), TRUE); + + + /* + * Check each checkbox that the current process + * has affinity with + */ + if (dwProcessAffinityMask & 0x00000001) + SendMessage(GetDlgItem(hDlg, IDC_CPU0), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000002) + SendMessage(GetDlgItem(hDlg, IDC_CPU1), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000004) + SendMessage(GetDlgItem(hDlg, IDC_CPU2), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000008) + SendMessage(GetDlgItem(hDlg, IDC_CPU3), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000010) + SendMessage(GetDlgItem(hDlg, IDC_CPU4), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000020) + SendMessage(GetDlgItem(hDlg, IDC_CPU5), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000040) + SendMessage(GetDlgItem(hDlg, IDC_CPU6), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000080) + SendMessage(GetDlgItem(hDlg, IDC_CPU7), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000100) + SendMessage(GetDlgItem(hDlg, IDC_CPU8), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000200) + SendMessage(GetDlgItem(hDlg, IDC_CPU9), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000400) + SendMessage(GetDlgItem(hDlg, IDC_CPU10), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00000800) + SendMessage(GetDlgItem(hDlg, IDC_CPU11), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00001000) + SendMessage(GetDlgItem(hDlg, IDC_CPU12), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00002000) + SendMessage(GetDlgItem(hDlg, IDC_CPU13), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00004000) + SendMessage(GetDlgItem(hDlg, IDC_CPU14), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00008000) + SendMessage(GetDlgItem(hDlg, IDC_CPU15), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00010000) + SendMessage(GetDlgItem(hDlg, IDC_CPU16), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00020000) + SendMessage(GetDlgItem(hDlg, IDC_CPU17), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00040000) + SendMessage(GetDlgItem(hDlg, IDC_CPU18), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00080000) + SendMessage(GetDlgItem(hDlg, IDC_CPU19), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00100000) + SendMessage(GetDlgItem(hDlg, IDC_CPU20), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00200000) + SendMessage(GetDlgItem(hDlg, IDC_CPU21), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00400000) + SendMessage(GetDlgItem(hDlg, IDC_CPU22), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x00800000) + SendMessage(GetDlgItem(hDlg, IDC_CPU23), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x01000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU24), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x02000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU25), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x04000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU26), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x08000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU27), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x10000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU28), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x20000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU29), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x40000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU30), BM_SETCHECK, BST_CHECKED, 0); + if (dwProcessAffinityMask & 0x80000000) + SendMessage(GetDlgItem(hDlg, IDC_CPU31), BM_SETCHECK, BST_CHECKED, 0); + + return TRUE; + + case WM_COMMAND: + + /* + * If the user has cancelled the dialog box + * then just close it + */ + if (LOWORD(wParam) == IDCANCEL) { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + + /* + * The user has clicked OK -- so now we have + * to adjust the process affinity mask + */ + if (LOWORD(wParam) == IDOK) { + /* + * First we have to create a mask out of each + * checkbox that the user checked. + */ + if (SendMessage(GetDlgItem(hDlg, IDC_CPU0), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000001; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU1), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000002; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU2), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000004; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU3), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000008; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU4), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000010; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU5), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000020; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU6), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000040; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU7), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000080; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU8), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000100; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU9), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000200; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU10), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000400; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU11), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00000800; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU12), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00001000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU13), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00002000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU14), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00004000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU15), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00008000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU16), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00010000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU17), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00020000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU18), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00040000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU19), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00080000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU20), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00100000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU21), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00200000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU22), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00400000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU23), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x00800000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU24), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x01000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU25), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x02000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU26), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x04000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU27), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x08000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU28), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x10000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU29), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x20000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU30), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x40000000; + if (SendMessage(GetDlgItem(hDlg, IDC_CPU31), BM_GETCHECK, 0, 0)) + dwProcessAffinityMask |= 0x80000000; + + /* + * Make sure they are giving the process affinity + * with at least one processor. I'd hate to see a + * process that is not in a wait state get deprived + * of it's cpu time. + */ + if (!dwProcessAffinityMask) { + MessageBox(hDlg, _T("The process must have affinity with at least one processor."), _T("Invalid Option"), MB_OK|MB_ICONSTOP); + return TRUE; + } + + /* + * Try to set the process affinity + */ + if (!SetProcessAffinityMask(hProcessAffinityHandle, dwProcessAffinityMask)) { + GetLastErrorText(strErrorText, 260); + EndDialog(hDlg, LOWORD(wParam)); + MessageBox(hMainWnd, strErrorText, _T("Unable to Access or Set Process Affinity"), MB_OK|MB_ICONSTOP); + } + + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + + break; + } + + return 0; +} diff --git a/programs/taskmgr/applpage.c b/programs/taskmgr/applpage.c new file mode 100644 index 00000000000..f4b1538fa01 --- /dev/null +++ b/programs/taskmgr/applpage.c @@ -0,0 +1,956 @@ +/* + * ReactOS Task Manager + * + * applpage.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" + +typedef struct +{ + HWND hWnd; + TCHAR szTitle[260]; + HICON hIcon; + BOOL bHung; +} APPLICATION_PAGE_LIST_ITEM, *LPAPPLICATION_PAGE_LIST_ITEM; + +HWND hApplicationPage; /* Application List Property Page */ +HWND hApplicationPageListCtrl; /* Application ListCtrl Window */ +HWND hApplicationPageEndTaskButton; /* Application End Task button */ +HWND hApplicationPageSwitchToButton; /* Application Switch To button */ +HWND hApplicationPageNewTaskButton; /* Application New Task button */ +static int nApplicationPageWidth; +static int nApplicationPageHeight; +static HANDLE hApplicationPageEvent = NULL; /* When this event becomes signaled then we refresh the app list */ +static BOOL bSortAscending = TRUE; +DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter); +BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam); +void AddOrUpdateHwnd(HWND hWnd, TCHAR *szTitle, HICON hIcon, BOOL bHung); +void ApplicationPageUpdate(void); +void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam); +void ApplicationPageShowContextMenu1(void); +void ApplicationPageShowContextMenu2(void); +int CALLBACK ApplicationPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); + +#if 0 +void SwitchToThisWindow ( +HWND hWnd, /* Handle to the window that should be activated */ +BOOL bRestore /* Restore the window if it is minimized */ +); +#endif + +LRESULT CALLBACK ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + RECT rc; + int nXDifference; + int nYDifference; + LV_COLUMN column; + TCHAR szTemp[256]; + int cx, cy; + + switch (message) { + case WM_INITDIALOG: + + /* Save the width and height */ + GetClientRect(hDlg, &rc); + nApplicationPageWidth = rc.right; + nApplicationPageHeight = rc.bottom; + + /* Update window position */ + SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + + /* Get handles to the controls */ + hApplicationPageListCtrl = GetDlgItem(hDlg, IDC_APPLIST); + hApplicationPageEndTaskButton = GetDlgItem(hDlg, IDC_ENDTASK); + hApplicationPageSwitchToButton = GetDlgItem(hDlg, IDC_SWITCHTO); + hApplicationPageNewTaskButton = GetDlgItem(hDlg, IDC_NEWTASK); + + SetWindowText(hApplicationPageListCtrl, _T("Tasks")); + + /* Initialize the application page's controls */ + column.mask = LVCF_TEXT|LVCF_WIDTH; + _tcscpy(szTemp, _T("Task")); + column.pszText = szTemp; + column.cx = 250; + ListView_InsertColumn(hApplicationPageListCtrl, 0, &column); /* Add the "Task" column */ + column.mask = LVCF_TEXT|LVCF_WIDTH; + _tcscpy(szTemp, _T("Status")); + column.pszText = szTemp; + column.cx = 95; + ListView_InsertColumn(hApplicationPageListCtrl, 1, &column); /* Add the "Status" column */ + + ListView_SetImageList(hApplicationPageListCtrl, ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 0, 1), LVSIL_SMALL); + ListView_SetImageList(hApplicationPageListCtrl, ImageList_Create(32, 32, ILC_COLOR8|ILC_MASK, 0, 1), LVSIL_NORMAL); + + UpdateApplicationListControlViewSetting(); + + /* Start our refresh thread */ + CreateThread(NULL, 0, ApplicationPageRefreshThread, NULL, 0, NULL); + + return TRUE; + + case WM_DESTROY: + /* Close the event handle, this will make the */ + /* refresh thread exit when the wait fails */ + CloseHandle(hApplicationPageEvent); + break; + + case WM_COMMAND: + + /* Handle the button clicks */ + switch (LOWORD(wParam)) + { + case IDC_ENDTASK: + ApplicationPage_OnEndTask(); + break; + case IDC_SWITCHTO: + ApplicationPage_OnSwitchTo(); + break; + case IDC_NEWTASK: + SendMessage(hMainWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, 0), 0); + break; + } + + break; + + case WM_SIZE: + if (wParam == SIZE_MINIMIZED) + return 0; + + cx = LOWORD(lParam); + cy = HIWORD(lParam); + nXDifference = cx - nApplicationPageWidth; + nYDifference = cy - nApplicationPageHeight; + nApplicationPageWidth = cx; + nApplicationPageHeight = cy; + + /* Reposition the application page's controls */ + GetWindowRect(hApplicationPageListCtrl, &rc); + cx = (rc.right - rc.left) + nXDifference; + cy = (rc.bottom - rc.top) + nYDifference; + SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + InvalidateRect(hApplicationPageListCtrl, NULL, TRUE); + + GetClientRect(hApplicationPageEndTaskButton, &rc); + MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE); + + GetClientRect(hApplicationPageSwitchToButton, &rc); + MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE); + + GetClientRect(hApplicationPageNewTaskButton, &rc); + MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE); + + break; + + case WM_NOTIFY: + ApplicationPageOnNotify(wParam, lParam); + break; + + } + + return 0; +} + +void RefreshApplicationPage(void) +{ + /* Signal the event so that our refresh thread */ + /* will wake up and refresh the application page */ + SetEvent(hApplicationPageEvent); +} + +void UpdateApplicationListControlViewSetting(void) +{ + DWORD dwStyle = GetWindowLong(hApplicationPageListCtrl, GWL_STYLE); + + dwStyle &= ~LVS_REPORT; + dwStyle &= ~LVS_ICON; + dwStyle &= ~LVS_LIST; + dwStyle &= ~LVS_SMALLICON; + + if (TaskManagerSettings.View_LargeIcons) + dwStyle |= LVS_ICON; + else if (TaskManagerSettings.View_SmallIcons) + dwStyle |= LVS_SMALLICON; + else + dwStyle |= LVS_REPORT; + + SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle); + + RefreshApplicationPage(); +} + +DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter) +{ + /* Create the event */ + hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, _T("Application Page Event")); + + /* If we couldn't create the event then exit the thread */ + if (!hApplicationPageEvent) + return 0; + + while (1) + { + DWORD dwWaitVal; + + /* Wait on the event */ + dwWaitVal = WaitForSingleObject(hApplicationPageEvent, INFINITE); + + /* If the wait failed then the event object must have been */ + /* closed and the task manager is exiting so exit this thread */ + if (dwWaitVal == WAIT_FAILED) + return 0; + + if (dwWaitVal == WAIT_OBJECT_0) + { + /* Reset our event */ + ResetEvent(hApplicationPageEvent); + + /* + * FIXME: + * + * Should this be EnumDesktopWindows() instead? + */ + EnumWindows(EnumWindowsProc, 0); + } + } +} + +BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) +{ + HICON hIcon; + TCHAR szText[260]; + BOOL bLargeIcon; + BOOL bHung = FALSE; + typedef int (__stdcall *IsHungAppWindowProc)(HWND); + IsHungAppWindowProc IsHungAppWindow; + + + /* Skip our window */ + if (hWnd == hMainWnd) + return TRUE; + + bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE; + + GetWindowText(hWnd, szText, 260); /* Get the window text */ + + /* Check and see if this is a top-level app window */ + if ((_tcslen(szText) <= 0) || + !IsWindowVisible(hWnd) || + (GetParent(hWnd) != NULL) || + (GetWindow(hWnd, GW_OWNER) != NULL) || + (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) + { + return TRUE; /* Skip this window */ + } + + /* Get the icon for this window */ + hIcon = NULL; + SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG /*1*/ : ICON_SMALL /*0*/, 0, 0, 1000, (unsigned long*)&hIcon); + + if (!hIcon) + { + hIcon = (HICON)GetClassLong(hWnd, bLargeIcon ? GCL_HICON : GCL_HICONSM); + if (!hIcon) hIcon = (HICON)GetClassLong(hWnd, bLargeIcon ? GCL_HICONSM : GCL_HICON); + if (!hIcon) SendMessageTimeout(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (unsigned long*)&hIcon); + if (!hIcon) SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL /*0*/ : ICON_BIG /*1*/, 0, 0, 1000, (unsigned long*)&hIcon); + } + + if (!hIcon) + hIcon = LoadIcon(hInst, bLargeIcon ? MAKEINTRESOURCE(IDI_WINDOW) : MAKEINTRESOURCE(IDI_WINDOWSM)); + + bHung = FALSE; + + IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandle(_T("USER32.DLL")), "IsHungAppWindow"); + + if (IsHungAppWindow) + bHung = IsHungAppWindow(hWnd); + + AddOrUpdateHwnd(hWnd, szText, hIcon, bHung); + + return TRUE; +} + +void AddOrUpdateHwnd(HWND hWnd, TCHAR *szTitle, HICON hIcon, BOOL bHung) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + HIMAGELIST hImageListLarge; + HIMAGELIST hImageListSmall; + LV_ITEM item; + int i; + BOOL bAlreadyInList = FALSE; + BOOL bItemRemoved = FALSE; + + memset(&item, 0, sizeof(LV_ITEM)); + + /* Get the image lists */ + hImageListLarge = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_NORMAL); + hImageListSmall = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_SMALL); + + /* Check to see if it's already in our list */ + for (i=0; ihWnd == hWnd) + { + bAlreadyInList = TRUE; + break; + } + } + + /* If it is already in the list then update it if necessary */ + if (bAlreadyInList) + { + /* Check to see if anything needs updating */ + if ((pAPLI->hIcon != hIcon) || + (_tcsicmp(pAPLI->szTitle, szTitle) != 0) || + (pAPLI->bHung != bHung)) + { + /* Update the structure */ + pAPLI->hIcon = hIcon; + pAPLI->bHung = bHung; + _tcscpy(pAPLI->szTitle, szTitle); + + /* Update the image list */ + ImageList_ReplaceIcon(hImageListLarge, item.iItem, hIcon); + ImageList_ReplaceIcon(hImageListSmall, item.iItem, hIcon); + + /* Update the list view */ + ListView_RedrawItems(hApplicationPageListCtrl, 0, ListView_GetItemCount(hApplicationPageListCtrl)); + /* UpdateWindow(hApplicationPageListCtrl); */ + InvalidateRect(hApplicationPageListCtrl, NULL, 0); + } + } + /* It is not already in the list so add it */ + else + { + pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)malloc(sizeof(APPLICATION_PAGE_LIST_ITEM)); + + pAPLI->hWnd = hWnd; + pAPLI->hIcon = hIcon; + pAPLI->bHung = bHung; + _tcscpy(pAPLI->szTitle, szTitle); + + /* Add the item to the list */ + memset(&item, 0, sizeof(LV_ITEM)); + item.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM; + ImageList_AddIcon(hImageListLarge, hIcon); + item.iImage = ImageList_AddIcon(hImageListSmall, hIcon); + item.pszText = LPSTR_TEXTCALLBACK; + item.iItem = ListView_GetItemCount(hApplicationPageListCtrl); + item.lParam = (LPARAM)pAPLI; + ListView_InsertItem(hApplicationPageListCtrl, &item); + } + + + /* Check to see if we need to remove any items from the list */ + for (i=ListView_GetItemCount(hApplicationPageListCtrl)-1; i>=0; i--) + { + memset(&item, 0, sizeof(LV_ITEM)); + item.mask = LVIF_IMAGE|LVIF_PARAM; + item.iItem = i; + ListView_GetItem(hApplicationPageListCtrl, &item); + + pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam; + if (!IsWindow(pAPLI->hWnd)|| + (_tcslen(pAPLI->szTitle) <= 0) || + !IsWindowVisible(pAPLI->hWnd) || + (GetParent(pAPLI->hWnd) != NULL) || + (GetWindow(pAPLI->hWnd, GW_OWNER) != NULL) || + (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) + { + ImageList_Remove(hImageListLarge, item.iItem); + ImageList_Remove(hImageListSmall, item.iItem); + + ListView_DeleteItem(hApplicationPageListCtrl, item.iItem); + free(pAPLI); + bItemRemoved = TRUE; + } + } + + /* + * If an item was removed from the list then + * we need to resync all the items with the + * image list + */ + if (bItemRemoved) + { + for (i=0; i 1) + { + EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + } + /* No items selected */ + else + { + EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + } + } +} + +void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam) +{ + int idctrl; + LPNMHDR pnmh; + LPNM_LISTVIEW pnmv; + LV_DISPINFO* pnmdi; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI; + + + idctrl = (int) wParam; + pnmh = (LPNMHDR) lParam; + pnmv = (LPNM_LISTVIEW) lParam; + pnmdi = (LV_DISPINFO*) lParam; + + if (pnmh->hwndFrom == hApplicationPageListCtrl) { + switch (pnmh->code) { + case LVN_ITEMCHANGED: + ApplicationPageUpdate(); + break; + + case LVN_GETDISPINFO: + pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)pnmdi->item.lParam; + + /* Update the item text */ + if (pnmdi->item.iSubItem == 0) + { + _tcsncpy(pnmdi->item.pszText, pAPLI->szTitle, pnmdi->item.cchTextMax); + } + + /* Update the item status */ + else if (pnmdi->item.iSubItem == 1) + { + if (pAPLI->bHung) + _tcsncpy(pnmdi->item.pszText, _T("Not Responding"), pnmdi->item.cchTextMax); + else + _tcsncpy(pnmdi->item.pszText, _T("Running"), pnmdi->item.cchTextMax); + } + + break; + + case NM_RCLICK: + + if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1) + { + ApplicationPageShowContextMenu1(); + } + else + { + ApplicationPageShowContextMenu2(); + } + + break; + + case NM_DBLCLK: + + ApplicationPage_OnSwitchTo(); + + break; + } + } + else if (pnmh->hwndFrom == ListView_GetHeader(hApplicationPageListCtrl)) + { + switch (pnmh->code) + { + case NM_RCLICK: + + if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1) + { + ApplicationPageShowContextMenu1(); + } + else + { + ApplicationPageShowContextMenu2(); + } + + break; + + case HDN_ITEMCLICK: + + ListView_SortItems(hApplicationPageListCtrl, ApplicationPageCompareFunc, 0); + bSortAscending = !bSortAscending; + + break; + } + } + +} + +void ApplicationPageShowContextMenu1(void) +{ + HMENU hMenu; + HMENU hSubMenu; + POINT pt; + + GetCursorPos(&pt); + + hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1)); + hSubMenu = GetSubMenu(hMenu, 0); + + if (TaskManagerSettings.View_LargeIcons) + CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND); + else if (TaskManagerSettings.View_SmallIcons) + CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND); + else + CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND); + + TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); + + DestroyMenu(hMenu); +} + +void ApplicationPageShowContextMenu2(void) +{ + HMENU hMenu; + HMENU hSubMenu; + POINT pt; + + GetCursorPos(&pt); + + hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2)); + hSubMenu = GetSubMenu(hMenu, 0); + + if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1) + { + EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED); + } + else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1) + { + EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + } + else + { + EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + } + + SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND); + + TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); + + DestroyMenu(hMenu); +} + +void ApplicationPage_OnViewLargeIcons(void) +{ + HMENU hMenu; + HMENU hViewMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + + TaskManagerSettings.View_LargeIcons = TRUE; + TaskManagerSettings.View_SmallIcons = FALSE; + TaskManagerSettings.View_Details = FALSE; + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND); + + UpdateApplicationListControlViewSetting(); +} + +void ApplicationPage_OnViewSmallIcons(void) +{ + HMENU hMenu; + HMENU hViewMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + + TaskManagerSettings.View_LargeIcons = FALSE; + TaskManagerSettings.View_SmallIcons = TRUE; + TaskManagerSettings.View_Details = FALSE; + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND); + + UpdateApplicationListControlViewSetting(); +} + +void ApplicationPage_OnViewDetails(void) +{ + HMENU hMenu; + HMENU hViewMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + + TaskManagerSettings.View_LargeIcons = FALSE; + TaskManagerSettings.View_SmallIcons = FALSE; + TaskManagerSettings.View_Details = TRUE; + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND); + + UpdateApplicationListControlViewSetting(); +} + +void ApplicationPage_OnWindowsTileHorizontally(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + HWND* hWndArray; + int nWndCount; + + hWndArray = (HWND*)malloc(sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl)); + nWndCount = 0; + + for (i=0; ihWnd; + nWndCount++; + } + } + } + TileWindows(NULL, MDITILE_HORIZONTAL, NULL, nWndCount, hWndArray); + free(hWndArray); +} + +void ApplicationPage_OnWindowsTileVertically(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + HWND* hWndArray; + int nWndCount; + + hWndArray = (HWND*)malloc(sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl)); + nWndCount = 0; + + for (i=0; ihWnd; + nWndCount++; + } + } + } + + TileWindows(NULL, MDITILE_VERTICAL, NULL, nWndCount, hWndArray); + free(hWndArray); +} + +void ApplicationPage_OnWindowsMinimize(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + + for (i=0; ihWnd, SW_MINIMIZE); + } + } + } +} + +void ApplicationPage_OnWindowsMaximize(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + + for (i=0; ihWnd, SW_MAXIMIZE); + } + } + } +} + +void ApplicationPage_OnWindowsCascade(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + HWND* hWndArray; + int nWndCount; + + hWndArray = (HWND*)malloc(sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl)); + nWndCount = 0; + + for (i=0; ihWnd; + nWndCount++; + } + } + } + CascadeWindows(NULL, 0, NULL, nWndCount, hWndArray); + free(hWndArray); +} + +void ApplicationPage_OnWindowsBringToFront(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + + for (i=0; ihWnd)) + ShowWindow(pAPLI->hWnd, SW_RESTORE); + BringWindowToTop(pAPLI->hWnd); + } +} + +void ApplicationPage_OnSwitchTo(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + + for (i=0; ihWnd, TRUE); + } else { + if (IsIconic(pAPLI->hWnd)) + ShowWindow(pAPLI->hWnd, SW_RESTORE); + BringWindowToTop(pAPLI->hWnd); + SetForegroundWindow(pAPLI->hWnd); + } + if (TaskManagerSettings.MinimizeOnUse) + ShowWindow(hMainWnd, SW_MINIMIZE); + } +} + +void ApplicationPage_OnEndTask(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + + for (i=0; ihWnd, WM_CLOSE, 0, 0); + } + } + } +} + +void ApplicationPage_OnGotoProcess(void) +{ + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + /* NMHDR nmhdr; */ + + for (i=0; ihWnd, &dwProcessId); + /* + * Switch to the process tab + */ + TabCtrl_SetCurFocus(hTabWnd, 1); + /* + * FIXME: Select the process item in the list + */ + for (i=0; iszTitle, Param2->szTitle); +} diff --git a/programs/taskmgr/column.c b/programs/taskmgr/column.c new file mode 100644 index 00000000000..0b8ef5545d6 --- /dev/null +++ b/programs/taskmgr/column.c @@ -0,0 +1,545 @@ +/* + * ReactOS Task Manager + * + * column.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "column.h" + +UINT ColumnDataHints[25]; + +int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat, int nWidth, int nSubItem); +LRESULT CALLBACK ColumnsDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); + +void AddColumns(void) +{ + int size; + + if (TaskManagerSettings.Column_ImageName) + InsertColumn(0, _T("Image Name"), LVCFMT_LEFT, TaskManagerSettings.ColumnSizeArray[0], -1); + if (TaskManagerSettings.Column_PID) + InsertColumn(1, _T("PID"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[1], -1); + if (TaskManagerSettings.Column_UserName) + InsertColumn(2, _T("Username"), LVCFMT_LEFT, TaskManagerSettings.ColumnSizeArray[2], -1); + if (TaskManagerSettings.Column_SessionID) + InsertColumn(3, _T("Session ID"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[3], -1); + if (TaskManagerSettings.Column_CPUUsage) + InsertColumn(4, _T("CPU"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[4], -1); + if (TaskManagerSettings.Column_CPUTime) + InsertColumn(5, _T("CPU Time"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[5], -1); + if (TaskManagerSettings.Column_MemoryUsage) + InsertColumn(6, _T("Mem Usage"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[6], -1); + if (TaskManagerSettings.Column_PeakMemoryUsage) + InsertColumn(7, _T("Peak Mem Usage"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[7], -1); + if (TaskManagerSettings.Column_MemoryUsageDelta) + InsertColumn(8, _T("Mem Delta"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[8], -1); + if (TaskManagerSettings.Column_PageFaults) + InsertColumn(9, _T("Page Faults"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[9], -1); + if (TaskManagerSettings.Column_PageFaultsDelta) + InsertColumn(10, _T("PF Delta"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[10], -1); + if (TaskManagerSettings.Column_VirtualMemorySize) + InsertColumn(11, _T("VM Size"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[11], -1); + if (TaskManagerSettings.Column_PagedPool) + InsertColumn(12, _T("Paged Pool"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[12], -1); + if (TaskManagerSettings.Column_NonPagedPool) + InsertColumn(13, _T("NP Pool"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[13], -1); + if (TaskManagerSettings.Column_BasePriority) + InsertColumn(14, _T("Base Pri"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[14], -1); + if (TaskManagerSettings.Column_HandleCount) + InsertColumn(15, _T("Handles"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[15], -1); + if (TaskManagerSettings.Column_ThreadCount) + InsertColumn(16, _T("Threads"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[16], -1); + if (TaskManagerSettings.Column_USERObjects) + InsertColumn(17, _T("USER Objects"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[17], -1); + if (TaskManagerSettings.Column_GDIObjects) + InsertColumn(18, _T("GDI Objects"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[18], -1); + if (TaskManagerSettings.Column_IOReads) + InsertColumn(19, _T("I/O Reads"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[19], -1); + if (TaskManagerSettings.Column_IOWrites) + InsertColumn(20, _T("I/O Writes"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[20], -1); + if (TaskManagerSettings.Column_IOOther) + InsertColumn(21, _T("I/O Other"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[21], -1); + if (TaskManagerSettings.Column_IOReadBytes) + InsertColumn(22, _T("I/O Read Bytes"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[22], -1); + if (TaskManagerSettings.Column_IOWriteBytes) + InsertColumn(23, _T("I/O Write Bytes"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[23], -1); + if (TaskManagerSettings.Column_IOOtherBytes) + InsertColumn(24, _T("I/O Other Bytes"), LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[24], -1); + + size = SendMessage(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0); + SendMessage(hProcessPageHeaderCtrl, HDM_SETORDERARRAY, (WPARAM) size, (LPARAM) &TaskManagerSettings.ColumnOrderArray); + + UpdateColumnDataHints(); +} + +int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat, int nWidth, int nSubItem) +{ + LVCOLUMN column; + + column.mask = LVCF_TEXT|LVCF_FMT; + column.pszText = (LPTSTR)lpszColumnHeading; + column.fmt = nFormat; + + if (nWidth != -1) + { + column.mask |= LVCF_WIDTH; + column.cx = nWidth; + } + + if (nSubItem != -1) + { + column.mask |= LVCF_SUBITEM; + column.iSubItem = nSubItem; + } + + return ListView_InsertColumn(hProcessPageListCtrl, nCol, &column); +} + +void SaveColumnSettings(void) +{ + HDITEM hditem; + int i; + TCHAR text[260]; + int size; + + /* Reset column data */ + for (i=0; i<25; i++) + TaskManagerSettings.ColumnOrderArray[i] = i; + + TaskManagerSettings.Column_ImageName = FALSE; + TaskManagerSettings.Column_PID = FALSE; + TaskManagerSettings.Column_CPUUsage = FALSE; + TaskManagerSettings.Column_CPUTime = FALSE; + TaskManagerSettings.Column_MemoryUsage = FALSE; + TaskManagerSettings.Column_MemoryUsageDelta = FALSE; + TaskManagerSettings.Column_PeakMemoryUsage = FALSE; + TaskManagerSettings.Column_PageFaults = FALSE; + TaskManagerSettings.Column_USERObjects = FALSE; + TaskManagerSettings.Column_IOReads = FALSE; + TaskManagerSettings.Column_IOReadBytes = FALSE; + TaskManagerSettings.Column_SessionID = FALSE; + TaskManagerSettings.Column_UserName = FALSE; + TaskManagerSettings.Column_PageFaultsDelta = FALSE; + TaskManagerSettings.Column_VirtualMemorySize = FALSE; + TaskManagerSettings.Column_PagedPool = FALSE; + TaskManagerSettings.Column_NonPagedPool = FALSE; + TaskManagerSettings.Column_BasePriority = FALSE; + TaskManagerSettings.Column_HandleCount = FALSE; + TaskManagerSettings.Column_ThreadCount = FALSE; + TaskManagerSettings.Column_GDIObjects = FALSE; + TaskManagerSettings.Column_IOWrites = FALSE; + TaskManagerSettings.Column_IOWriteBytes = FALSE; + TaskManagerSettings.Column_IOOther = FALSE; + TaskManagerSettings.Column_IOOtherBytes = FALSE; + TaskManagerSettings.ColumnSizeArray[0] = 105; + TaskManagerSettings.ColumnSizeArray[1] = 50; + TaskManagerSettings.ColumnSizeArray[2] = 107; + TaskManagerSettings.ColumnSizeArray[3] = 70; + TaskManagerSettings.ColumnSizeArray[4] = 35; + TaskManagerSettings.ColumnSizeArray[5] = 70; + TaskManagerSettings.ColumnSizeArray[6] = 70; + TaskManagerSettings.ColumnSizeArray[7] = 100; + TaskManagerSettings.ColumnSizeArray[8] = 70; + TaskManagerSettings.ColumnSizeArray[9] = 70; + TaskManagerSettings.ColumnSizeArray[10] = 70; + TaskManagerSettings.ColumnSizeArray[11] = 70; + TaskManagerSettings.ColumnSizeArray[12] = 70; + TaskManagerSettings.ColumnSizeArray[13] = 70; + TaskManagerSettings.ColumnSizeArray[14] = 60; + TaskManagerSettings.ColumnSizeArray[15] = 60; + TaskManagerSettings.ColumnSizeArray[16] = 60; + TaskManagerSettings.ColumnSizeArray[17] = 60; + TaskManagerSettings.ColumnSizeArray[18] = 60; + TaskManagerSettings.ColumnSizeArray[19] = 70; + TaskManagerSettings.ColumnSizeArray[20] = 70; + TaskManagerSettings.ColumnSizeArray[21] = 70; + TaskManagerSettings.ColumnSizeArray[22] = 70; + TaskManagerSettings.ColumnSizeArray[23] = 70; + TaskManagerSettings.ColumnSizeArray[24] = 70; + + /* Get header order */ + size = SendMessage(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0); + SendMessage(hProcessPageHeaderCtrl, HDM_GETORDERARRAY, (WPARAM) size, (LPARAM) &TaskManagerSettings.ColumnOrderArray); + + /* Get visible columns */ + for (i=0; i=0; i--) + { + ListView_DeleteColumn(hProcessPageListCtrl, i); + } + + for (i=0; i<25; i++) + TaskManagerSettings.ColumnOrderArray[i] = i; + + TaskManagerSettings.ColumnSizeArray[0] = 105; + TaskManagerSettings.ColumnSizeArray[1] = 50; + TaskManagerSettings.ColumnSizeArray[2] = 107; + TaskManagerSettings.ColumnSizeArray[3] = 70; + TaskManagerSettings.ColumnSizeArray[4] = 35; + TaskManagerSettings.ColumnSizeArray[5] = 70; + TaskManagerSettings.ColumnSizeArray[6] = 70; + TaskManagerSettings.ColumnSizeArray[7] = 100; + TaskManagerSettings.ColumnSizeArray[8] = 70; + TaskManagerSettings.ColumnSizeArray[9] = 70; + TaskManagerSettings.ColumnSizeArray[10] = 70; + TaskManagerSettings.ColumnSizeArray[11] = 70; + TaskManagerSettings.ColumnSizeArray[12] = 70; + TaskManagerSettings.ColumnSizeArray[13] = 70; + TaskManagerSettings.ColumnSizeArray[14] = 60; + TaskManagerSettings.ColumnSizeArray[15] = 60; + TaskManagerSettings.ColumnSizeArray[16] = 60; + TaskManagerSettings.ColumnSizeArray[17] = 60; + TaskManagerSettings.ColumnSizeArray[18] = 60; + TaskManagerSettings.ColumnSizeArray[19] = 70; + TaskManagerSettings.ColumnSizeArray[20] = 70; + TaskManagerSettings.ColumnSizeArray[21] = 70; + TaskManagerSettings.ColumnSizeArray[22] = 70; + TaskManagerSettings.ColumnSizeArray[23] = 70; + TaskManagerSettings.ColumnSizeArray[24] = 70; + + AddColumns(); + } +} + +LRESULT CALLBACK ColumnsDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + + switch (message) + { + case WM_INITDIALOG: + + if (TaskManagerSettings.Column_ImageName) + SendMessage(GetDlgItem(hDlg, IDC_IMAGENAME), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_PID) + SendMessage(GetDlgItem(hDlg, IDC_PID), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_UserName) + SendMessage(GetDlgItem(hDlg, IDC_USERNAME), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_SessionID) + SendMessage(GetDlgItem(hDlg, IDC_SESSIONID), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_CPUUsage) + SendMessage(GetDlgItem(hDlg, IDC_CPUUSAGE), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_CPUTime) + SendMessage(GetDlgItem(hDlg, IDC_CPUTIME), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_MemoryUsage) + SendMessage(GetDlgItem(hDlg, IDC_MEMORYUSAGE), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_PeakMemoryUsage) + SendMessage(GetDlgItem(hDlg, IDC_PEAKMEMORYUSAGE), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_MemoryUsageDelta) + SendMessage(GetDlgItem(hDlg, IDC_MEMORYUSAGEDELTA), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_PageFaults) + SendMessage(GetDlgItem(hDlg, IDC_PAGEFAULTS), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_PageFaultsDelta) + SendMessage(GetDlgItem(hDlg, IDC_PAGEFAULTSDELTA), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_VirtualMemorySize) + SendMessage(GetDlgItem(hDlg, IDC_VIRTUALMEMORYSIZE), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_PagedPool) + SendMessage(GetDlgItem(hDlg, IDC_PAGEDPOOL), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_NonPagedPool) + SendMessage(GetDlgItem(hDlg, IDC_NONPAGEDPOOL), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_BasePriority) + SendMessage(GetDlgItem(hDlg, IDC_BASEPRIORITY), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_HandleCount) + SendMessage(GetDlgItem(hDlg, IDC_HANDLECOUNT), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_ThreadCount) + SendMessage(GetDlgItem(hDlg, IDC_THREADCOUNT), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_USERObjects) + SendMessage(GetDlgItem(hDlg, IDC_USEROBJECTS), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_GDIObjects) + SendMessage(GetDlgItem(hDlg, IDC_GDIOBJECTS), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_IOReads) + SendMessage(GetDlgItem(hDlg, IDC_IOREADS), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_IOWrites) + SendMessage(GetDlgItem(hDlg, IDC_IOWRITES), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_IOOther) + SendMessage(GetDlgItem(hDlg, IDC_IOOTHER), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_IOReadBytes) + SendMessage(GetDlgItem(hDlg, IDC_IOREADBYTES), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_IOWriteBytes) + SendMessage(GetDlgItem(hDlg, IDC_IOWRITEBYTES), BM_SETCHECK, BST_CHECKED, 0); + if (TaskManagerSettings.Column_IOOtherBytes) + SendMessage(GetDlgItem(hDlg, IDC_IOOTHERBYTES), BM_SETCHECK, BST_CHECKED, 0); + + return TRUE; + + case WM_COMMAND: + + if (LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + + if (LOWORD(wParam) == IDOK) + { + TaskManagerSettings.Column_ImageName = SendMessage(GetDlgItem(hDlg, IDC_IMAGENAME), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_PID = SendMessage(GetDlgItem(hDlg, IDC_PID), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_UserName = SendMessage(GetDlgItem(hDlg, IDC_USERNAME), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_SessionID = SendMessage(GetDlgItem(hDlg, IDC_SESSIONID), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_CPUUsage = SendMessage(GetDlgItem(hDlg, IDC_CPUUSAGE), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_CPUTime = SendMessage(GetDlgItem(hDlg, IDC_CPUTIME), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_MemoryUsage = SendMessage(GetDlgItem(hDlg, IDC_MEMORYUSAGE), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_PeakMemoryUsage = SendMessage(GetDlgItem(hDlg, IDC_PEAKMEMORYUSAGE), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_MemoryUsageDelta = SendMessage(GetDlgItem(hDlg, IDC_MEMORYUSAGEDELTA), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_PageFaults = SendMessage(GetDlgItem(hDlg, IDC_PAGEFAULTS), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_PageFaultsDelta = SendMessage(GetDlgItem(hDlg, IDC_PAGEFAULTSDELTA), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_VirtualMemorySize = SendMessage(GetDlgItem(hDlg, IDC_VIRTUALMEMORYSIZE), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_PagedPool = SendMessage(GetDlgItem(hDlg, IDC_PAGEDPOOL), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_NonPagedPool = SendMessage(GetDlgItem(hDlg, IDC_NONPAGEDPOOL), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_BasePriority = SendMessage(GetDlgItem(hDlg, IDC_BASEPRIORITY), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_HandleCount = SendMessage(GetDlgItem(hDlg, IDC_HANDLECOUNT), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_ThreadCount = SendMessage(GetDlgItem(hDlg, IDC_THREADCOUNT), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_USERObjects = SendMessage(GetDlgItem(hDlg, IDC_USEROBJECTS), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_GDIObjects = SendMessage(GetDlgItem(hDlg, IDC_GDIOBJECTS), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_IOReads = SendMessage(GetDlgItem(hDlg, IDC_IOREADS), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_IOWrites = SendMessage(GetDlgItem(hDlg, IDC_IOWRITES), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_IOOther = SendMessage(GetDlgItem(hDlg, IDC_IOOTHER), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_IOReadBytes = SendMessage(GetDlgItem(hDlg, IDC_IOREADBYTES), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_IOWriteBytes = SendMessage(GetDlgItem(hDlg, IDC_IOWRITEBYTES), BM_GETCHECK, 0, 0); + TaskManagerSettings.Column_IOOtherBytes = SendMessage(GetDlgItem(hDlg, IDC_IOOTHERBYTES), BM_GETCHECK, 0, 0); + + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + + break; + } + + return 0; +} + +void UpdateColumnDataHints(void) +{ + HDITEM hditem; + TCHAR text[260]; + ULONG Index; + + for (Index=0; Index<(ULONG)SendMessage(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0); Index++) + { + memset(&hditem, 0, sizeof(HDITEM)); + + hditem.mask = HDI_TEXT; + hditem.pszText = text; + hditem.cchTextMax = 260; + + SendMessage(hProcessPageHeaderCtrl, HDM_GETITEM, Index, (LPARAM) &hditem); + + if (_tcsicmp(text, _T("Image Name")) == 0) + ColumnDataHints[Index] = COLUMN_IMAGENAME; + if (_tcsicmp(text, _T("PID")) == 0) + ColumnDataHints[Index] = COLUMN_PID; + if (_tcsicmp(text, _T("Username")) == 0) + ColumnDataHints[Index] = COLUMN_USERNAME; + if (_tcsicmp(text, _T("Session ID")) == 0) + ColumnDataHints[Index] = COLUMN_SESSIONID; + if (_tcsicmp(text, _T("CPU")) == 0) + ColumnDataHints[Index] = COLUMN_CPUUSAGE; + if (_tcsicmp(text, _T("CPU Time")) == 0) + ColumnDataHints[Index] = COLUMN_CPUTIME; + if (_tcsicmp(text, _T("Mem Usage")) == 0) + ColumnDataHints[Index] = COLUMN_MEMORYUSAGE; + if (_tcsicmp(text, _T("Peak Mem Usage")) == 0) + ColumnDataHints[Index] = COLUMN_PEAKMEMORYUSAGE; + if (_tcsicmp(text, _T("Mem Delta")) == 0) + ColumnDataHints[Index] = COLUMN_MEMORYUSAGEDELTA; + if (_tcsicmp(text, _T("Page Faults")) == 0) + ColumnDataHints[Index] = COLUMN_PAGEFAULTS; + if (_tcsicmp(text, _T("PF Delta")) == 0) + ColumnDataHints[Index] = COLUMN_PAGEFAULTSDELTA; + if (_tcsicmp(text, _T("VM Size")) == 0) + ColumnDataHints[Index] = COLUMN_VIRTUALMEMORYSIZE; + if (_tcsicmp(text, _T("Paged Pool")) == 0) + ColumnDataHints[Index] = COLUMN_PAGEDPOOL; + if (_tcsicmp(text, _T("NP Pool")) == 0) + ColumnDataHints[Index] = COLUMN_NONPAGEDPOOL; + if (_tcsicmp(text, _T("Base Pri")) == 0) + ColumnDataHints[Index] = COLUMN_BASEPRIORITY; + if (_tcsicmp(text, _T("Handles")) == 0) + ColumnDataHints[Index] = COLUMN_HANDLECOUNT; + if (_tcsicmp(text, _T("Threads")) == 0) + ColumnDataHints[Index] = COLUMN_THREADCOUNT; + if (_tcsicmp(text, _T("USER Objects")) == 0) + ColumnDataHints[Index] = COLUMN_USEROBJECTS; + if (_tcsicmp(text, _T("GDI Objects")) == 0) + ColumnDataHints[Index] = COLUMN_GDIOBJECTS; + if (_tcsicmp(text, _T("I/O Reads")) == 0) + ColumnDataHints[Index] = COLUMN_IOREADS; + if (_tcsicmp(text, _T("I/O Writes")) == 0) + ColumnDataHints[Index] = COLUMN_IOWRITES; + if (_tcsicmp(text, _T("I/O Other")) == 0) + ColumnDataHints[Index] = COLUMN_IOOTHER; + if (_tcsicmp(text, _T("I/O Read Bytes")) == 0) + ColumnDataHints[Index] = COLUMN_IOREADBYTES; + if (_tcsicmp(text, _T("I/O Write Bytes")) == 0) + ColumnDataHints[Index] = COLUMN_IOWRITEBYTES; + if (_tcsicmp(text, _T("I/O Other Bytes")) == 0) + ColumnDataHints[Index] = COLUMN_IOOTHERBYTES; + } +} diff --git a/programs/taskmgr/column.h b/programs/taskmgr/column.h new file mode 100644 index 00000000000..7525c7b52c4 --- /dev/null +++ b/programs/taskmgr/column.h @@ -0,0 +1,59 @@ +/* + * ReactOS Task Manager + * + * column.h + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __COLUMN_H +#define __COLUMN_H + +#define COLUMN_IMAGENAME 0 +#define COLUMN_PID 1 +#define COLUMN_USERNAME 2 +#define COLUMN_SESSIONID 3 +#define COLUMN_CPUUSAGE 4 +#define COLUMN_CPUTIME 5 +#define COLUMN_MEMORYUSAGE 6 +#define COLUMN_PEAKMEMORYUSAGE 7 +#define COLUMN_MEMORYUSAGEDELTA 8 +#define COLUMN_PAGEFAULTS 9 +#define COLUMN_PAGEFAULTSDELTA 10 +#define COLUMN_VIRTUALMEMORYSIZE 11 +#define COLUMN_PAGEDPOOL 12 +#define COLUMN_NONPAGEDPOOL 13 +#define COLUMN_BASEPRIORITY 14 +#define COLUMN_HANDLECOUNT 15 +#define COLUMN_THREADCOUNT 16 +#define COLUMN_USEROBJECTS 17 +#define COLUMN_GDIOBJECTS 18 +#define COLUMN_IOREADS 19 +#define COLUMN_IOWRITES 20 +#define COLUMN_IOOTHER 21 +#define COLUMN_IOREADBYTES 22 +#define COLUMN_IOWRITEBYTES 23 +#define COLUMN_IOOTHERBYTES 24 + +extern UINT ColumnDataHints[25]; + +void ProcessPage_OnViewSelectColumns(void); +void AddColumns(void); +void SaveColumnSettings(void); +void UpdateColumnDataHints(void); + +#endif /* __COLUMN_H */ diff --git a/programs/taskmgr/dbgchnl.c b/programs/taskmgr/dbgchnl.c new file mode 100644 index 00000000000..cd2a96df690 --- /dev/null +++ b/programs/taskmgr/dbgchnl.c @@ -0,0 +1,368 @@ +/* + * ReactOS Task Manager + * + * dbgchnl.c + * + * Copyright (C) 2003 - 2004 Eric Pouech + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" +#include "column.h" +#include + +/* TODO: + * - the dialog box could be non modal + * - in that case, + * + could refresh channels from time to time + * + set the name of exec (and perhaps its pid) in dialog title + * - get a better UI (replace the 'x' by real tick boxes in list view) + * - enhance visual feedback: the list is large, and it's hard to get the + * right line when clicking on rightmost column (trace for example) + * - get rid of printfs (error reporting) and use real message boxes + * - include the column width settings in the full column management scheme + * - use more global settings (like having a temporary on/off + * setting for a fixme:s or err:s + */ + +static BOOL (WINAPI *pSymInitialize)(HANDLE, PSTR, BOOL); +static DWORD (WINAPI *pSymLoadModule)(HANDLE, HANDLE, PSTR, PSTR, DWORD, DWORD); +static BOOL (WINAPI *pSymCleanup)(HANDLE); +static BOOL (WINAPI *pSymFromName)(HANDLE, LPSTR, PSYMBOL_INFO); + +BOOL AreDebugChannelsSupported(void) +{ + static HANDLE hDbgHelp /* = NULL */; + + if (hDbgHelp) return TRUE; + + if (!(hDbgHelp = LoadLibrary("dbghelp.dll"))) return FALSE; + pSymInitialize = (void*)GetProcAddress(hDbgHelp, "SymInitialize"); + pSymLoadModule = (void*)GetProcAddress(hDbgHelp, "SymLoadModule"); + pSymFromName = (void*)GetProcAddress(hDbgHelp, "SymFromName"); + pSymCleanup = (void*)GetProcAddress(hDbgHelp, "SymCleanup"); + if (!pSymInitialize || !pSymLoadModule || !pSymCleanup || !pSymFromName) + { + FreeLibrary(hDbgHelp); + hDbgHelp = NULL; + return FALSE; + } + return TRUE; +} + +static DWORD get_selected_pid(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + + for (Index = 0; Index < (ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return 0; + return dwProcessId; +} + +static int list_channel_CB(HANDLE hProcess, void* addr, char* buffer, void* user) +{ + int j; + char val[2]; + LVITEMA lvi; + int index; + HWND hChannelLV = (HWND)user; + + memset(&lvi, 0, sizeof(lvi)); + + lvi.mask = LVIF_TEXT; + lvi.pszText = buffer + 1; + + index = ListView_InsertItem(hChannelLV, &lvi); + if (index == -1) return 0; + + val[1] = '\0'; + for (j = 0; j < 4; j++) + { + val[0] = (buffer[0] & (1 << j)) ? 'x' : ' '; + ListView_SetItemText(hChannelLV, index, j + 1, val); + } + return 1; +} + +struct cce_user +{ + const char* name; /* channel to look for */ + unsigned value, mask; /* how to change channel */ + unsigned done; /* number of successful changes */ + unsigned notdone; /* number of unsuccessful changes */ +}; + +/****************************************************************** + * change_channel_CB + * + * Callback used for changing a given channel attributes + */ +static int change_channel_CB(HANDLE hProcess, void* addr, char* buffer, void* pmt) +{ + struct cce_user* user = (struct cce_user*)pmt; + + if (!user->name || !strcmp(buffer + 1, user->name)) + { + buffer[0] = (buffer[0] & ~user->mask) | (user->value & user->mask); + if (WriteProcessMemory(hProcess, addr, buffer, 1, NULL)) + user->done++; + else + user->notdone++; + } + return 1; +} + +void* get_symbol(HANDLE hProcess, char* name, char* lib) +{ + char buffer[sizeof(IMAGEHLP_SYMBOL) + 256]; + SYMBOL_INFO* si = (SYMBOL_INFO*)buffer; + void* ret = NULL; + + if (pSymInitialize(hProcess, NULL, FALSE)) + { + si->SizeOfStruct = sizeof(*si); + si->MaxNameLen = sizeof(buffer) - sizeof(IMAGEHLP_SYMBOL); + if (pSymLoadModule(hProcess, NULL, lib, NULL, 0, 0) && + pSymFromName(hProcess, name, si)) + ret = (void*)si->Address; + pSymCleanup(hProcess); + } + return ret; +} + +struct dll_option_layout +{ + void* next; + void* prev; + char* const* channels; + int nb_channels; +}; + +typedef int (*EnumChannelCB)(HANDLE, void*, char*, void*); + +/****************************************************************** + * enum_channel + * + * Enumerates all known channels on process hProcess through callback + * ce. + */ +static int enum_channel(HANDLE hProcess, EnumChannelCB ce, void* user, unsigned unique) +{ + struct dll_option_layout dol; + int i, j, ret = 1; + void* buf_addr; + unsigned char buffer[32]; + void* addr; + const char** cache = NULL; + unsigned num_cache, used_cache; + + if (!(addr = get_symbol(hProcess, "first_dll", "libwine.so"))) return -1; + if (unique) + cache = HeapAlloc(GetProcessHeap(), 0, (num_cache = 32) * sizeof(char*)); + else + num_cache = 0; + used_cache = 0; + + for (; + ret && addr && ReadProcessMemory(hProcess, addr, &dol, sizeof(dol), NULL); + addr = dol.next) + { + for (i = 0; i < dol.nb_channels; i++) + { + if (ReadProcessMemory(hProcess, (void*)(dol.channels + i), &buf_addr, sizeof(buf_addr), NULL) && + ReadProcessMemory(hProcess, buf_addr, buffer, sizeof(buffer), NULL)) + { + if (unique) + { + /* since some channels are defined in multiple compilation units, + * they will appear several times... + * so cache the channel's names we already reported and don't report + * them again + */ + for (j = 0; j < used_cache; j++) + if (!strcmp(cache[j], buffer + 1)) break; + if (j != used_cache) continue; + if (used_cache == num_cache) + cache = HeapReAlloc(GetProcessHeap(), 0, cache, (num_cache *= 2) * sizeof(char*)); + cache[used_cache++] = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(buffer + 1) + 1), + buffer + 1); + } + ret = ce(hProcess, buf_addr, buffer, user); + } + } + } + if (unique) + { + for (j = 0; j < used_cache; j++) HeapFree(GetProcessHeap(), 0, (char*)cache[j]); + HeapFree(GetProcessHeap(), 0, cache); + } + return 0; +} + +static void DebugChannels_FillList(HWND hChannelLV) +{ + HANDLE hProcess; + + ListView_DeleteAllItems(hChannelLV); + + hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ, FALSE, get_selected_pid()); + if (!hProcess) return; /* FIXME messagebox */ + SendMessage(hChannelLV, WM_SETREDRAW, FALSE, 0); + enum_channel(hProcess, list_channel_CB, (void*)hChannelLV, TRUE); + SendMessage(hChannelLV, WM_SETREDRAW, TRUE, 0); + CloseHandle(hProcess); +} + +static void DebugChannels_OnCreate(HWND hwndDlg) +{ + HWND hLV = GetDlgItem(hwndDlg, IDC_DEBUG_CHANNELS_LIST); + LVCOLUMN lvc; + + lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt = LVCFMT_LEFT; + lvc.pszText = _T("Debug Channel"); + lvc.cx = 100; + ListView_InsertColumn(hLV, 0, &lvc); + + lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt = LVCFMT_CENTER; + lvc.pszText = _T("Fixme"); + lvc.cx = 55; + ListView_InsertColumn(hLV, 1, &lvc); + + lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt = LVCFMT_CENTER; + lvc.pszText = _T("Err"); + lvc.cx = 55; + ListView_InsertColumn(hLV, 2, &lvc); + + lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt = LVCFMT_CENTER; + lvc.pszText = _T("Warn"); + lvc.cx = 55; + ListView_InsertColumn(hLV, 3, &lvc); + + lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt = LVCFMT_CENTER; + lvc.pszText = _T("Trace"); + lvc.cx = 55; + ListView_InsertColumn(hLV, 4, &lvc); + + DebugChannels_FillList(hLV); +} + +static void DebugChannels_OnNotify(HWND hDlg, LPARAM lParam) +{ + NMHDR* nmh = (NMHDR*)lParam; + + switch (nmh->code) + { + case NM_CLICK: + if (nmh->idFrom == IDC_DEBUG_CHANNELS_LIST) + { + LVHITTESTINFO lhti; + HWND hChannelLV; + HANDLE hProcess; + NMITEMACTIVATE* nmia = (NMITEMACTIVATE*)lParam; + + hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, get_selected_pid()); + if (!hProcess) return; /* FIXME message box */ + lhti.pt = nmia->ptAction; + hChannelLV = GetDlgItem(hDlg, IDC_DEBUG_CHANNELS_LIST); + SendMessage(hChannelLV, LVM_SUBITEMHITTEST, 0, (LPARAM)&lhti); + if (nmia->iSubItem >= 1 && nmia->iSubItem <= 4) + { + TCHAR val[2]; + TCHAR name[32]; + unsigned bitmask = 1 << (lhti.iSubItem - 1); + struct cce_user user; + + ListView_GetItemText(hChannelLV, lhti.iItem, 0, name, sizeof(name) / sizeof(name[0])); + ListView_GetItemText(hChannelLV, lhti.iItem, lhti.iSubItem, val, sizeof(val) / sizeof(val[0])); + user.name = name; + user.value = (val[0] == 'x') ? 0 : bitmask; + user.mask = bitmask; + user.done = user.notdone = 0; + enum_channel(hProcess, change_channel_CB, &user, FALSE); + if (user.done) + { + val[0] ^= ('x' ^ ' '); + ListView_SetItemText(hChannelLV, lhti.iItem, lhti.iSubItem, val); + } + if (user.notdone) + printf("Some channel instance weren't correctly set\n"); + } + CloseHandle(hProcess); + } + break; + } +} + +static LRESULT CALLBACK DebugChannelsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG: + DebugChannels_OnCreate(hDlg); + return TRUE; + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + break; + case WM_NOTIFY: + DebugChannels_OnNotify(hDlg, lParam); + break; + } + return FALSE; +} + +void ProcessPage_OnDebugChannels(void) +{ + DialogBox(hInst, (LPCTSTR)IDD_DEBUG_CHANNELS_DIALOG, hMainWnd, (DLGPROC)DebugChannelsDlgProc); +} diff --git a/programs/taskmgr/debug.c b/programs/taskmgr/debug.c new file mode 100644 index 00000000000..2dfab7b8182 --- /dev/null +++ b/programs/taskmgr/debug.c @@ -0,0 +1,114 @@ +/* + * ReactOS Task Manager + * + * debug.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" + +void ProcessPage_OnDebug(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + TCHAR strErrorText[260]; + HKEY hKey; + TCHAR strDebugPath[260]; + TCHAR strDebugger[260]; + DWORD dwDebuggerSize; + PROCESS_INFORMATION pi; + STARTUPINFO si; + HANDLE hDebugEvent; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Debugging this process may result in loss of data.\nAre you sure you wish to attach the debugger?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP); + return; + } + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) != ERROR_SUCCESS) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP); + return; + } + + dwDebuggerSize = 260; + if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP); + RegCloseKey(hKey); + return; + } + + RegCloseKey(hKey); + + hDebugEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!hDebugEvent) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP); + return; + } + + wsprintf(strDebugPath, strDebugger, dwProcessId, hDebugEvent); + + memset(&pi, 0, sizeof(PROCESS_INFORMATION)); + memset(&si, 0, sizeof(STARTUPINFO)); + si.cb = sizeof(STARTUPINFO); + if (!CreateProcess(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hDebugEvent); +} diff --git a/programs/taskmgr/endproc.c b/programs/taskmgr/endproc.c new file mode 100644 index 00000000000..13853f6164b --- /dev/null +++ b/programs/taskmgr/endproc.c @@ -0,0 +1,130 @@ +/* + * ReactOS Task Manager + * + * endproc.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" + +void ProcessPage_OnEndProcess(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Terminating a process can cause undesired\nresults including loss of data and system instability. The\nprocess will not be given the chance to save its state or\ndata before it is terminated. Are you sure you want to\nterminate the process?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP); + return; + } + + if (!TerminateProcess(hProcess, 0)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} + +void ProcessPage_OnEndProcessTree(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Terminating a process can cause undesired\nresults including loss of data and system instability. The\nprocess will not be given the chance to save its state or\ndata before it is terminated. Are you sure you want to\nterminate the process?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP); + return; + } + + if (!TerminateProcess(hProcess, 0)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} diff --git a/programs/taskmgr/graph.c b/programs/taskmgr/graph.c new file mode 100644 index 00000000000..4db1d8756dc --- /dev/null +++ b/programs/taskmgr/graph.c @@ -0,0 +1,474 @@ +/* + * ReactOS Task Manager + * + * graph.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" + +#define BRIGHT_GREEN RGB(0, 255, 0) +#define DARK_GREEN RGB(0, 130, 0) +#define RED RGB(255, 0, 0) + + +LONG OldGraphWndProc; + +void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd); +void Graph_DrawMemUsageGraph(HDC hDC, HWND hWnd); +void Graph_DrawMemUsageHistoryGraph(HDC hDC, HWND hWnd); + +LRESULT CALLBACK Graph_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HDC hdc; + PAINTSTRUCT ps; + LONG WindowId; + + switch (message) + { + case WM_ERASEBKGND: + return TRUE; + + /* + * Filter out mouse & keyboard messages + */ + /* case WM_APPCOMMAND: */ + case WM_CAPTURECHANGED: + case WM_LBUTTONDBLCLK: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_MBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_MOUSEACTIVATE: + case WM_MOUSEHOVER: + case WM_MOUSELEAVE: + case WM_MOUSEMOVE: + /* case WM_MOUSEWHEEL: */ + case WM_NCHITTEST: + case WM_NCLBUTTONDBLCLK: + case WM_NCLBUTTONDOWN: + case WM_NCLBUTTONUP: + case WM_NCMBUTTONDBLCLK: + case WM_NCMBUTTONDOWN: + case WM_NCMBUTTONUP: + /* case WM_NCMOUSEHOVER: */ + /* case WM_NCMOUSELEAVE: */ + case WM_NCMOUSEMOVE: + case WM_NCRBUTTONDBLCLK: + case WM_NCRBUTTONDOWN: + case WM_NCRBUTTONUP: + /* case WM_NCXBUTTONDBLCLK: */ + /* case WM_NCXBUTTONDOWN: */ + /* case WM_NCXBUTTONUP: */ + case WM_RBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + /* case WM_XBUTTONDBLCLK: */ + /* case WM_XBUTTONDOWN: */ + /* case WM_XBUTTONUP: */ + case WM_ACTIVATE: + case WM_CHAR: + case WM_DEADCHAR: + case WM_GETHOTKEY: + case WM_HOTKEY: + case WM_KEYDOWN: + case WM_KEYUP: + case WM_KILLFOCUS: + case WM_SETFOCUS: + case WM_SETHOTKEY: + case WM_SYSCHAR: + case WM_SYSDEADCHAR: + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + + case WM_NCCALCSIZE: + return 0; + + case WM_PAINT: + + hdc = BeginPaint(hWnd, &ps); + + WindowId = GetWindowLong(hWnd, GWL_ID); + + switch (WindowId) + { + case IDC_CPU_USAGE_GRAPH: + Graph_DrawCpuUsageGraph(hdc, hWnd); + break; + case IDC_MEM_USAGE_GRAPH: + Graph_DrawMemUsageGraph(hdc, hWnd); + break; + case IDC_MEM_USAGE_HISTORY_GRAPH: + Graph_DrawMemUsageHistoryGraph(hdc, hWnd); + break; + } + + EndPaint(hWnd, &ps); + + return 0; + + } + + /* + * We pass on all non-handled messages + */ + return CallWindowProc((WNDPROC)OldGraphWndProc, hWnd, message, wParam, lParam); +} + +void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) +{ + RECT rcClient; + RECT rcBarLeft; + RECT rcBarRight; + TCHAR Text[260]; + ULONG CpuUsage; + ULONG CpuKernelUsage; + int nBars; + int nBarsUsed; +/* Bottom bars that are "used", i.e. are bright green, representing used cpu time */ + int nBarsUsedKernel; +/* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */ + int nBarsFree; +/* Top bars that are "unused", i.e. are dark green, representing free cpu time */ + int i; + + /* + * Get the client area rectangle + */ + GetClientRect(hWnd, &rcClient); + + /* + * Fill it with blackness + */ + FillSolidRect(hDC, &rcClient, RGB(0, 0, 0)); + + /* + * Get the CPU usage + */ + CpuUsage = PerfDataGetProcessorUsage(); + CpuKernelUsage = PerfDataGetProcessorSystemUsage(); + if (CpuUsage < 0) CpuUsage = 0; + if (CpuUsage > 100) CpuUsage = 100; + if (CpuKernelUsage < 0) CpuKernelUsage = 0; + if (CpuKernelUsage > 100) CpuKernelUsage = 100; + + /* + * Check and see how many digits it will take + * so we get the indentation right every time. + */ + if (CpuUsage == 100) + { + _stprintf(Text, _T("%d%%"), (int)CpuUsage); + } + else if (CpuUsage < 10) + { + _stprintf(Text, _T(" %d%%"), (int)CpuUsage); + } + else + { + _stprintf(Text, _T(" %d%%"), (int)CpuUsage); + } + + /* + * Draw the font text onto the graph + * The bottom 20 pixels are reserved for the text + */ + Font_DrawText(hDC, Text, ((rcClient.right - rcClient.left) - 32) / 2, rcClient.bottom - 11 - 5); + + /* + * Now we have to draw the graph + * So first find out how many bars we can fit + */ + nBars = ((rcClient.bottom - rcClient.top) - 25) / 3; + nBarsUsed = (nBars * CpuUsage) / 100; + if ((CpuUsage) && (nBarsUsed == 0)) + { + nBarsUsed = 1; + } + nBarsFree = nBars - nBarsUsed; + if (TaskManagerSettings.ShowKernelTimes) + { + nBarsUsedKernel = ((nBars * 2) * CpuKernelUsage) / 100; + nBarsUsed -= (nBarsUsedKernel / 2); + } + else + { + nBarsUsedKernel = 0; + } + + /* + * Now draw the bar graph + */ + rcBarLeft.left = ((rcClient.right - rcClient.left) - 33) / 2; + rcBarLeft.right = rcBarLeft.left + 16; + rcBarRight.left = rcBarLeft.left + 17; + rcBarRight.right = rcBarLeft.right + 17; + rcBarLeft.top = rcBarRight.top = 5; + rcBarLeft.bottom = rcBarRight.bottom = 7; + + if (nBarsUsed < 0) nBarsUsed = 0; + if (nBarsUsed > nBars) nBarsUsed = nBars; + + if (nBarsFree < 0) nBarsFree = 0; + if (nBarsFree > nBars) nBarsFree = nBars; + + if (nBarsUsedKernel < 0) nBarsUsedKernel = 0; + if (nBarsUsedKernel > nBars) nBarsUsedKernel = nBars; + + /* + * Draw the "free" bars + */ + for (i=0; i 5000) nBarsUsed = 5000; + + FillSolidRect(hDC, &rcBarLeft, BRIGHT_GREEN); + FillSolidRect(hDC, &rcBarRight, BRIGHT_GREEN); + + rcBarLeft.top += 3; + rcBarLeft.bottom += 3; + + rcBarRight.top += 3; + rcBarRight.bottom += 3; + } + + /* + * Draw the "used" kernel bars + */ + rcBarLeft.bottom--; + rcBarRight.bottom--; + if (nBarsUsedKernel && nBarsUsedKernel % 2) + { + rcBarLeft.top -= 2; + rcBarLeft.bottom -= 2; + + rcBarRight.top -= 2; + rcBarRight.bottom -= 2; + + FillSolidRect(hDC, &rcBarLeft, RED); + FillSolidRect(hDC, &rcBarRight, RED); + + rcBarLeft.top += 2; + rcBarLeft.bottom += 2; + + rcBarRight.top += 2; + rcBarRight.bottom += 2; + + nBarsUsedKernel--; + } + for (i=0; i 5000) nBarsUsedKernel = 5000; + + FillSolidRect(hDC, &rcBarLeft, RED); + FillSolidRect(hDC, &rcBarRight, RED); + + rcBarLeft.top++; + rcBarLeft.bottom++; + + rcBarRight.top++; + rcBarRight.bottom++; + + if (i % 2) + { + rcBarLeft.top++; + rcBarLeft.bottom++; + + rcBarRight.top++; + rcBarRight.bottom++; + } + } +} + +void Graph_DrawMemUsageGraph(HDC hDC, HWND hWnd) +{ + RECT rcClient; + RECT rcBarLeft; + RECT rcBarRight; + TCHAR Text[260]; + ULONGLONG CommitChargeTotal; + ULONGLONG CommitChargeLimit; + int nBars; + int nBarsUsed = 0; +/* Bottom bars that are "used", i.e. are bright green, representing used memory */ + int nBarsFree; +/* Top bars that are "unused", i.e. are dark green, representing free memory */ + int i; + + /* + * Get the client area rectangle + */ + GetClientRect(hWnd, &rcClient); + + /* + * Fill it with blackness + */ + FillSolidRect(hDC, &rcClient, RGB(0, 0, 0)); + + /* + * Get the memory usage + */ + CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK(); + CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); + + _stprintf(Text, _T("%dK"), (int)CommitChargeTotal); + + /* + * Draw the font text onto the graph + * The bottom 20 pixels are reserved for the text + */ + Font_DrawText(hDC, Text, ((rcClient.right - rcClient.left) - (_tcslen(Text) * 8)) / 2, rcClient.bottom - 11 - 5); + + /* + * Now we have to draw the graph + * So first find out how many bars we can fit + */ + nBars = ((rcClient.bottom - rcClient.top) - 25) / 3; + if (CommitChargeLimit) + nBarsUsed = (nBars * (int)((CommitChargeTotal * 100) / CommitChargeLimit)) / 100; + nBarsFree = nBars - nBarsUsed; + + if (nBarsUsed < 0) nBarsUsed = 0; + if (nBarsUsed > nBars) nBarsUsed = nBars; + + if (nBarsFree < 0) nBarsFree = 0; + if (nBarsFree > nBars) nBarsFree = nBars; + + /* + * Now draw the bar graph + */ + rcBarLeft.left = ((rcClient.right - rcClient.left) - 33) / 2; + rcBarLeft.right = rcBarLeft.left + 16; + rcBarRight.left = rcBarLeft.left + 17; + rcBarRight.right = rcBarLeft.right + 17; + rcBarLeft.top = rcBarRight.top = 5; + rcBarLeft.bottom = rcBarRight.bottom = 7; + + /* + * Draw the "free" bars + */ + for (i=0; i= 10) + offset = 0; + + /* + * Get the client area rectangle + */ + GetClientRect(hWnd, &rcClient); + + /* + * Fill it with blackness + */ + FillSolidRect(hDC, &rcClient, RGB(0, 0, 0)); + + /* + * Get the memory usage + */ + CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); + + /* + * Draw the graph background + * + * Draw the horizontal bars + */ + for (i=0; i=0; i--) + { + } +} diff --git a/programs/taskmgr/graphctl.c b/programs/taskmgr/graphctl.c new file mode 100644 index 00000000000..adfde9003a4 --- /dev/null +++ b/programs/taskmgr/graphctl.c @@ -0,0 +1,630 @@ +/* + * ReactOS Task Manager + * + * graphctl.c + * + * Copyright (C) 2002 Robert Dickenson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include "graphctl.h" +#include "taskmgr.h" + +LONG OldGraphCtrlWndProc; + +static void GraphCtrl_Init(TGraphCtrl* this) +{ + int i; + + this->m_hWnd = 0; + this->m_hParentWnd = 0; + this->m_dcGrid = 0; + this->m_dcPlot = 0; + this->m_bitmapOldGrid = 0; + this->m_bitmapOldPlot = 0; + this->m_bitmapGrid = 0; + this->m_bitmapPlot = 0; + this->m_brushBack = 0; + + this->m_penPlot[0] = 0; + this->m_penPlot[1] = 0; + this->m_penPlot[2] = 0; + this->m_penPlot[3] = 0; + + /* since plotting is based on a LineTo for each new point + * we need a starting point (i.e. a "previous" point) + * use 0.0 as the default first point. + * these are public member variables, and can be changed outside + * (after construction). Therefore m_perviousPosition could be set to + * a more appropriate value prior to the first call to SetPosition. + */ + this->m_dPreviousPosition[0] = 0.0; + this->m_dPreviousPosition[1] = 0.0; + this->m_dPreviousPosition[2] = 0.0; + this->m_dPreviousPosition[3] = 0.0; + + /* public variable for the number of decimal places on the y axis */ + this->m_nYDecimals = 3; + + /* set some initial values for the scaling until "SetRange" is called. + * these are protected varaibles and must be set with SetRange + * in order to ensure that m_dRange is updated accordingly + */ + /* m_dLowerLimit = -10.0; */ + /* m_dUpperLimit = 10.0; */ + this->m_dLowerLimit = 0.0; + this->m_dUpperLimit = 100.0; + this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit; /* protected member variable */ + + /* m_nShiftPixels determines how much the plot shifts (in terms of pixels) */ + /* with the addition of a new data point */ + this->m_nShiftPixels = 4; + this->m_nHalfShiftPixels = this->m_nShiftPixels/2; /* protected */ + this->m_nPlotShiftPixels = this->m_nShiftPixels + this->m_nHalfShiftPixels; /* protected */ + + /* background, grid and data colors */ + /* these are public variables and can be set directly */ + this->m_crBackColor = RGB( 0, 0, 0); /* see also SetBackgroundColor */ + this->m_crGridColor = RGB( 0, 255, 255); /* see also SetGridColor */ + this->m_crPlotColor[0] = RGB(255, 255, 255); /* see also SetPlotColor */ + this->m_crPlotColor[1] = RGB(100, 255, 255); /* see also SetPlotColor */ + this->m_crPlotColor[2] = RGB(255, 100, 255); /* see also SetPlotColor */ + this->m_crPlotColor[3] = RGB(255, 255, 100); /* see also SetPlotColor */ + + /* protected variables */ + for (i = 0; i < MAX_PLOTS; i++) + { + this->m_penPlot[i] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[i]); + } + this->m_brushBack = CreateSolidBrush(this->m_crBackColor); + + /* public member variables, can be set directly */ + strcpy(this->m_strXUnitsString, "Samples"); /* can also be set with SetXUnits */ + strcpy(this->m_strYUnitsString, "Y units"); /* can also be set with SetYUnits */ + + /* protected bitmaps to restore the memory DC's */ + this->m_bitmapOldGrid = NULL; + this->m_bitmapOldPlot = NULL; +} + +#if 0 +TGraphCtrl::~TGraphCtrl() +{ + /* just to be picky restore the bitmaps for the two memory dc's */ + /* (these dc's are being destroyed so there shouldn't be any leaks) */ + if (m_bitmapOldGrid != NULL) SelectObject(m_dcGrid, m_bitmapOldGrid); + if (m_bitmapOldPlot != NULL) SelectObject(m_dcPlot, m_bitmapOldPlot); + if (m_bitmapGrid != NULL) DeleteObject(m_bitmapGrid); + if (m_bitmapPlot != NULL) DeleteObject(m_bitmapPlot); + if (m_dcGrid != NULL) DeleteDC(m_dcGrid); + if (m_dcPlot != NULL) DeleteDC(m_dcPlot); + if (m_brushBack != NULL) DeleteObject(m_brushBack); +} +#endif + +BOOL GraphCtrl_Create(TGraphCtrl* this, HWND hWnd, HWND hParentWnd, UINT nID) +{ + BOOL result = 0; + + GraphCtrl_Init(this); + this->m_hParentWnd = hParentWnd; + this->m_hWnd = hWnd; + GraphCtrl_Resize(this); + if (result != 0) + GraphCtrl_InvalidateCtrl(this); + return result; +} + +void GraphCtrl_SetRange(TGraphCtrl* this, double dLower, double dUpper, int nDecimalPlaces) +{ + /* ASSERT(dUpper > dLower); */ + this->m_dLowerLimit = dLower; + this->m_dUpperLimit = dUpper; + this->m_nYDecimals = nDecimalPlaces; + this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit; + this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange; + /* clear out the existing garbage, re-start with a clean plot */ + GraphCtrl_InvalidateCtrl(this); +} + +#if 0 +void TGraphCtrl::SetXUnits(const char* string) +{ + strncpy(m_strXUnitsString, string, sizeof(m_strXUnitsString) - 1); + /* clear out the existing garbage, re-start with a clean plot */ + InvalidateCtrl(); +} + +void TGraphCtrl::SetYUnits(const char* string) +{ + strncpy(m_strYUnitsString, string, sizeof(m_strYUnitsString) - 1); + /* clear out the existing garbage, re-start with a clean plot */ + InvalidateCtrl(); +} +#endif + +void GraphCtrl_SetGridColor(TGraphCtrl* this, COLORREF color) +{ + this->m_crGridColor = color; + /* clear out the existing garbage, re-start with a clean plot */ + GraphCtrl_InvalidateCtrl(this); +} + +void GraphCtrl_SetPlotColor(TGraphCtrl* this, int plot, COLORREF color) +{ + this->m_crPlotColor[plot] = color; + DeleteObject(this->m_penPlot[plot]); + this->m_penPlot[plot] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[plot]); + /* clear out the existing garbage, re-start with a clean plot */ + GraphCtrl_InvalidateCtrl(this); +} + +void GraphCtrl_SetBackgroundColor(TGraphCtrl* this, COLORREF color) +{ + this->m_crBackColor = color; + DeleteObject(this->m_brushBack); + this->m_brushBack = CreateSolidBrush(this->m_crBackColor); + /* clear out the existing garbage, re-start with a clean plot */ + GraphCtrl_InvalidateCtrl(this); +} + +void GraphCtrl_InvalidateCtrl(TGraphCtrl* this) +{ + /* There is a lot of drawing going on here - particularly in terms of */ + /* drawing the grid. Don't panic, this is all being drawn (only once) */ + /* to a bitmap. The result is then BitBlt'd to the control whenever needed. */ + int i, j; + int nCharacters; + int nTopGridPix, nMidGridPix, nBottomGridPix; + + HPEN oldPen; + HPEN solidPen = CreatePen(PS_SOLID, 0, this->m_crGridColor); + /* HFONT axisFont, yUnitFont, oldFont; */ + /* char strTemp[50]; */ + + /* in case we haven't established the memory dc's */ + /* CClientDC dc(this); */ + HDC dc = GetDC(this->m_hParentWnd); + + /* if we don't have one yet, set up a memory dc for the grid */ + if (this->m_dcGrid == NULL) + { + this->m_dcGrid = CreateCompatibleDC(dc); + this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); + this->m_bitmapOldGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapGrid); + } + + SetBkColor(this->m_dcGrid, this->m_crBackColor); + + /* fill the grid background */ + FillRect(this->m_dcGrid, &this->m_rectClient, this->m_brushBack); + + /* draw the plot rectangle: */ + /* determine how wide the y axis scaling values are */ + nCharacters = abs((int)log10(fabs(this->m_dUpperLimit))); + nCharacters = max(nCharacters, abs((int)log10(fabs(this->m_dLowerLimit)))); + + /* add the units digit, decimal point and a minus sign, and an extra space */ + /* as well as the number of decimal places to display */ + nCharacters = nCharacters + 4 + this->m_nYDecimals; + + /* adjust the plot rectangle dimensions */ + /* assume 6 pixels per character (this may need to be adjusted) */ + /* m_rectPlot.left = m_rectClient.left + 6*(nCharacters); */ + this->m_rectPlot.left = this->m_rectClient.left; + this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;/* m_rectPlot.Width(); */ + + /* draw the plot rectangle */ + oldPen = (HPEN)SelectObject(this->m_dcGrid, solidPen); + MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top, NULL); + LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.top); + LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.bottom+1); + LineTo(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.bottom+1); + /* LineTo(m_dcGrid, m_rectPlot.left, m_rectPlot.top); */ + SelectObject(this->m_dcGrid, oldPen); + DeleteObject(solidPen); + + /* draw the dotted lines, + * use SetPixel instead of a dotted pen - this allows for a + * finer dotted line and a more "technical" look + */ + nMidGridPix = (this->m_rectPlot.top + this->m_rectPlot.bottom)/2; + nTopGridPix = nMidGridPix - this->m_nPlotHeight/4; + nBottomGridPix = nMidGridPix + this->m_nPlotHeight/4; + + for (i=this->m_rectPlot.left; im_rectPlot.right; i+=2) + { + SetPixel(this->m_dcGrid, i, nTopGridPix, this->m_crGridColor); + SetPixel(this->m_dcGrid, i, nMidGridPix, this->m_crGridColor); + SetPixel(this->m_dcGrid, i, nBottomGridPix, this->m_crGridColor); + } + + for (i=this->m_rectPlot.left; im_rectPlot.right; i+=10) + { + for (j=this->m_rectPlot.top; jm_rectPlot.bottom; j+=2) + { + SetPixel(this->m_dcGrid, i, j, this->m_crGridColor); + /* SetPixel(m_dcGrid, i, j, m_crGridColor); */ + /* SetPixel(m_dcGrid, i, j, m_crGridColor); */ + } + } + +#if 0 + /* create some fonts (horizontal and vertical) */ + /* use a height of 14 pixels and 300 weight */ + /* (these may need to be adjusted depending on the display) */ + axisFont = CreateFont (14, 0, 0, 0, 300, + FALSE, FALSE, 0, ANSI_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + DEFAULT_PITCH|FF_SWISS, "Arial"); + yUnitFont = CreateFont (14, 0, 900, 0, 300, + FALSE, FALSE, 0, ANSI_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + DEFAULT_PITCH|FF_SWISS, "Arial"); + + /* grab the horizontal font */ + oldFont = (HFONT)SelectObject(m_dcGrid, axisFont); + + /* y max */ + SetTextColor(m_dcGrid, m_crGridColor); + SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP); + sprintf(strTemp, "%.*lf", m_nYDecimals, m_dUpperLimit); + TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.top, strTemp, _tcslen(strTemp)); + + /* y min */ + SetTextAlign(m_dcGrid, TA_RIGHT|TA_BASELINE); + sprintf(strTemp, "%.*lf", m_nYDecimals, m_dLowerLimit); + TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.bottom, strTemp, _tcslen(strTemp)); + + /* x min */ + SetTextAlign(m_dcGrid, TA_LEFT|TA_TOP); + TextOut(m_dcGrid, m_rectPlot.left, m_rectPlot.bottom+4, "0", 1); + + /* x max */ + SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP); + sprintf(strTemp, "%d", m_nPlotWidth/m_nShiftPixels); + TextOut(m_dcGrid, m_rectPlot.right, m_rectPlot.bottom+4, strTemp, _tcslen(strTemp)); + + /* x units */ + SetTextAlign(m_dcGrid, TA_CENTER|TA_TOP); + TextOut(m_dcGrid, (m_rectPlot.left+m_rectPlot.right)/2, + m_rectPlot.bottom+4, m_strXUnitsString, _tcslen(m_strXUnitsString)); + + /* restore the font */ + SelectObject(m_dcGrid, oldFont); + + /* y units */ + oldFont = (HFONT)SelectObject(m_dcGrid, yUnitFont); + SetTextAlign(m_dcGrid, TA_CENTER|TA_BASELINE); + TextOut(m_dcGrid, (m_rectClient.left+m_rectPlot.left)/2, + (m_rectPlot.bottom+m_rectPlot.top)/2, m_strYUnitsString, _tcslen(m_strYUnitsString)); + SelectObject(m_dcGrid, oldFont); +#endif + /* at this point we are done filling the the grid bitmap, */ + /* no more drawing to this bitmap is needed until the setting are changed */ + + /* if we don't have one yet, set up a memory dc for the plot */ + if (this->m_dcPlot == NULL) + { + this->m_dcPlot = CreateCompatibleDC(dc); + this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); + this->m_bitmapOldPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapPlot); + } + + /* make sure the plot bitmap is cleared */ + SetBkColor(this->m_dcPlot, this->m_crBackColor); + FillRect(this->m_dcPlot, &this->m_rectClient, this->m_brushBack); + + /* finally, force the plot area to redraw */ + InvalidateRect(this->m_hParentWnd, &this->m_rectClient, TRUE); + ReleaseDC(this->m_hParentWnd, dc); +} + +double GraphCtrl_AppendPoint(TGraphCtrl* this, + double dNewPoint0, double dNewPoint1, + double dNewPoint2, double dNewPoint3) +{ + /* append a data point to the plot & return the previous point */ + double dPrevious; + + dPrevious = this->m_dCurrentPosition[0]; + this->m_dCurrentPosition[0] = dNewPoint0; + this->m_dCurrentPosition[1] = dNewPoint1; + this->m_dCurrentPosition[2] = dNewPoint2; + this->m_dCurrentPosition[3] = dNewPoint3; + GraphCtrl_DrawPoint(this); + /* Invalidate(); */ + return dPrevious; +} + +void GraphCtrl_Paint(TGraphCtrl* this, HWND hWnd, HDC dc) +{ + HDC memDC; + HBITMAP memBitmap; + HBITMAP oldBitmap; /* bitmap originally found in CMemDC */ + +/* RECT rcClient; */ +/* GetClientRect(hWnd, &rcClient); */ +/* FillSolidRect(dc, &rcClient, RGB(255, 0, 255)); */ +/* m_nClientWidth = rcClient.right - rcClient.left; */ +/* m_nClientHeight = rcClient.bottom - rcClient.top; */ + + /* no real plotting work is performed here, */ + /* just putting the existing bitmaps on the client */ + + /* to avoid flicker, establish a memory dc, draw to it */ + /* and then BitBlt it to the client */ + memDC = CreateCompatibleDC(dc); + memBitmap = (HBITMAP)CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); + oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap); + + if (memDC != NULL) + { + /* first drop the grid on the memory dc */ + BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcGrid, 0, 0, SRCCOPY); + /* now add the plot on top as a "pattern" via SRCPAINT. */ + /* works well with dark background and a light plot */ + BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcPlot, 0, 0, SRCPAINT); /* SRCPAINT */ + /* finally send the result to the display */ + BitBlt(dc, 0, 0, this->m_nClientWidth, this->m_nClientHeight, memDC, 0, 0, SRCCOPY); + } + SelectObject(memDC, oldBitmap); + DeleteObject(memBitmap); + DeleteDC(memDC); +} + +void GraphCtrl_DrawPoint(TGraphCtrl* this) +{ + /* this does the work of "scrolling" the plot to the left + * and appending a new data point all of the plotting is + * directed to the memory based bitmap associated with m_dcPlot + * the will subsequently be BitBlt'd to the client in Paint + */ + int currX, prevX, currY, prevY; + HPEN oldPen; + RECT rectCleanUp; + int i; + + if (this->m_dcPlot != NULL) + { + /* shift the plot by BitBlt'ing it to itself + * note: the m_dcPlot covers the entire client + * but we only shift bitmap that is the size + * of the plot rectangle + * grab the right side of the plot (exluding m_nShiftPixels on the left) + * move this grabbed bitmap to the left by m_nShiftPixels + */ + BitBlt(this->m_dcPlot, this->m_rectPlot.left, this->m_rectPlot.top+1, + this->m_nPlotWidth, this->m_nPlotHeight, this->m_dcPlot, + this->m_rectPlot.left+this->m_nShiftPixels, this->m_rectPlot.top+1, + SRCCOPY); + + /* establish a rectangle over the right side of plot */ + /* which now needs to be cleaned up proir to adding the new point */ + rectCleanUp = this->m_rectPlot; + rectCleanUp.left = rectCleanUp.right - this->m_nShiftPixels; + + /* fill the cleanup area with the background */ + FillRect(this->m_dcPlot, &rectCleanUp, this->m_brushBack); + + /* draw the next line segement */ + for (i = 0; i < MAX_PLOTS; i++) + { + /* grab the plotting pen */ + oldPen = (HPEN)SelectObject(this->m_dcPlot, this->m_penPlot[i]); + + /* move to the previous point */ + prevX = this->m_rectPlot.right-this->m_nPlotShiftPixels; + prevY = this->m_rectPlot.bottom - + (long)((this->m_dPreviousPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor); + MoveToEx(this->m_dcPlot, prevX, prevY, NULL); + + /* draw to the current point */ + currX = this->m_rectPlot.right-this->m_nHalfShiftPixels; + currY = this->m_rectPlot.bottom - + (long)((this->m_dCurrentPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor); + LineTo(this->m_dcPlot, currX, currY); + + /* Restore the pen */ + SelectObject(this->m_dcPlot, oldPen); + + /* if the data leaks over the upper or lower plot boundaries + * fill the upper and lower leakage with the background + * this will facilitate clipping on an as needed basis + * as opposed to always calling IntersectClipRect + */ + if ((prevY <= this->m_rectPlot.top) || (currY <= this->m_rectPlot.top)) + { + RECT rc; + rc.bottom = this->m_rectPlot.top+1; + rc.left = prevX; + rc.right = currX+1; + rc.top = this->m_rectClient.top; + FillRect(this->m_dcPlot, &rc, this->m_brushBack); + } + if ((prevY >= this->m_rectPlot.bottom) || (currY >= this->m_rectPlot.bottom)) + { + RECT rc; + rc.bottom = this->m_rectClient.bottom+1; + rc.left = prevX; + rc.right = currX+1; + rc.top = this->m_rectPlot.bottom+1; + /* RECT rc(prevX, m_rectPlot.bottom+1, currX+1, m_rectClient.bottom+1); */ + FillRect(this->m_dcPlot, &rc, this->m_brushBack); + } + + /* store the current point for connection to the next point */ + this->m_dPreviousPosition[i] = this->m_dCurrentPosition[i]; + } + } +} + +void GraphCtrl_Resize(TGraphCtrl* this) +{ + /* NOTE: Resize automatically gets called during the setup of the control */ + GetClientRect(this->m_hWnd, &this->m_rectClient); + + /* set some member variables to avoid multiple function calls */ + this->m_nClientHeight = this->m_rectClient.bottom - this->m_rectClient.top;/* m_rectClient.Height(); */ + this->m_nClientWidth = this->m_rectClient.right - this->m_rectClient.left;/* m_rectClient.Width(); */ + + /* the "left" coordinate and "width" will be modified in */ + /* InvalidateCtrl to be based on the width of the y axis scaling */ +#if 0 + this->m_rectPlot.left = 20; + this->m_rectPlot.top = 10; + this->m_rectPlot.right = this->m_rectClient.right-10; + this->m_rectPlot.bottom = this->m_rectClient.bottom-25; +#else + this->m_rectPlot.left = 0; + this->m_rectPlot.top = -1; + this->m_rectPlot.right = this->m_rectClient.right-0; + this->m_rectPlot.bottom = this->m_rectClient.bottom-0; +#endif + + /* set some member variables to avoid multiple function calls */ + this->m_nPlotHeight = this->m_rectPlot.bottom - this->m_rectPlot.top;/* m_rectPlot.Height(); */ + this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;/* m_rectPlot.Width(); */ + + /* set the scaling factor for now, this can be adjusted */ + /* in the SetRange functions */ + this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange; +} + +#if 0 +void TGraphCtrl::Reset() +{ + /* to clear the existing data (in the form of a bitmap) */ + /* simply invalidate the entire control */ + InvalidateCtrl(); +} +#endif + +extern TGraphCtrl PerformancePageCpuUsageHistoryGraph; +extern TGraphCtrl PerformancePageMemUsageHistoryGraph; +extern HWND hPerformancePageCpuUsageHistoryGraph; +extern HWND hPerformancePageMemUsageHistoryGraph; + +LRESULT CALLBACK GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + RECT rcClient; + HDC hdc; + PAINTSTRUCT ps; + + switch (message) + { + case WM_ERASEBKGND: + return TRUE; + /* + * Filter out mouse & keyboard messages + */ + /* case WM_APPCOMMAND: */ + case WM_CAPTURECHANGED: + case WM_LBUTTONDBLCLK: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_MBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_MOUSEACTIVATE: + case WM_MOUSEHOVER: + case WM_MOUSELEAVE: + case WM_MOUSEMOVE: + /* case WM_MOUSEWHEEL: */ + case WM_NCHITTEST: + case WM_NCLBUTTONDBLCLK: + case WM_NCLBUTTONDOWN: + case WM_NCLBUTTONUP: + case WM_NCMBUTTONDBLCLK: + case WM_NCMBUTTONDOWN: + case WM_NCMBUTTONUP: + /* case WM_NCMOUSEHOVER: */ + /* case WM_NCMOUSELEAVE: */ + case WM_NCMOUSEMOVE: + case WM_NCRBUTTONDBLCLK: + case WM_NCRBUTTONDOWN: + case WM_NCRBUTTONUP: + /* case WM_NCXBUTTONDBLCLK: */ + /* case WM_NCXBUTTONDOWN: */ + /* case WM_NCXBUTTONUP: */ + case WM_RBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + /* case WM_XBUTTONDBLCLK: */ + /* case WM_XBUTTONDOWN: */ + /* case WM_XBUTTONUP: */ + case WM_ACTIVATE: + case WM_CHAR: + case WM_DEADCHAR: + case WM_GETHOTKEY: + case WM_HOTKEY: + case WM_KEYDOWN: + case WM_KEYUP: + case WM_KILLFOCUS: + case WM_SETFOCUS: + case WM_SETHOTKEY: + case WM_SYSCHAR: + case WM_SYSDEADCHAR: + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + return 0; + + case WM_NCCALCSIZE: + return 0; + + case WM_SIZE: + if (hWnd == hPerformancePageMemUsageHistoryGraph) + { + GraphCtrl_Resize(&PerformancePageMemUsageHistoryGraph); + GraphCtrl_InvalidateCtrl(&PerformancePageMemUsageHistoryGraph); + } + if (hWnd == hPerformancePageCpuUsageHistoryGraph) + { + GraphCtrl_Resize(&PerformancePageCpuUsageHistoryGraph); + GraphCtrl_InvalidateCtrl(&PerformancePageCpuUsageHistoryGraph); + } + return 0; + + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rcClient); + if (hWnd == hPerformancePageMemUsageHistoryGraph) + GraphCtrl_Paint(&PerformancePageMemUsageHistoryGraph, hWnd, hdc); + if (hWnd == hPerformancePageCpuUsageHistoryGraph) + GraphCtrl_Paint(&PerformancePageCpuUsageHistoryGraph, hWnd, hdc); + EndPaint(hWnd, &ps); + return 0; + } + + /* + * We pass on all non-handled messages + */ + return CallWindowProc((WNDPROC)OldGraphCtrlWndProc, hWnd, message, wParam, lParam); +} diff --git a/programs/taskmgr/graphctl.h b/programs/taskmgr/graphctl.h new file mode 100644 index 00000000000..9756637fa50 --- /dev/null +++ b/programs/taskmgr/graphctl.h @@ -0,0 +1,113 @@ +/* + * ReactOS Task Manager + * + * graphctl.h + * + * Copyright (C) 2002 Robert Dickenson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __GRAPH_CTRL_H__ +#define __GRAPH_CTRL_H__ + +#define MAX_PLOTS 4 +#define MAX_CTRLS 4 + +#ifdef __cplusplus +extern "C" { +#endif + +#if 0 + +/* Attributes */ +public: + void SetXUnits(const char* string); + void SetYUnits(const char* string); + + /* Operations */ +public: + BOOL Create(DWORD dwStyle, const RECT& rect, HWND hParentWnd, UINT nID=NULL); + +#endif + +typedef struct +{ + int m_nShiftPixels; /* amount to shift with each new point */ + int m_nYDecimals; + + char m_strXUnitsString[50]; + char m_strYUnitsString[50]; + + COLORREF m_crBackColor; /* background color */ + COLORREF m_crGridColor; /* grid color */ + COLORREF m_crPlotColor[MAX_PLOTS]; /* data color */ + + double m_dCurrentPosition[MAX_PLOTS]; /* current position */ + double m_dPreviousPosition[MAX_PLOTS]; /* previous position */ + +/* those were protected fields */ + int m_nHalfShiftPixels; + int m_nPlotShiftPixels; + int m_nClientHeight; + int m_nClientWidth; + int m_nPlotHeight; + int m_nPlotWidth; + + double m_dLowerLimit; /* lower bounds */ + double m_dUpperLimit; /* upper bounds */ + double m_dRange; + double m_dVerticalFactor; + + HWND m_hWnd; + HWND m_hParentWnd; + HDC m_dcGrid; + HDC m_dcPlot; + HBITMAP m_bitmapOldGrid; + HBITMAP m_bitmapOldPlot; + HBITMAP m_bitmapGrid; + HBITMAP m_bitmapPlot; + HBRUSH m_brushBack; + HPEN m_penPlot[MAX_PLOTS]; + RECT m_rectClient; + RECT m_rectPlot; +} TGraphCtrl; + +extern LONG OldGraphCtrlWndProc; +double GraphCtrl_AppendPoint(TGraphCtrl* this, + double dNewPoint0, double dNewPoint1, + double dNewPoint2, double dNewPoint3); +BOOL GraphCtrl_Create(TGraphCtrl* this, HWND hWnd, HWND hParentWnd, +UINT nID); +void GraphCtrl_DrawPoint(TGraphCtrl* this); +void GraphCtrl_InvalidateCtrl(TGraphCtrl* this); +void GraphCtrl_Paint(TGraphCtrl* this, HWND hWnd, HDC dc); +void GraphCtrl_Reset(TGraphCtrl* this); +void GraphCtrl_Resize(TGraphCtrl* this); +void GraphCtrl_SetBackgroundColor(TGraphCtrl* this, COLORREF +color); +void GraphCtrl_SetGridColor(TGraphCtrl* this, COLORREF color); +void GraphCtrl_SetPlotColor(TGraphCtrl* this, int plot, COLORREF +color); +void GraphCtrl_SetRange(TGraphCtrl* this, double dLower, double +dUpper, int nDecimalPlaces); + +LRESULT CALLBACK GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + +#ifdef __cplusplus +} +#endif + +#endif /* __GRAPH_CTRL_H__ */ diff --git a/programs/taskmgr/optnmenu.c b/programs/taskmgr/optnmenu.c new file mode 100644 index 00000000000..ed45d873995 --- /dev/null +++ b/programs/taskmgr/optnmenu.c @@ -0,0 +1,147 @@ +/* + * ReactOS Task Manager + * + * optnmenu.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * options.c + * + * Menu item handlers for the options menu. + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" + +#define OPTIONS_MENU_INDEX 1 + +void TaskManager_OnOptionsAlwaysOnTop(void) +{ + HMENU hMenu; + HMENU hOptionsMenu; + + hMenu = GetMenu(hMainWnd); + hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX); + + /* + * Check or uncheck the always on top menu item + * and update main window. + */ + if (GetMenuState(hOptionsMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND) & MF_CHECKED) + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED); + TaskManagerSettings.AlwaysOnTop = FALSE; + SetWindowPos(hMainWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + } + else + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED); + TaskManagerSettings.AlwaysOnTop = TRUE; + SetWindowPos(hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + } +} + +void TaskManager_OnOptionsMinimizeOnUse(void) +{ + HMENU hMenu; + HMENU hOptionsMenu; + + hMenu = GetMenu(hMainWnd); + hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX); + + /* + * Check or uncheck the minimize on use menu item. + */ + if (GetMenuState(hOptionsMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND) & MF_CHECKED) + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED); + TaskManagerSettings.MinimizeOnUse = FALSE; + } + else + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED); + TaskManagerSettings.MinimizeOnUse = TRUE; + } +} + +void TaskManager_OnOptionsHideWhenMinimized(void) +{ + HMENU hMenu; + HMENU hOptionsMenu; + + hMenu = GetMenu(hMainWnd); + hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX); + + /* + * Check or uncheck the hide when minimized menu item. + */ + if (GetMenuState(hOptionsMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND) & MF_CHECKED) + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED); + TaskManagerSettings.HideWhenMinimized = FALSE; + } + else + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED); + TaskManagerSettings.HideWhenMinimized = TRUE; + } +} + +void TaskManager_OnOptionsShow16BitTasks(void) +{ + HMENU hMenu; + HMENU hOptionsMenu; + + hMenu = GetMenu(hMainWnd); + hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX); + + /* + * FIXME: Currently this is useless because the + * current implemetation doesn't list the 16-bit + * processes. I believe that would require querying + * each ntvdm.exe process for it's children. + */ + + /* + * Check or uncheck the show 16-bit tasks menu item + */ + if (GetMenuState(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND) & MF_CHECKED) + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED); + TaskManagerSettings.Show16BitTasks = FALSE; + } + else + { + CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED); + TaskManagerSettings.Show16BitTasks = TRUE; + } + + /* + * Refresh the list of processes. + */ + RefreshProcessPage(); +} diff --git a/programs/taskmgr/perfdata.c b/programs/taskmgr/perfdata.c new file mode 100644 index 00000000000..368031041c7 --- /dev/null +++ b/programs/taskmgr/perfdata.c @@ -0,0 +1,866 @@ +/* + * ReactOS Task Manager + * + * perfdata.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "taskmgr.h" +#include "perfdata.h" + +PROCNTQSI NtQuerySystemInformation = NULL; +PROCGGR pGetGuiResources = NULL; +PROCGPIC pGetProcessIoCounters = NULL; +CRITICAL_SECTION PerfDataCriticalSection; +PPERFDATA pPerfDataOld = NULL; /* Older perf data (saved to establish delta values) */ +PPERFDATA pPerfData = NULL; /* Most recent copy of perf data */ +ULONG ProcessCountOld = 0; +ULONG ProcessCount = 0; +double dbIdleTime; +double dbKernelTime; +double dbSystemTime; +LARGE_INTEGER liOldIdleTime = {{0,0}}; +double OldKernelTime = 0; +LARGE_INTEGER liOldSystemTime = {{0,0}}; +SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo; +SYSTEM_BASIC_INFORMATION SystemBasicInfo; +SYSTEM_CACHE_INFORMATION SystemCacheInfo; +SYSTEM_HANDLE_INFORMATION SystemHandleInfo; +PSYSTEM_PROCESSORTIME_INFO SystemProcessorTimeInfo = NULL; + +BOOL PerfDataInitialize(void) +{ + LONG status; + + NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQuerySystemInformation"); + pGetGuiResources = (PROCGGR)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetGuiResources"); + pGetProcessIoCounters = (PROCGPIC)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetProcessIoCounters"); + + InitializeCriticalSection(&PerfDataCriticalSection); + + if (!NtQuerySystemInformation) + return FALSE; + + /* + * Get number of processors in the system + */ + status = NtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), NULL); + if (status != NO_ERROR) + return FALSE; + + return TRUE; +} + +void PerfDataUninitialize(void) +{ + NtQuerySystemInformation = NULL; + + DeleteCriticalSection(&PerfDataCriticalSection); +} + +void PerfDataRefresh(void) +{ + ULONG ulSize; + LONG status; + LPBYTE pBuffer; + ULONG BufferSize; + PSYSTEM_PROCESS_INFORMATION pSPI; + PPERFDATA pPDOld; + ULONG Idx, Idx2; + HANDLE hProcess; + HANDLE hProcessToken; + TCHAR szTemp[MAX_PATH]; + DWORD dwSize; + SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; + SYSTEM_TIME_INFORMATION SysTimeInfo; + SYSTEM_CACHE_INFORMATION SysCacheInfo; + LPBYTE SysHandleInfoData; + PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo; + double CurrentKernelTime; + + + if (!NtQuerySystemInformation) + return; + + /* Get new system time */ + status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0); + if (status != NO_ERROR) + return; + + /* Get new CPU's idle time */ + status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL); + if (status != NO_ERROR) + return; + + /* Get system cache information */ + status = NtQuerySystemInformation(SystemCacheInformation, &SysCacheInfo, sizeof(SysCacheInfo), NULL); + if (status != NO_ERROR) + return; + + /* Get processor time information */ + SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.bKeNumberProcessors); + status = NtQuerySystemInformation(SystemProcessorTimeInformation, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.bKeNumberProcessors, &ulSize); + if (status != NO_ERROR) + return; + + /* Get handle information + * We don't know how much data there is so just keep + * increasing the buffer size until the call succeeds + */ + BufferSize = 0; + do + { + BufferSize += 0x10000; + SysHandleInfoData = (LPBYTE)malloc(BufferSize); + + status = NtQuerySystemInformation(SystemHandleInformation, SysHandleInfoData, BufferSize, &ulSize); + + if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) { + free(SysHandleInfoData); + } + + } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/); + + /* Get process information + * We don't know how much data there is so just keep + * increasing the buffer size until the call succeeds + */ + BufferSize = 0; + do + { + BufferSize += 0x10000; + pBuffer = (LPBYTE)malloc(BufferSize); + + status = NtQuerySystemInformation(SystemProcessInformation, pBuffer, BufferSize, &ulSize); + + if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) { + free(pBuffer); + } + + } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/); + + EnterCriticalSection(&PerfDataCriticalSection); + + /* + * Save system performance info + */ + memcpy(&SystemPerfInfo, &SysPerfInfo, sizeof(SYSTEM_PERFORMANCE_INFORMATION)); + + /* + * Save system cache info + */ + memcpy(&SystemCacheInfo, &SysCacheInfo, sizeof(SYSTEM_CACHE_INFORMATION)); + + /* + * Save system processor time info + */ + if (SystemProcessorTimeInfo) { + free(SystemProcessorTimeInfo); + } + SystemProcessorTimeInfo = SysProcessorTimeInfo; + + /* + * Save system handle info + */ + memcpy(&SystemHandleInfo, SysHandleInfoData, sizeof(SYSTEM_HANDLE_INFORMATION)); + free(SysHandleInfoData); + + for (CurrentKernelTime=0, Idx=0; IdxRelativeOffset == 0) + break; + pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset); + } + + /* Now alloc a new PERFDATA array and fill in the data */ + if (pPerfDataOld) { + free(pPerfDataOld); + } + pPerfDataOld = pPerfData; + pPerfData = (PPERFDATA)malloc(sizeof(PERFDATA) * ProcessCount); + pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer; + for (Idx=0; IdxProcessId) { + pPDOld = &pPerfDataOld[Idx2]; + break; + } + } + + /* Clear out process perf data structure */ + memset(&pPerfData[Idx], 0, sizeof(PERFDATA)); + + if (pSPI->Name.Buffer) + lstrcpyW(pPerfData[Idx].ImageName, pSPI->Name.Buffer); + else + { + static const WCHAR idleW[] = {'S','y','s','t','e','m',' ','I','d','l','e',' ','P','r','o','c','e','s','s',0}; + lstrcpyW(pPerfData[Idx].ImageName, idleW ); + } + + pPerfData[Idx].ProcessId = pSPI->ProcessId; + + if (pPDOld) { + double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime); + double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime); + double CpuTime = (CurTime - OldTime) / dbSystemTime; + CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */ + pPerfData[Idx].CPUUsage = (ULONG)CpuTime; + } + pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart; + pPerfData[Idx].WorkingSetSizeBytes = pSPI->TotalWorkingSetSizeBytes; + pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->PeakWorkingSetSizeBytes; + if (pPDOld) + pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->TotalWorkingSetSizeBytes - (LONG)pPDOld->WorkingSetSizeBytes); + else + pPerfData[Idx].WorkingSetSizeDelta = 0; + pPerfData[Idx].PageFaultCount = pSPI->PageFaultCount; + if (pPDOld) + pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->PageFaultCount - (LONG)pPDOld->PageFaultCount); + else + pPerfData[Idx].PageFaultCountDelta = 0; + pPerfData[Idx].VirtualMemorySizeBytes = pSPI->TotalVirtualSizeBytes; + pPerfData[Idx].PagedPoolUsagePages = pSPI->TotalPagedPoolUsagePages; + pPerfData[Idx].NonPagedPoolUsagePages = pSPI->TotalNonPagedPoolUsagePages; + pPerfData[Idx].BasePriority = pSPI->BasePriority; + pPerfData[Idx].HandleCount = pSPI->HandleCount; + pPerfData[Idx].ThreadCount = pSPI->ThreadCount; + pPerfData[Idx].SessionId = pSPI->SessionId; + + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pSPI->ProcessId); + if (hProcess) { + if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) { + ImpersonateLoggedOnUser(hProcessToken); + memset(szTemp, 0, sizeof(TCHAR[MAX_PATH])); + dwSize = MAX_PATH; + GetUserName(szTemp, &dwSize); +#ifndef UNICODE + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTemp, -1, pPerfData[Idx].UserName, MAX_PATH); +/* +int MultiByteToWideChar( + UINT CodePage, // code page + DWORD dwFlags, // character-type options + LPCSTR lpMultiByteStr, // string to map + int cbMultiByte, // number of bytes in string + LPWSTR lpWideCharStr, // wide-character buffer + int cchWideChar // size of buffer +); + */ +#endif + RevertToSelf(); + CloseHandle(hProcessToken); + } + if (pGetGuiResources) { + pPerfData[Idx].USERObjectCount = pGetGuiResources(hProcess, GR_USEROBJECTS); + pPerfData[Idx].GDIObjectCount = pGetGuiResources(hProcess, GR_GDIOBJECTS); + } + if (pGetProcessIoCounters) + pGetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters); + CloseHandle(hProcess); + } + pPerfData[Idx].UserTime.QuadPart = pSPI->UserTime.QuadPart; + pPerfData[Idx].KernelTime.QuadPart = pSPI->KernelTime.QuadPart; + pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset); + } + free(pBuffer); + LeaveCriticalSection(&PerfDataCriticalSection); +} + +ULONG PerfDataGetProcessCount(void) +{ + return ProcessCount; +} + +ULONG PerfDataGetProcessorUsage(void) +{ + return (ULONG)dbIdleTime; +} + +ULONG PerfDataGetProcessorSystemUsage(void) +{ + return (ULONG)dbKernelTime; +} + +BOOL PerfDataGetImageName(ULONG Index, LPTSTR lpImageName, int nMaxCount) +{ + BOOL bSuccessful; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) { + #ifdef _UNICODE + wcsncpy(lpImageName, pPerfData[Index].ImageName, nMaxCount); + #else + WideCharToMultiByte(CP_ACP, 0, pPerfData[Index].ImageName, -1, lpImageName, nMaxCount, NULL, NULL); + #endif + + bSuccessful = TRUE; + } else { + bSuccessful = FALSE; + } + LeaveCriticalSection(&PerfDataCriticalSection); + return bSuccessful; +} + +ULONG PerfDataGetProcessId(ULONG Index) +{ + ULONG ProcessId; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + ProcessId = pPerfData[Index].ProcessId; + else + ProcessId = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return ProcessId; +} + +BOOL PerfDataGetUserName(ULONG Index, LPTSTR lpUserName, int nMaxCount) +{ + BOOL bSuccessful; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) { + #ifdef _UNICODE + wcsncpy(lpUserName, pPerfData[Index].UserName, nMaxCount); + #else + WideCharToMultiByte(CP_ACP, 0, pPerfData[Index].UserName, -1, lpUserName, nMaxCount, NULL, NULL); + #endif + + bSuccessful = TRUE; + } else { + bSuccessful = FALSE; + } + + LeaveCriticalSection(&PerfDataCriticalSection); + + return bSuccessful; +} + +ULONG PerfDataGetSessionId(ULONG Index) +{ + ULONG SessionId; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + SessionId = pPerfData[Index].SessionId; + else + SessionId = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return SessionId; +} + +ULONG PerfDataGetCPUUsage(ULONG Index) +{ + ULONG CpuUsage; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + CpuUsage = pPerfData[Index].CPUUsage; + else + CpuUsage = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return CpuUsage; +} + +TIME PerfDataGetCPUTime(ULONG Index) +{ + TIME CpuTime = {{0,0}}; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + CpuTime = pPerfData[Index].CPUTime; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return CpuTime; +} + +ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index) +{ + ULONG WorkingSetSizeBytes; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + WorkingSetSizeBytes = pPerfData[Index].WorkingSetSizeBytes; + else + WorkingSetSizeBytes = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return WorkingSetSizeBytes; +} + +ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index) +{ + ULONG PeakWorkingSetSizeBytes; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + PeakWorkingSetSizeBytes = pPerfData[Index].PeakWorkingSetSizeBytes; + else + PeakWorkingSetSizeBytes = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return PeakWorkingSetSizeBytes; +} + +ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index) +{ + ULONG WorkingSetSizeDelta; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + WorkingSetSizeDelta = pPerfData[Index].WorkingSetSizeDelta; + else + WorkingSetSizeDelta = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return WorkingSetSizeDelta; +} + +ULONG PerfDataGetPageFaultCount(ULONG Index) +{ + ULONG PageFaultCount; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + PageFaultCount = pPerfData[Index].PageFaultCount; + else + PageFaultCount = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return PageFaultCount; +} + +ULONG PerfDataGetPageFaultCountDelta(ULONG Index) +{ + ULONG PageFaultCountDelta; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + PageFaultCountDelta = pPerfData[Index].PageFaultCountDelta; + else + PageFaultCountDelta = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return PageFaultCountDelta; +} + +ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index) +{ + ULONG VirtualMemorySizeBytes; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + VirtualMemorySizeBytes = pPerfData[Index].VirtualMemorySizeBytes; + else + VirtualMemorySizeBytes = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return VirtualMemorySizeBytes; +} + +ULONG PerfDataGetPagedPoolUsagePages(ULONG Index) +{ + ULONG PagedPoolUsagePages; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + PagedPoolUsagePages = pPerfData[Index].PagedPoolUsagePages; + else + PagedPoolUsagePages = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return PagedPoolUsagePages; +} + +ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index) +{ + ULONG NonPagedPoolUsagePages; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + NonPagedPoolUsagePages = pPerfData[Index].NonPagedPoolUsagePages; + else + NonPagedPoolUsagePages = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return NonPagedPoolUsagePages; +} + +ULONG PerfDataGetBasePriority(ULONG Index) +{ + ULONG BasePriority; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + BasePriority = pPerfData[Index].BasePriority; + else + BasePriority = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return BasePriority; +} + +ULONG PerfDataGetHandleCount(ULONG Index) +{ + ULONG HandleCount; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + HandleCount = pPerfData[Index].HandleCount; + else + HandleCount = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return HandleCount; +} + +ULONG PerfDataGetThreadCount(ULONG Index) +{ + ULONG ThreadCount; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + ThreadCount = pPerfData[Index].ThreadCount; + else + ThreadCount = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return ThreadCount; +} + +ULONG PerfDataGetUSERObjectCount(ULONG Index) +{ + ULONG USERObjectCount; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + USERObjectCount = pPerfData[Index].USERObjectCount; + else + USERObjectCount = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return USERObjectCount; +} + +ULONG PerfDataGetGDIObjectCount(ULONG Index) +{ + ULONG GDIObjectCount; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + GDIObjectCount = pPerfData[Index].GDIObjectCount; + else + GDIObjectCount = 0; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return GDIObjectCount; +} + +BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters) +{ + BOOL bSuccessful; + + EnterCriticalSection(&PerfDataCriticalSection); + + if (Index < ProcessCount) + { + memcpy(pIoCounters, &pPerfData[Index].IOCounters, sizeof(IO_COUNTERS)); + bSuccessful = TRUE; + } + else + bSuccessful = FALSE; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return bSuccessful; +} + +ULONG PerfDataGetCommitChargeTotalK(void) +{ + ULONG Total; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Total = SystemPerfInfo.MmTotalCommitedPages; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Total = Total * (PageSize / 1024); + + return Total; +} + +ULONG PerfDataGetCommitChargeLimitK(void) +{ + ULONG Limit; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Limit = SystemPerfInfo.MmTotalCommitLimit; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Limit = Limit * (PageSize / 1024); + + return Limit; +} + +ULONG PerfDataGetCommitChargePeakK(void) +{ + ULONG Peak; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Peak = SystemPerfInfo.MmPeakLimit; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Peak = Peak * (PageSize / 1024); + + return Peak; +} + +ULONG PerfDataGetKernelMemoryTotalK(void) +{ + ULONG Total; + ULONG Paged; + ULONG NonPaged; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Paged = SystemPerfInfo.PoolPagedBytes; + NonPaged = SystemPerfInfo.PoolNonPagedBytes; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Paged = Paged * (PageSize / 1024); + NonPaged = NonPaged * (PageSize / 1024); + + Total = Paged + NonPaged; + + return Total; +} + +ULONG PerfDataGetKernelMemoryPagedK(void) +{ + ULONG Paged; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Paged = SystemPerfInfo.PoolPagedBytes; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Paged = Paged * (PageSize / 1024); + + return Paged; +} + +ULONG PerfDataGetKernelMemoryNonPagedK(void) +{ + ULONG NonPaged; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + NonPaged = SystemPerfInfo.PoolNonPagedBytes; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + NonPaged = NonPaged * (PageSize / 1024); + + return NonPaged; +} + +ULONG PerfDataGetPhysicalMemoryTotalK(void) +{ + ULONG Total; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Total = SystemBasicInfo.uMmNumberOfPhysicalPages; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Total = Total * (PageSize / 1024); + + return Total; +} + +ULONG PerfDataGetPhysicalMemoryAvailableK(void) +{ + ULONG Available; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + Available = SystemPerfInfo.MmAvailablePages; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + Available = Available * (PageSize / 1024); + + return Available; +} + +ULONG PerfDataGetPhysicalMemorySystemCacheK(void) +{ + ULONG SystemCache; + ULONG PageSize; + + EnterCriticalSection(&PerfDataCriticalSection); + + SystemCache = SystemCacheInfo.CurrentSize; + PageSize = SystemBasicInfo.uPageSize; + + LeaveCriticalSection(&PerfDataCriticalSection); + + /* SystemCache = SystemCache * (PageSize / 1024); */ + SystemCache = SystemCache / 1024; + + return SystemCache; +} + +ULONG PerfDataGetSystemHandleCount(void) +{ + ULONG HandleCount; + + EnterCriticalSection(&PerfDataCriticalSection); + + HandleCount = SystemHandleInfo.Count; + + LeaveCriticalSection(&PerfDataCriticalSection); + + return HandleCount; +} + +ULONG PerfDataGetTotalThreadCount(void) +{ + ULONG ThreadCount = 0; + ULONG i; + + EnterCriticalSection(&PerfDataCriticalSection); + + for (i=0; i + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __PERFDATA_H +#define __PERFDATA_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#if 0 +typedef struct _TIME { + DWORD LowPart; + LONG HighPart; +} TIME, *PTIME; +#endif + +typedef ULARGE_INTEGER TIME, *PTIME; + +/* typedef WCHAR UNICODE_STRING; */ +typedef struct _UNICODE_STRING { + USHORT Length; + USHORT MaximumLength; + PWSTR Buffer; +} UNICODE_STRING, *PUNICODE_STRING; + +typedef struct _PERFDATA +{ + WCHAR ImageName[MAX_PATH]; + ULONG ProcessId; + WCHAR UserName[MAX_PATH]; + ULONG SessionId; + ULONG CPUUsage; + TIME CPUTime; + ULONG WorkingSetSizeBytes; + ULONG PeakWorkingSetSizeBytes; + ULONG WorkingSetSizeDelta; + ULONG PageFaultCount; + ULONG PageFaultCountDelta; + ULONG VirtualMemorySizeBytes; + ULONG PagedPoolUsagePages; + ULONG NonPagedPoolUsagePages; + ULONG BasePriority; + ULONG HandleCount; + ULONG ThreadCount; + ULONG USERObjectCount; + ULONG GDIObjectCount; + IO_COUNTERS IOCounters; + + TIME UserTime; + TIME KernelTime; +} PERFDATA, *PPERFDATA; + +typedef struct _CLIENT_ID +{ + HANDLE UniqueProcess; + HANDLE UniqueThread; +} CLIENT_ID, *PCLIENT_ID; + +typedef enum _KWAIT_REASON +{ + Executive, + FreePage, + PageIn, + PoolAllocation, + DelayExecution, + Suspended, + UserRequest, + WrExecutive, + WrFreePage, + WrPageIn, + WrDelayExecution, + WrSuspended, + WrUserRequest, + WrQueue, + WrLpcReceive, + WrLpcReply, + WrVirtualMemory, + WrPageOut, + WrRendezvous, + Spare2, + Spare3, + Spare4, + Spare5, + Spare6, + WrKernel, + MaximumWaitReason, +} KWAIT_REASON; + +/* SystemProcessThreadInfo (5) */ +typedef struct _SYSTEM_THREAD_INFORMATION +{ + TIME KernelTime; + TIME UserTime; + TIME CreateTime; + ULONG TickCount; + ULONG StartEIP; + CLIENT_ID ClientId; + ULONG DynamicPriority; + ULONG BasePriority; + ULONG nSwitches; + DWORD State; + KWAIT_REASON WaitReason; + +} SYSTEM_THREAD_INFORMATION, *PSYSTEM_THREAD_INFORMATION; + +typedef struct SYSTEM_PROCESS_INFORMATION +{ + ULONG RelativeOffset; + ULONG ThreadCount; + ULONG Unused1 [6]; + TIME CreateTime; + TIME UserTime; + TIME KernelTime; + UNICODE_STRING Name; + ULONG BasePriority; + ULONG ProcessId; + ULONG ParentProcessId; + ULONG HandleCount; + ULONG SessionId; + ULONG Unused2; + ULONG PeakVirtualSizeBytes; + ULONG TotalVirtualSizeBytes; + ULONG PageFaultCount; + ULONG PeakWorkingSetSizeBytes; + ULONG TotalWorkingSetSizeBytes; + ULONG PeakPagedPoolUsagePages; + ULONG TotalPagedPoolUsagePages; + ULONG PeakNonPagedPoolUsagePages; + ULONG TotalNonPagedPoolUsagePages; + ULONG TotalPageFileUsageBytes; + ULONG PeakPageFileUsageBytes; + ULONG TotalPrivateBytes; + SYSTEM_THREAD_INFORMATION ThreadSysInfo [1]; + +} SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION; + +typedef struct +{ + DWORD dwUnknown1; + ULONG uKeMaximumIncrement; + ULONG uPageSize; + ULONG uMmNumberOfPhysicalPages; + ULONG uMmLowestPhysicalPage; + ULONG uMmHighestPhysicalPage; + ULONG uAllocationGranularity; + PVOID pLowestUserAddress; + PVOID pMmHighestUserAddress; + ULONG uKeActiveProcessors; + BYTE bKeNumberProcessors; + BYTE bUnknown2; + WORD wUnknown3; +} SYSTEM_BASIC_INFORMATION; + +/* SystemPerformanceInfo (2) */ +typedef struct _SYSTEM_PERFORMANCE_INFORMATION +{ + LARGE_INTEGER /*TotalProcessorTime*/liIdleTime; + LARGE_INTEGER IoReadTransferCount; + LARGE_INTEGER IoWriteTransferCount; + LARGE_INTEGER IoOtherTransferCount; + ULONG IoReadOperationCount; + ULONG IoWriteOperationCount; + ULONG IoOtherOperationCount; + ULONG MmAvailablePages; + ULONG MmTotalCommitedPages; + ULONG MmTotalCommitLimit; + ULONG MmPeakLimit; + ULONG PageFaults; + ULONG WriteCopies; + ULONG TransitionFaults; + ULONG Unknown1; + ULONG DemandZeroFaults; + ULONG PagesInput; + ULONG PagesRead; + ULONG Unknown2; + ULONG Unknown3; + ULONG PagesOutput; + ULONG PageWrites; + ULONG Unknown4; + ULONG Unknown5; + ULONG PoolPagedBytes; + ULONG PoolNonPagedBytes; + ULONG Unknown6; + ULONG Unknown7; + ULONG Unknown8; + ULONG Unknown9; + ULONG MmTotalSystemFreePtes; + ULONG MmSystemCodepage; + ULONG MmTotalSystemDriverPages; + ULONG MmTotalSystemCodePages; + ULONG Unknown10; + ULONG Unknown11; + ULONG Unknown12; + ULONG MmSystemCachePage; + ULONG MmPagedPoolPage; + ULONG MmSystemDriverPage; + ULONG CcFastReadNoWait; + ULONG CcFastReadWait; + ULONG CcFastReadResourceMiss; + ULONG CcFastReadNotPossible; + ULONG CcFastMdlReadNoWait; + ULONG CcFastMdlReadWait; + ULONG CcFastMdlReadResourceMiss; + ULONG CcFastMdlReadNotPossible; + ULONG CcMapDataNoWait; + ULONG CcMapDataWait; + ULONG CcMapDataNoWaitMiss; + ULONG CcMapDataWaitMiss; + ULONG CcPinMappedDataCount; + ULONG CcPinReadNoWait; + ULONG CcPinReadWait; + ULONG CcPinReadNoWaitMiss; + ULONG CcPinReadWaitMiss; + ULONG CcCopyReadNoWait; + ULONG CcCopyReadWait; + ULONG CcCopyReadNoWaitMiss; + ULONG CcCopyReadWaitMiss; + ULONG CcMdlReadNoWait; + ULONG CcMdlReadWait; + ULONG CcMdlReadNoWaitMiss; + ULONG CcMdlReadWaitMiss; + ULONG CcReadaheadIos; + ULONG CcLazyWriteIos; + ULONG CcLazyWritePages; + ULONG CcDataFlushes; + ULONG CcDataPages; + ULONG ContextSwitches; + ULONG Unknown13; + ULONG Unknown14; + ULONG SystemCalls; + +} SYSTEM_PERFORMANCE_INFORMATION, *PSYSTEM_PERFORMANCE_INFORMATION; + +typedef struct +{ + LARGE_INTEGER liKeBootTime; + LARGE_INTEGER liKeSystemTime; + LARGE_INTEGER liExpTimeZoneBias; + ULONG uCurrentTimeZoneId; + DWORD dwReserved; +} SYSTEM_TIME_INFORMATION; + +/* SystemCacheInformation (21) */ +typedef struct _SYSTEM_CACHE_INFORMATION +{ + ULONG CurrentSize; + ULONG PeakSize; + ULONG PageFaultCount; + ULONG MinimumWorkingSet; + ULONG MaximumWorkingSet; + ULONG Unused[4]; + +} SYSTEM_CACHE_INFORMATION; + +/* SystemPageFileInformation (18) */ +typedef +struct _SYSTEM_PAGEFILE_INFORMATION +{ + ULONG RelativeOffset; + ULONG CurrentSizePages; + ULONG TotalUsedPages; + ULONG PeakUsedPages; + UNICODE_STRING PagefileFileName; + +} SYSTEM_PAGEFILE_INFORMATION, *PSYSTEM_PAGEFILE_INFORMATION; + +/* SystemHandleInformation (16) */ +/* (see ontypes.h) */ +typedef +struct _SYSTEM_HANDLE_ENTRY +{ + ULONG OwnerPid; + BYTE ObjectType; + BYTE HandleFlags; + USHORT HandleValue; + PVOID ObjectPointer; + ULONG AccessMask; + +} SYSTEM_HANDLE_ENTRY, *PSYSTEM_HANDLE_ENTRY; + +typedef +struct _SYSTEM_HANDLE_INFORMATION +{ + ULONG Count; + SYSTEM_HANDLE_ENTRY Handle [1]; + +} SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION; + +/* SystemProcessorPerformanceInformation (8) */ +typedef +struct _SYSTEM_PROCESSORTIME_INFO +{ + LARGE_INTEGER IdleTime; + LARGE_INTEGER KernelTime; + LARGE_INTEGER UserTime; + LARGE_INTEGER DpcTime; + LARGE_INTEGER InterruptTime; + ULONG InterruptCount; + ULONG Unused; + +} SYSTEM_PROCESSORTIME_INFO, *PSYSTEM_PROCESSORTIME_INFO; + +#define SystemBasicInformation 0 +#define SystemPerformanceInformation 2 +#define SystemTimeInformation 3 +#define SystemProcessInformation 5 +#define SystemProcessorTimeInformation 8 +#define SystemHandleInformation 16 +#define SystemPageFileInformation 18 +#define SystemCacheInformation 21 + +#define Li2Double(x) ((double)((x).QuadPart)) + +#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000 +#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 + +#define GR_GDIOBJECTS 0 /* Count of GDI objects */ +#define GR_USEROBJECTS 1 /* Count of USER objects */ + +typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG); +typedef DWORD (WINAPI *PROCGGR)(HANDLE,DWORD); +typedef BOOL (WINAPI *PROCGPIC)(HANDLE,PIO_COUNTERS); + +BOOL PerfDataInitialize(void); +void PerfDataUninitialize(void); +void PerfDataRefresh(void); + +ULONG PerfDataGetProcessCount(void); +ULONG PerfDataGetProcessorUsage(void); +ULONG PerfDataGetProcessorSystemUsage(void); + +BOOL PerfDataGetImageName(ULONG Index, LPTSTR lpImageName, int nMaxCount); +ULONG PerfDataGetProcessId(ULONG Index); +BOOL PerfDataGetUserName(ULONG Index, LPTSTR lpUserName, int nMaxCount); +ULONG PerfDataGetSessionId(ULONG Index); +ULONG PerfDataGetCPUUsage(ULONG Index); +TIME PerfDataGetCPUTime(ULONG Index); +ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index); +ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index); +ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index); +ULONG PerfDataGetPageFaultCount(ULONG Index); +ULONG PerfDataGetPageFaultCountDelta(ULONG Index); +ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index); +ULONG PerfDataGetPagedPoolUsagePages(ULONG Index); +ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index); +ULONG PerfDataGetBasePriority(ULONG Index); +ULONG PerfDataGetHandleCount(ULONG Index); +ULONG PerfDataGetThreadCount(ULONG Index); +ULONG PerfDataGetUSERObjectCount(ULONG Index); +ULONG PerfDataGetGDIObjectCount(ULONG Index); +BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters); + +ULONG PerfDataGetCommitChargeTotalK(void); +ULONG PerfDataGetCommitChargeLimitK(void); +ULONG PerfDataGetCommitChargePeakK(void); + +ULONG PerfDataGetKernelMemoryTotalK(void); +ULONG PerfDataGetKernelMemoryPagedK(void); +ULONG PerfDataGetKernelMemoryNonPagedK(void); + +ULONG PerfDataGetPhysicalMemoryTotalK(void); +ULONG PerfDataGetPhysicalMemoryAvailableK(void); +ULONG PerfDataGetPhysicalMemorySystemCacheK(void); + +ULONG PerfDataGetSystemHandleCount(void); + +ULONG PerfDataGetTotalThreadCount(void); + + +#ifdef __cplusplus +}; +#endif + +#endif /* __PERFDATA_H */ diff --git a/programs/taskmgr/perfpage.c b/programs/taskmgr/perfpage.c new file mode 100644 index 00000000000..0653ab85260 --- /dev/null +++ b/programs/taskmgr/perfpage.c @@ -0,0 +1,504 @@ +/* + * ReactOS Task Manager + * + * perfpage.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" +#include "graphctl.h" + +TGraphCtrl PerformancePageCpuUsageHistoryGraph; +TGraphCtrl PerformancePageMemUsageHistoryGraph; + +HWND hPerformancePage; /* Performance Property Page */ +HWND hPerformancePageCpuUsageGraph; /* CPU Usage Graph */ +HWND hPerformancePageMemUsageGraph; /* MEM Usage Graph */ +HWND hPerformancePageCpuUsageHistoryGraph; /* CPU Usage History Graph */ +HWND hPerformancePageMemUsageHistoryGraph; /* Memory Usage History Graph */ +HWND hPerformancePageTotalsFrame; /* Totals Frame */ +HWND hPerformancePageCommitChargeFrame; /* Commit Charge Frame */ +HWND hPerformancePageKernelMemoryFrame; /* Kernel Memory Frame */ +HWND hPerformancePagePhysicalMemoryFrame; /* Physical Memory Frame */ +HWND hPerformancePageCpuUsageFrame; +HWND hPerformancePageMemUsageFrame; +HWND hPerformancePageCpuUsageHistoryFrame; +HWND hPerformancePageMemUsageHistoryFrame; +HWND hPerformancePageCommitChargeTotalEdit; /* Commit Charge Total Edit Control */ +HWND hPerformancePageCommitChargeLimitEdit; /* Commit Charge Limit Edit Control */ +HWND hPerformancePageCommitChargePeakEdit; /* Commit Charge Peak Edit Control */ +HWND hPerformancePageKernelMemoryTotalEdit; /* Kernel Memory Total Edit Control */ +HWND hPerformancePageKernelMemoryPagedEdit; /* Kernel Memory Paged Edit Control */ +HWND hPerformancePageKernelMemoryNonPagedEdit; /* Kernel Memory NonPaged Edit Control */ +HWND hPerformancePagePhysicalMemoryTotalEdit; /* Physical Memory Total Edit Control */ +HWND hPerformancePagePhysicalMemoryAvailableEdit; /* Physical Memory Available Edit Control */ +HWND hPerformancePagePhysicalMemorySystemCacheEdit; /* Physical Memory System Cache Edit Control */ +HWND hPerformancePageTotalsHandleCountEdit; /* Total Handles Edit Control */ +HWND hPerformancePageTotalsProcessCountEdit; /* Total Processes Edit Control */ +HWND hPerformancePageTotalsThreadCountEdit; /* Total Threads Edit Control */ + + +static int nPerformancePageWidth; +static int nPerformancePageHeight; +static HANDLE hPerformancePageEvent = NULL; /* When this event becomes signaled then we refresh the performance page */ +DWORD WINAPI PerformancePageRefreshThread(void *lpParameter); + +void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference, int pos) +{ + RECT rc; + int cx, cy, sx, sy; + + GetClientRect(hCntrl, &rc); + MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT))); + if (pos) { + cx = rc.left; + cy = rc.top; + sx = rc.right - rc.left; + switch (pos) { + case 1: + break; + case 2: + cy += nYDifference / 2; + break; + case 3: + sx += nXDifference; + break; + case 4: + cy += nYDifference / 2; + sx += nXDifference; + break; + } + sy = rc.bottom - rc.top + nYDifference / 2; + SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER); + } else { + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + sx = sy = 0; + SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + } + InvalidateRect(hCntrl, NULL, TRUE); +} + +void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference) +{ + AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0); +} + +void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference) +{ + AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0); +} + +LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + RECT rc; + int nXDifference; + int nYDifference; + +/* HDC hdc; */ +/* PAINTSTRUCT ps; */ + + switch (message) { + case WM_INITDIALOG: + + /* Save the width and height */ + GetClientRect(hDlg, &rc); + nPerformancePageWidth = rc.right; + nPerformancePageHeight = rc.bottom; + + /* Update window position */ + SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + + /* + * Get handles to all the controls + */ + hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME); + hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME); + hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME); + hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME); + + hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME); + hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME); + hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME); + hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME); + + hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL); + hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT); + hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK); + hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL); + hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED); + hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED); + hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL); + hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE); + hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE); + hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT); + hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT); + hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT); + + hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH); + hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH); + hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH); + hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); + + GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc); + /* create the control */ + /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */ + GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); + /* customize the control */ + GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10); +/* PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */ +/* PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */ +/* PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */ +/* PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */ +/* PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */ + GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ; + GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(152, 205, 152)) ; + GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(255, 0, 0)) ; + GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(0, 255, 0)) ; + + GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc); + GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH); + GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ; + GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ; + GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(152, 215, 152)) ; + GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ; + /* Start our refresh thread */ +#ifdef RUN_PERF_PAGE + CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL); +#endif + + /* + * Subclass graph buttons + */ + OldGraphWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc); + SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc); + OldGraphCtrlWndProc = SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc); + SetWindowLong(hPerformancePageCpuUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc); + return TRUE; + + case WM_COMMAND: + break; +#if 0 + case WM_NCPAINT: + hdc = GetDC(hDlg); + GetClientRect(hDlg, &rc); + Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); + ReleaseDC(hDlg, hdc); + break; + + case WM_PAINT: + hdc = BeginPaint(hDlg, &ps); + GetClientRect(hDlg, &rc); + Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); + EndPaint(hDlg, &ps); + break; +#endif + case WM_SIZE: + do { + int cx, cy; + + if (wParam == SIZE_MINIMIZED) + return 0; + + cx = LOWORD(lParam); + cy = HIWORD(lParam); + nXDifference = cx - nPerformancePageWidth; + nYDifference = cy - nPerformancePageHeight; + nPerformancePageWidth = cx; + nPerformancePageHeight = cy; + } while (0); + + /* Reposition the performance page's controls */ + AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0); + AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0); + AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0); + AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0); + AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference); + AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference); + + AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference); + AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference); + + { + static int lastX, lastY; + + nXDifference += lastX; + nYDifference += lastY; + lastX = lastY = 0; + if (nXDifference % 2) { + if (nXDifference > 0) { + nXDifference--; + lastX++; + } else { + nXDifference++; + lastX--; + } + } + if (nYDifference % 2) { + if (nYDifference > 0) { + nYDifference--; + lastY++; + } else { + nYDifference++; + lastY--; + } + } + } + + AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1); + AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2); + AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3); + AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4); + AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1); + AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2); + AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3); + AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4); + break; + } + return 0; +} + +void RefreshPerformancePage(void) +{ + /* Signal the event so that our refresh thread */ + /* will wake up and refresh the performance page */ + SetEvent(hPerformancePageEvent); +} + +DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) +{ + ULONG CommitChargeTotal; + ULONG CommitChargeLimit; + ULONG CommitChargePeak; + + ULONG KernelMemoryTotal; + ULONG KernelMemoryPaged; + ULONG KernelMemoryNonPaged; + + ULONG PhysicalMemoryTotal; + ULONG PhysicalMemoryAvailable; + ULONG PhysicalMemorySystemCache; + + ULONG TotalHandles; + ULONG TotalThreads; + ULONG TotalProcesses; + + TCHAR Text[260]; + + /* Create the event */ + hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, _T("Performance Page Event")); + + /* If we couldn't create the event then exit the thread */ + if (!hPerformancePageEvent) + return 0; + + while (1) + { + DWORD dwWaitVal; + + /* Wait on the event */ + dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE); + + /* If the wait failed then the event object must have been */ + /* closed and the task manager is exiting so exit this thread */ + if (dwWaitVal == WAIT_FAILED) + return 0; + + if (dwWaitVal == WAIT_OBJECT_0) + { + ULONG CpuUsage; + ULONG CpuKernelUsage; + int nBarsUsed1; + int nBarsUsed2; + + /* Reset our event */ + ResetEvent(hPerformancePageEvent); + + /* + * Update the commit charge info + */ + CommitChargeTotal = PerfDataGetCommitChargeTotalK(); + CommitChargeLimit = PerfDataGetCommitChargeLimitK(); + CommitChargePeak = PerfDataGetCommitChargePeakK(); + _ultoa(CommitChargeTotal, Text, 10); + SetWindowText(hPerformancePageCommitChargeTotalEdit, Text); + _ultoa(CommitChargeLimit, Text, 10); + SetWindowText(hPerformancePageCommitChargeLimitEdit, Text); + _ultoa(CommitChargePeak, Text, 10); + SetWindowText(hPerformancePageCommitChargePeakEdit, Text); + wsprintf(Text, _T("Mem Usage: %dK / %dK"), CommitChargeTotal, CommitChargeLimit); + SendMessage(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text); + + /* + * Update the kernel memory info + */ + KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); + KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); + KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); + _ultoa(KernelMemoryTotal, Text, 10); + SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text); + _ultoa(KernelMemoryPaged, Text, 10); + SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text); + _ultoa(KernelMemoryNonPaged, Text, 10); + SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text); + + /* + * Update the physical memory info + */ + PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); + PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); + PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); + _ultoa(PhysicalMemoryTotal, Text, 10); + SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text); + _ultoa(PhysicalMemoryAvailable, Text, 10); + SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text); + _ultoa(PhysicalMemorySystemCache, Text, 10); + SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text); + + /* + * Update the totals info + */ + TotalHandles = PerfDataGetSystemHandleCount(); + TotalThreads = PerfDataGetTotalThreadCount(); + TotalProcesses = PerfDataGetProcessCount(); + _ultoa(TotalHandles, Text, 10); + SetWindowText(hPerformancePageTotalsHandleCountEdit, Text); + _ultoa(TotalThreads, Text, 10); + SetWindowText(hPerformancePageTotalsThreadCountEdit, Text); + _ultoa(TotalProcesses, Text, 10); + SetWindowText(hPerformancePageTotalsProcessCountEdit, Text); + + /* + * Redraw the graphs + */ + InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); + InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); + + /* + * Get the CPU usage + */ + CpuUsage = PerfDataGetProcessorUsage(); + CpuKernelUsage = PerfDataGetProcessorSystemUsage(); + if (CpuUsage < 0 ) CpuUsage = 0; + if (CpuUsage > 100) CpuUsage = 100; + if (CpuKernelUsage < 0) CpuKernelUsage = 0; + if (CpuKernelUsage > 100) CpuKernelUsage = 100; + + /* + * Get the memory usage + */ + CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK(); + CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); + nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; + + PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); + PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); + nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; + + + GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); + GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); + /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ + InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); + InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); + } + } + return 0; +} + +void PerformancePage_OnViewShowKernelTimes(void) +{ + HMENU hMenu; + HMENU hViewMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + + /* Check or uncheck the show 16-bit tasks menu item */ + if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED) + { + CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED); + TaskManagerSettings.ShowKernelTimes = FALSE; + } + else + { + CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED); + TaskManagerSettings.ShowKernelTimes = TRUE; + } + + RefreshPerformancePage(); +} + +void PerformancePage_OnViewCPUHistoryOneGraphAll(void) +{ + HMENU hMenu; + HMENU hViewMenu; + HMENU hCPUHistoryMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hCPUHistoryMenu = GetSubMenu(hViewMenu, 3); + + TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE; + CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND); +} + +void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void) +{ + HMENU hMenu; + HMENU hViewMenu; + HMENU hCPUHistoryMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hCPUHistoryMenu = GetSubMenu(hViewMenu, 3); + + TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE; + CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND); +} diff --git a/programs/taskmgr/priority.c b/programs/taskmgr/priority.c new file mode 100644 index 00000000000..7f76289a1fb --- /dev/null +++ b/programs/taskmgr/priority.c @@ -0,0 +1,322 @@ +/* + * ReactOS Task Manager + * + * priority.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" + +void ProcessPage_OnSetPriorityRealTime(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + return; + } + + if (!SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} + +void ProcessPage_OnSetPriorityHigh(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + return; + } + + if (!SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} + +void ProcessPage_OnSetPriorityAboveNormal(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + return; + } + + if (!SetPriorityClass(hProcess, ABOVE_NORMAL_PRIORITY_CLASS)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} + +void ProcessPage_OnSetPriorityNormal(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + return; + } + + if (!SetPriorityClass(hProcess, NORMAL_PRIORITY_CLASS)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} + +void ProcessPage_OnSetPriorityBelowNormal(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + return; + } + + if (!SetPriorityClass(hProcess, BELOW_NORMAL_PRIORITY_CLASS)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} + +void ProcessPage_OnSetPriorityLow(void) +{ + LVITEM lvitem; + ULONG Index; + DWORD dwProcessId; + HANDLE hProcess; + TCHAR strErrorText[260]; + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + dwProcessId = PerfDataGetProcessId(Index); + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0)) + return; + + if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES) + return; + + hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + if (!hProcess) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + return; + } + + if (!SetPriorityClass(hProcess, IDLE_PRIORITY_CLASS)) + { + GetLastErrorText(strErrorText, 260); + MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP); + } + + CloseHandle(hProcess); +} diff --git a/programs/taskmgr/proclist.c b/programs/taskmgr/proclist.c new file mode 100644 index 00000000000..70ad04187de --- /dev/null +++ b/programs/taskmgr/proclist.c @@ -0,0 +1,120 @@ +/* + * ReactOS Task Manager + * + * proclist.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" + + +LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + +LONG OldProcessListWndProc; + + +LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HBRUSH hbrBackground; + RECT rcItem; + RECT rcClip; + HDC hDC; + int DcSave; + + switch (message) + { + case WM_ERASEBKGND: + + /* + * The list control produces a nasty flicker + * when the user is resizing the window because + * it erases the background to white, then + * paints the list items over it. + * + * We will clip the drawing so that it only + * erases the parts of the list control that + * show only the background. + */ + + /* + * Get the device context and save it's state + * to be restored after we're done + */ + hDC = (HDC) wParam; + DcSave = SaveDC(hDC); + + /* + * Get the background brush + */ + hbrBackground = (HBRUSH) GetClassLong(hWnd, GCL_HBRBACKGROUND); + + /* + * Calculate the clip rect by getting the RECT + * of the first and last items and adding them up. + * + * We also have to get the item's icon RECT and + * subtract it from our clip rect because we don't + * use icons in this list control. + */ + ListView_GetItemRect(hWnd, 0, &rcClip, LVIR_BOUNDS); + ListView_GetItemRect(hWnd, ListView_GetItemCount(hWnd) - 1, &rcItem, LVIR_BOUNDS); + rcClip.bottom = rcItem.bottom; + ListView_GetItemRect(hWnd, 0, &rcItem, LVIR_ICON); + rcClip.left = rcItem.right; + + /* + * Now exclude the clip rect + */ + ExcludeClipRect(hDC, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); + + /* + * Now erase the background + * + * + * FIXME: Should I erase it myself or + * pass down the updated HDC and let + * the default handler do it? + */ + GetClientRect(hWnd, &rcItem); + FillRect(hDC, &rcItem, hbrBackground); + + /* + * Now restore the DC state that we + * saved earlier + */ + RestoreDC(hDC, DcSave); + + return TRUE; + } + + /* + * We pass on all messages except WM_ERASEBKGND + */ + return CallWindowProc((WNDPROC)OldProcessListWndProc, hWnd, message, wParam, lParam); +} diff --git a/programs/taskmgr/procpage.c b/programs/taskmgr/procpage.c new file mode 100644 index 00000000000..9eb29b0d8e9 --- /dev/null +++ b/programs/taskmgr/procpage.c @@ -0,0 +1,543 @@ +/* + * ReactOS Task Manager + * + * procpage.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" +#include "column.h" +#include + +HWND hProcessPage; /* Process List Property Page */ + +HWND hProcessPageListCtrl; /* Process ListCtrl Window */ +HWND hProcessPageHeaderCtrl; /* Process Header Control */ +HWND hProcessPageEndProcessButton; /* Process End Process button */ +HWND hProcessPageShowAllProcessesButton;/* Process Show All Processes checkbox */ + +static int nProcessPageWidth; +static int nProcessPageHeight; + +static HANDLE hProcessPageEvent = NULL; /* When this event becomes signaled then we refresh the process list */ + +void ProcessPageOnNotify(WPARAM wParam, LPARAM lParam); +void CommaSeparateNumberString(LPTSTR strNumber, int nMaxCount); +void ProcessPageShowContextMenu(DWORD dwProcessId); +DWORD WINAPI ProcessPageRefreshThread(void *lpParameter); + +LRESULT CALLBACK ProcessPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + RECT rc; + int nXDifference; + int nYDifference; + int cx, cy; + + switch (message) { + case WM_INITDIALOG: + /* + * Save the width and height + */ + GetClientRect(hDlg, &rc); + nProcessPageWidth = rc.right; + nProcessPageHeight = rc.bottom; + + /* Update window position */ + SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + + /* + * Get handles to the controls + */ + hProcessPageListCtrl = GetDlgItem(hDlg, IDC_PROCESSLIST); + hProcessPageHeaderCtrl = ListView_GetHeader(hProcessPageListCtrl); + hProcessPageEndProcessButton = GetDlgItem(hDlg, IDC_ENDPROCESS); + hProcessPageShowAllProcessesButton = GetDlgItem(hDlg, IDC_SHOWALLPROCESSES); + + /* + * Set the font, title, and extended window styles for the list control + */ + SendMessage(hProcessPageListCtrl, WM_SETFONT, SendMessage(hProcessPage, WM_GETFONT, 0, 0), TRUE); + SetWindowText(hProcessPageListCtrl, _T("Processes")); + ListView_SetExtendedListViewStyle(hProcessPageListCtrl, ListView_GetExtendedListViewStyle(hProcessPageListCtrl) | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP); + + AddColumns(); + + /* + * Subclass the process list control so we can intercept WM_ERASEBKGND + */ + OldProcessListWndProc = SetWindowLong(hProcessPageListCtrl, GWL_WNDPROC, (LONG)ProcessListWndProc); + + /* Start our refresh thread */ + CreateThread(NULL, 0, ProcessPageRefreshThread, NULL, 0, NULL); + + return TRUE; + + case WM_DESTROY: + /* Close the event handle, this will make the */ + /* refresh thread exit when the wait fails */ + CloseHandle(hProcessPageEvent); + + SaveColumnSettings(); + + break; + + case WM_COMMAND: + break; + + case WM_SIZE: + if (wParam == SIZE_MINIMIZED) + return 0; + + cx = LOWORD(lParam); + cy = HIWORD(lParam); + nXDifference = cx - nProcessPageWidth; + nYDifference = cy - nProcessPageHeight; + nProcessPageWidth = cx; + nProcessPageHeight = cy; + + /* Reposition the application page's controls */ + GetWindowRect(hProcessPageListCtrl, &rc); + cx = (rc.right - rc.left) + nXDifference; + cy = (rc.bottom - rc.top) + nYDifference; + SetWindowPos(hProcessPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + InvalidateRect(hProcessPageListCtrl, NULL, TRUE); + + GetClientRect(hProcessPageEndProcessButton, &rc); + MapWindowPoints(hProcessPageEndProcessButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + SetWindowPos(hProcessPageEndProcessButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hProcessPageEndProcessButton, NULL, TRUE); + + GetClientRect(hProcessPageShowAllProcessesButton, &rc); + MapWindowPoints(hProcessPageShowAllProcessesButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); + cx = rc.left; + cy = rc.top + nYDifference; + SetWindowPos(hProcessPageShowAllProcessesButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hProcessPageShowAllProcessesButton, NULL, TRUE); + + break; + + case WM_NOTIFY: + + ProcessPageOnNotify(wParam, lParam); + break; + } + + return 0; +} + +void ProcessPageOnNotify(WPARAM wParam, LPARAM lParam) +{ + int idctrl; + LPNMHDR pnmh; + LPNMLISTVIEW pnmv; + NMLVDISPINFO* pnmdi; + LPNMHEADER pnmhdr; + LVITEM lvitem; + ULONG Index; + ULONG ColumnIndex; + IO_COUNTERS iocounters; + TIME time; + + idctrl = (int) wParam; + pnmh = (LPNMHDR) lParam; + pnmv = (LPNMLISTVIEW) lParam; + pnmdi = (NMLVDISPINFO*) lParam; + pnmhdr = (LPNMHEADER) lParam; + + if (pnmh->hwndFrom == hProcessPageListCtrl) + { + switch (pnmh->code) + { + #if 0 + case LVN_ITEMCHANGED: + ProcessPageUpdate(); + break; + #endif + + case LVN_GETDISPINFO: + + if (!(pnmdi->item.mask & LVIF_TEXT)) + break; + + ColumnIndex = pnmdi->item.iSubItem; + Index = pnmdi->item.iItem; + + if (ColumnDataHints[ColumnIndex] == COLUMN_IMAGENAME) + PerfDataGetImageName(Index, pnmdi->item.pszText, pnmdi->item.cchTextMax); + if (ColumnDataHints[ColumnIndex] == COLUMN_PID) + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetProcessId(Index)); + if (ColumnDataHints[ColumnIndex] == COLUMN_USERNAME) + PerfDataGetUserName(Index, pnmdi->item.pszText, pnmdi->item.cchTextMax); + if (ColumnDataHints[ColumnIndex] == COLUMN_SESSIONID) + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetSessionId(Index)); + if (ColumnDataHints[ColumnIndex] == COLUMN_CPUUSAGE) + wsprintf(pnmdi->item.pszText, _T("%02d"), PerfDataGetCPUUsage(Index)); + if (ColumnDataHints[ColumnIndex] == COLUMN_CPUTIME) + { + DWORD dwHours; + DWORD dwMinutes; + DWORD dwSeconds; + + time = PerfDataGetCPUTime(Index); +#ifdef _MSC_VER + dwHours = (DWORD)(time.QuadPart / 36000000000L); + dwMinutes = (DWORD)((time.QuadPart % 36000000000L) / 600000000L); + dwSeconds = (DWORD)(((time.QuadPart % 36000000000L) % 600000000L) / 10000000L); +#else + dwHours = (DWORD)(time.QuadPart / 36000000000LL); + dwMinutes = (DWORD)((time.QuadPart % 36000000000LL) / 600000000LL); + dwSeconds = (DWORD)(((time.QuadPart % 36000000000LL) % 600000000LL) / 10000000LL); +#endif + wsprintf(pnmdi->item.pszText, _T("%d:%02d:%02d"), dwHours, dwMinutes, dwSeconds); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_MEMORYUSAGE) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetWorkingSetSizeBytes(Index) / 1024); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + _tcscat(pnmdi->item.pszText, _T(" K")); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_PEAKMEMORYUSAGE) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPeakWorkingSetSizeBytes(Index) / 1024); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + _tcscat(pnmdi->item.pszText, _T(" K")); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_MEMORYUSAGEDELTA) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetWorkingSetSizeDelta(Index) / 1024); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + _tcscat(pnmdi->item.pszText, _T(" K")); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_PAGEFAULTS) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPageFaultCount(Index)); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_PAGEFAULTSDELTA) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPageFaultCountDelta(Index)); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_VIRTUALMEMORYSIZE) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetVirtualMemorySizeBytes(Index) / 1024); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + _tcscat(pnmdi->item.pszText, _T(" K")); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_PAGEDPOOL) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPagedPoolUsagePages(Index) / 1024); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + _tcscat(pnmdi->item.pszText, _T(" K")); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_NONPAGEDPOOL) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetNonPagedPoolUsagePages(Index) / 1024); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + _tcscat(pnmdi->item.pszText, _T(" K")); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_BASEPRIORITY) + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetBasePriority(Index)); + if (ColumnDataHints[ColumnIndex] == COLUMN_HANDLECOUNT) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetHandleCount(Index)); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_THREADCOUNT) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetThreadCount(Index)); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_USEROBJECTS) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetUSERObjectCount(Index)); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_GDIOBJECTS) + { + wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetGDIObjectCount(Index)); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_IOREADS) + { + PerfDataGetIOCounters(Index, &iocounters); + /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.ReadOperationCount); */ +#ifdef UNICODE +#define _ui64toa _ui64tow +#else +#endif + _ui64toa(iocounters.ReadOperationCount, pnmdi->item.pszText, 10); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_IOWRITES) + { + PerfDataGetIOCounters(Index, &iocounters); + /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.WriteOperationCount); */ + _ui64toa(iocounters.WriteOperationCount, pnmdi->item.pszText, 10); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_IOOTHER) + { + PerfDataGetIOCounters(Index, &iocounters); + /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.OtherOperationCount); */ + _ui64toa(iocounters.OtherOperationCount, pnmdi->item.pszText, 10); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_IOREADBYTES) + { + PerfDataGetIOCounters(Index, &iocounters); + /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.ReadTransferCount); */ + _ui64toa(iocounters.ReadTransferCount, pnmdi->item.pszText, 10); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_IOWRITEBYTES) + { + PerfDataGetIOCounters(Index, &iocounters); + /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.WriteTransferCount); */ + _ui64toa(iocounters.WriteTransferCount, pnmdi->item.pszText, 10); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + if (ColumnDataHints[ColumnIndex] == COLUMN_IOOTHERBYTES) + { + PerfDataGetIOCounters(Index, &iocounters); + /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.OtherTransferCount); */ + _ui64toa(iocounters.OtherTransferCount, pnmdi->item.pszText, 10); + CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax); + } + + break; + + case NM_RCLICK: + + for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++) + { + memset(&lvitem, 0, sizeof(LVITEM)); + + lvitem.mask = LVIF_STATE; + lvitem.stateMask = LVIS_SELECTED; + lvitem.iItem = Index; + + ListView_GetItem(hProcessPageListCtrl, &lvitem); + + if (lvitem.state & LVIS_SELECTED) + break; + } + + if ((ListView_GetSelectedCount(hProcessPageListCtrl) == 1) && + (PerfDataGetProcessId(Index) != 0)) + { + ProcessPageShowContextMenu(PerfDataGetProcessId(Index)); + } + + break; + + } + } + else if (pnmh->hwndFrom == hProcessPageHeaderCtrl) + { + switch (pnmh->code) + { + case HDN_ITEMCLICK: + + /* + * FIXME: Fix the column sorting + * + *ListView_SortItems(hApplicationPageListCtrl, ApplicationPageCompareFunc, NULL); + *bSortAscending = !bSortAscending; + */ + + break; + + case HDN_ITEMCHANGED: + + UpdateColumnDataHints(); + + break; + + case HDN_ENDDRAG: + + UpdateColumnDataHints(); + + break; + + } + } + +} + +void CommaSeparateNumberString(LPTSTR strNumber, int nMaxCount) +{ + TCHAR temp[260]; + UINT i, j, k; + + for (i=0,j=0; i<(_tcslen(strNumber) % 3); i++, j++) + temp[j] = strNumber[i]; + for (k=0; i<_tcslen(strNumber); i++,j++,k++) { + if ((k % 3 == 0) && (j > 0)) + temp[j++] = _T(','); + temp[j] = strNumber[i]; + } + temp[j] = _T('\0'); + _tcsncpy(strNumber, temp, nMaxCount); +} + +void ProcessPageShowContextMenu(DWORD dwProcessId) +{ + HMENU hMenu; + HMENU hSubMenu; + HMENU hPriorityMenu; + POINT pt; + SYSTEM_INFO si; + HANDLE hProcess; + DWORD dwProcessPriorityClass; + TCHAR strDebugger[260]; + DWORD dwDebuggerSize; + HKEY hKey; + UINT Idx; + + memset(&si, 0, sizeof(SYSTEM_INFO)); + + GetCursorPos(&pt); + GetSystemInfo(&si); + + hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PROCESS_PAGE_CONTEXT)); + hSubMenu = GetSubMenu(hMenu, 0); + hPriorityMenu = GetSubMenu(hSubMenu, 4); + + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId); + dwProcessPriorityClass = GetPriorityClass(hProcess); + CloseHandle(hProcess); + + if (si.dwNumberOfProcessors < 2) + RemoveMenu(hSubMenu, ID_PROCESS_PAGE_SETAFFINITY, MF_BYCOMMAND); + + if (!AreDebugChannelsSupported()) + RemoveMenu(hSubMenu, ID_PROCESS_PAGE_DEBUGCHANNELS, MF_BYCOMMAND); + + switch (dwProcessPriorityClass) { + case REALTIME_PRIORITY_CLASS: + CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, MF_BYCOMMAND); + break; + case HIGH_PRIORITY_CLASS: + CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_HIGH, MF_BYCOMMAND); + break; + case ABOVE_NORMAL_PRIORITY_CLASS: + CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, MF_BYCOMMAND); + break; + case NORMAL_PRIORITY_CLASS: + CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_NORMAL, MF_BYCOMMAND); + break; + case BELOW_NORMAL_PRIORITY_CLASS: + CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, MF_BYCOMMAND); + break; + case IDLE_PRIORITY_CLASS: + CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_LOW, MF_BYCOMMAND); + break; + } + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + dwDebuggerSize = 260; + if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) == ERROR_SUCCESS) + { + for (Idx=0; Idx<_tcslen(strDebugger); Idx++) + strDebugger[Idx] = toupper(strDebugger[Idx]); + + if (_tcsstr(strDebugger, _T("DRWTSN32"))) + EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + } + else + EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + + RegCloseKey(hKey); + } else { + EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + } + TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); + DestroyMenu(hMenu); +} + +void RefreshProcessPage(void) +{ + /* Signal the event so that our refresh thread */ + /* will wake up and refresh the process page */ + SetEvent(hProcessPageEvent); +} + +DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) +{ + ULONG OldProcessorUsage = 0; + ULONG OldProcessCount = 0; + + /* Create the event */ + hProcessPageEvent = CreateEvent(NULL, TRUE, TRUE, _T("Process Page Event")); + + /* If we couldn't create the event then exit the thread */ + if (!hProcessPageEvent) + return 0; + + while (1) { + DWORD dwWaitVal; + + /* Wait on the event */ + dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE); + + /* If the wait failed then the event object must have been */ + /* closed and the task manager is exiting so exit this thread */ + if (dwWaitVal == WAIT_FAILED) + return 0; + + if (dwWaitVal == WAIT_OBJECT_0) { + TCHAR text[260]; + + /* Reset our event */ + ResetEvent(hProcessPageEvent); + + if ((ULONG)SendMessage(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount()) + SendMessage(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL); + + if (IsWindowVisible(hProcessPage)) + InvalidateRect(hProcessPageListCtrl, NULL, FALSE); + + if (OldProcessorUsage != PerfDataGetProcessorUsage()) { + OldProcessorUsage = PerfDataGetProcessorUsage(); + wsprintf(text, _T("CPU Usage: %3d%%"), OldProcessorUsage); + SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); + } + if (OldProcessCount != PerfDataGetProcessCount()) { + OldProcessCount = PerfDataGetProcessCount(); + wsprintf(text, _T("Processes: %d"), OldProcessCount); + SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); + } + } + } + return 0; +} diff --git a/programs/taskmgr/resource.h b/programs/taskmgr/resource.h new file mode 100644 index 00000000000..27add7da108 --- /dev/null +++ b/programs/taskmgr/resource.h @@ -0,0 +1,199 @@ +/* + *{{NO_DEPENDENCIES}} + * Microsoft Developer Studio generated include file. + * Used by taskmgr.rc + * + */ +#define IDD_TASKMGR_DIALOG 102 +#define IDD_ABOUTBOX 103 +#define IDS_APP_TITLE 103 +#define IDM_ABOUT 104 +#define IDM_EXIT 105 +#define IDD_APPLICATION_PAGE 106 +#define IDI_TASKMGR 107 +#define IDI_SMALL 108 +#define IDC_TASKMGR 109 +#define IDR_MAINFRAME 128 +#define IDR_TASKMANAGER 130 +#define IDD_PROCESS_PAGE 133 +#define IDD_PERFORMANCE_PAGE 134 +#define IDR_WINDOWSMENU 135 +#define IDI_TASKMANAGER 136 +#define IDI_WINDOW 137 +#define IDI_WINDOWSM 138 +#define IDR_APPLICATION_PAGE_CONTEXT1 139 +#define IDR_APPLICATION_PAGE_CONTEXT2 140 +#define IDR_TRAY_POPUP 141 +#define IDD_AFFINITY_DIALOG 142 +#define IDD_COLUMNS_DIALOG 143 +#define IDR_PROCESS_PAGE_CONTEXT 144 +#define IDB_TRAYMASK 150 +#define IDB_TRAYICON 153 +#define IDB_FONT 154 +#define IDD_DEBUG_CHANNELS_DIALOG 155 +#define IDC_DEBUG_CHANNELS_LIST 156 + +#define IDC_ENDTASK 1012 +#define IDC_SWITCHTO 1013 +#define IDC_NEWTASK 1014 +#define IDC_TAB 1015 +#define IDC_APPLIST 1016 +#define IDC_ENDPROCESS 1017 +#define IDC_PROCESSLIST 1018 +#define IDC_CPU0 1019 +#define IDC_CPU1 1020 +#define IDC_CPU2 1021 +#define IDC_SHOWALLPROCESSES 1021 +#define IDC_CPU3 1022 +#define IDC_IMAGENAME 1022 +#define IDC_CPU4 1023 +#define IDC_PID 1023 +#define IDC_CPU5 1024 +#define IDC_CPUUSAGE 1024 +#define IDC_TOTALS_HANDLE_COUNT 1024 +#define IDC_CPU6 1025 +#define IDC_CPUTIME 1025 +#define IDC_CPU7 1026 +#define IDC_MEMORYUSAGE 1026 +#define IDC_TOTALS_THREAD_COUNT 1026 +#define IDC_CPU8 1027 +#define IDC_MEMORYUSAGEDELTA 1027 +#define IDC_TOTALS_PROCESS_COUNT 1027 +#define IDC_CPU9 1028 +#define IDC_PEAKMEMORYUSAGE 1028 +#define IDC_COMMIT_CHARGE_TOTAL 1028 +#define IDC_CPU10 1029 +#define IDC_PAGEFAULTS 1029 +#define IDC_COMMIT_CHARGE_LIMIT 1029 +#define IDC_LICENSE_EDIT 1029 +#define IDC_CPU11 1030 +#define IDC_USEROBJECTS 1030 +#define IDC_COMMIT_CHARGE_PEAK 1030 +#define IDC_CPU12 1031 +#define IDC_IOREADS 1031 +#define IDC_PHYSICAL_MEMORY_TOTAL 1031 +#define IDC_CPU13 1032 +#define IDC_IOREADBYTES 1032 +#define IDC_PHYSICAL_MEMORY_AVAILABLE 1032 +#define IDC_CPU14 1033 +#define IDC_SESSIONID 1033 +#define IDC_PHYSICAL_MEMORY_SYSTEM_CACHE 1033 +#define IDC_CPU15 1034 +#define IDC_USERNAME 1034 +#define IDC_KERNEL_MEMORY_TOTAL 1034 +#define IDC_CPU16 1035 +#define IDC_PAGEFAULTSDELTA 1035 +#define IDC_KERNEL_MEMORY_PAGED 1035 +#define IDC_CPU17 1036 +#define IDC_VIRTUALMEMORYSIZE 1036 +#define IDC_KERNEL_MEMORY_NONPAGED 1036 +#define IDC_CPU18 1037 +#define IDC_PAGEDPOOL 1037 +#define IDC_TOTALS_FRAME 1037 +#define IDC_CPU19 1038 +#define IDC_NONPAGEDPOOL 1038 +#define IDC_COMMIT_CHARGE_FRAME 1038 +#define IDC_CPU20 1039 +#define IDC_BASEPRIORITY 1039 +#define IDC_KERNEL_MEMORY_FRAME 1039 +#define IDC_CPU21 1040 +#define IDC_HANDLECOUNT 1040 +#define IDC_PHYSICAL_MEMORY_FRAME 1040 +#define IDC_CPU22 1041 +#define IDC_THREADCOUNT 1041 +#define IDC_CPU23 1042 +#define IDC_CPU24 1043 +#define IDC_GDIOBJECTS 1043 +#define IDC_CPU_USAGE_FRAME 1043 +#define IDC_CPU25 1044 +#define IDC_IOWRITES 1044 +#define IDC_MEM_USAGE_FRAME 1044 +#define IDC_CPU26 1045 +#define IDC_IOWRITEBYTES 1045 +#define IDC_CPU_USAGE_HISTORY_FRAME 1045 +#define IDC_CPU27 1046 +#define IDC_IOOTHER 1046 +#define IDC_MEMORY_USAGE_HISTORY_FRAME 1046 +#define IDC_CPU28 1047 +#define IDC_IOOTHERBYTES 1047 +#define IDC_CPU_USAGE_GRAPH 1047 +#define IDC_CPU29 1048 +#define IDC_MEM_USAGE_GRAPH2 1048 +#define IDC_MEM_USAGE_GRAPH 1048 +#define IDC_CPU30 1049 +#define IDC_MEM_USAGE_HISTORY_GRAPH 1049 +#define IDC_CPU_USAGE_HISTORY_GRAPH 1050 +#define IDC_CPU31 1051 + +#define IDS_TOTALS_HANDLE_COUNT 1060 +#define IDS_TOTALS_THREAD_COUNT 1061 +#define IDS_TOTALS_PROCESS_COUNT 1062 +#define IDS_COMMIT_CHARGE_TOTAL 1063 +#define IDS_COMMIT_CHARGE_LIMIT 1064 +#define IDS_COMMIT_CHARGE_PEAK 1065 +#define IDS_PHYSICAL_MEMORY_TOTAL 1066 +#define IDS_PHYSICAL_MEMORY_AVAILABLE 1067 +#define IDS_PHYSICAL_MEMORY_SYSTEM_CACHE 1068 +#define IDS_KERNEL_MEMORY_TOTAL 1069 +#define IDS_KERNEL_MEMORY_PAGED 1070 +#define IDS_KERNEL_MEMORY_NONPAGED 1071 + + +#define ID_FILE_NEW 32771 +#define ID_OPTIONS_ALWAYSONTOP 32773 +#define ID_OPTIONS_MINIMIZEONUSE 32774 +#define ID_OPTIONS_HIDEWHENMINIMIZED 32775 +#define ID_VIEW_REFRESH 32776 +#define ID_VIEW_LARGE 32778 +#define ID_VIEW_SMALL 32779 +#define ID_VIEW_DETAILS 32780 +#define ID_VIEW_UPDATESPEED_HIGH 32781 +#define ID_VIEW_UPDATESPEED_NORMAL 32782 +#define ID_VIEW_UPDATESPEED_LOW 32783 +#define ID_VIEW_UPDATESPEED_PAUSED 32784 +#define ID_WINDOWS_TILEHORIZONTALLY 32785 +#define ID_WINDOWS_TILEVERTICALLY 32786 +#define ID_WINDOWS_MINIMIZE 32787 +#define ID_WINDOWS_MAXIMIZE 32788 +#define ID_WINDOWS_CASCADE 32789 +#define ID_WINDOWS_BRINGTOFRONT 32790 +#define ID_HELP_TOPICS 32791 +#define ID_HELP_ABOUT 32792 +#define ID_FILE_EXIT 32793 +#define ID_OPTIONS_SHOW16BITTASKS 32794 +#define ID_VIEW_SELECTCOLUMNS 32795 +#define ID_VIEW_SHOWKERNELTIMES 32796 +#define ID_VIEW_CPUHISTORY_ONEGRAPHALL 32797 +#define ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU 32798 +#define ID_APPLICATION_PAGE_SWITCHTO 32799 +#define ID_ENDTASK 32800 +#define ID_GOTOPROCESS 32801 +#define ID_RESTORE 32802 +#define ID_APPLICATION_PAGE_ENDTASK 32803 +#define ID_APPLICATION_PAGE_GOTOPROCESS 32804 +#define ID_PROCESS_PAGE_ENDPROCESS 32805 +#define ID_PROCESS_PAGE_ENDPROCESSTREE 32806 +#define ID_PROCESS_PAGE_DEBUG 32807 +#define ID_PROCESS_PAGE_SETAFFINITY 32808 +#define ID_PROCESS_PAGE_SETPRIORITY_REALTIME 32809 +#define ID_PROCESS_PAGE_SETPRIORITY_HIGH 32810 +#define ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL 32811 +#define ID_PROCESS_PAGE_SETPRIORITY_NORMAL 32812 +#define ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL 32813 +#define ID_PROCESS_PAGE_SETPRIORITY_LOW 32814 +#define ID_PROCESS_PAGE_DEBUGCHANNELS 32815 +#define IDS_LICENSE 32816 +#define IDC_STATIC -1 + +/* + * Next default values for new objects + * + */ +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 157 +#define _APS_NEXT_COMMAND_VALUE 32817 +#define _APS_NEXT_CONTROL_VALUE 1048 +#define _APS_NEXT_SYMED_VALUE 110 +#endif +#endif diff --git a/programs/taskmgr/run.c b/programs/taskmgr/run.c new file mode 100644 index 00000000000..f381d94f69a --- /dev/null +++ b/programs/taskmgr/run.c @@ -0,0 +1,82 @@ +/* + * ReactOS Task Manager + * + * run.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" + +typedef void (WINAPI *RUNFILEDLG)( +HWND hwndOwner, +HICON hIcon, +LPCSTR lpstrDirectory, +LPCSTR lpstrTitle, +LPCSTR lpstrDescription, +UINT uFlags); + +/* + * Flags for RunFileDlg + */ + +#define RFF_NOBROWSE 0x01 /* Removes the browse button. */ +#define RFF_NODEFAULT 0x02 /* No default item selected. */ +#define RFF_CALCDIRECTORY 0x04 /* Calculates the working directory from the file name. */ +#define RFF_NOLABEL 0x08 /* Removes the edit box label. */ +#define RFF_NOSEPARATEMEM 0x20 /* Removes the Separate Memory Space check box (Windows NT only). */ + +void TaskManager_OnFileNew(void) +{ + HMODULE hShell32; + RUNFILEDLG RunFileDlg; + OSVERSIONINFO versionInfo; + WCHAR wTitle[40]; + WCHAR wText[256]; + char szTitle[40] = "Create New Task"; + char szText[256] = "Type the name of a program, folder, document, or Internet resource, and Task Manager will open it for you."; + + hShell32 = LoadLibrary(_T("SHELL32.DLL")); + RunFileDlg = (RUNFILEDLG)(FARPROC)GetProcAddress(hShell32, (char*)((long)0x3D)); + + /* Show "Run..." dialog */ + if (RunFileDlg) + { + versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&versionInfo); + + if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTitle, -1, wTitle, 40); + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szText, -1, wText, 256); + RunFileDlg(hMainWnd, 0, NULL, (LPCSTR)wTitle, (LPCSTR)wText, RFF_CALCDIRECTORY); + } + else + RunFileDlg(hMainWnd, 0, NULL, szTitle, szText, RFF_CALCDIRECTORY); + } + + FreeLibrary(hShell32); +} diff --git a/programs/taskmgr/taskmgr.c b/programs/taskmgr/taskmgr.c new file mode 100644 index 00000000000..40d4be457cd --- /dev/null +++ b/programs/taskmgr/taskmgr.c @@ -0,0 +1,1034 @@ +/* + * ReactOS Task Manager + * + * taskmgr.c : Defines the entry point for the application. + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "resource.h" +#include "taskmgr.h" +#include "perfdata.h" +#include "column.h" + +#define STATUS_WINDOW 2001 + +/* Global Variables: */ +HINSTANCE hInst; /* current instance */ + +HWND hMainWnd; /* Main Window */ +HWND hStatusWnd; /* Status Bar Window */ +HWND hTabWnd; /* Tab Control Window */ + +int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */ +int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */ + +int nOldWidth; /* Holds the previous client area width */ +int nOldHeight; /* Holds the previous client area height */ + +BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */ + +TASKMANAGER_SETTINGS TaskManagerSettings; + + +int APIENTRY WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + HANDLE hProcess; + HANDLE hToken; + TOKEN_PRIVILEGES tkp; + + /* Initialize global variables */ + hInst = hInstance; + + /* Change our priority class to HIGH */ + hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); + SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS); + CloseHandle(hProcess); + + /* Now lets get the SE_DEBUG_NAME priviledge + * so that we can debug processes + */ + + /* Get a token for this process. */ + if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { + /* Get the LUID for the debug privilege. */ + LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); + + tkp.PrivilegeCount = 1; /* one privilege to set */ + tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + /* Get the debug privilege for this process. */ + AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); + } + + /* Load our settings from the registry */ + LoadSettings(); + + /* Initialize perf data */ + if (!PerfDataInitialize()) { + return -1; + } + + DialogBox(hInst, (LPCTSTR)IDD_TASKMGR_DIALOG, NULL, (DLGPROC)TaskManagerWndProc); + + /* Save our settings to the registry */ + SaveSettings(); + PerfDataUninitialize(); + return 0; +} + +/* Message handler for dialog box. */ +LRESULT CALLBACK TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + HDC hdc; + PAINTSTRUCT ps; + LPRECT pRC; + RECT rc; + int idctrl; + LPNMHDR pnmh; + WINDOWPLACEMENT wp; + + switch (message) { + case WM_INITDIALOG: + hMainWnd = hDlg; + return OnCreate(hDlg); + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } + /* Process menu commands */ + switch (LOWORD(wParam)) + { + case ID_FILE_NEW: + TaskManager_OnFileNew(); + break; + case ID_OPTIONS_ALWAYSONTOP: + TaskManager_OnOptionsAlwaysOnTop(); + break; + case ID_OPTIONS_MINIMIZEONUSE: + TaskManager_OnOptionsMinimizeOnUse(); + break; + case ID_OPTIONS_HIDEWHENMINIMIZED: + TaskManager_OnOptionsHideWhenMinimized(); + break; + case ID_OPTIONS_SHOW16BITTASKS: + TaskManager_OnOptionsShow16BitTasks(); + break; + case ID_VIEW_LARGE: + ApplicationPage_OnViewLargeIcons(); + break; + case ID_VIEW_SMALL: + ApplicationPage_OnViewSmallIcons(); + break; + case ID_VIEW_DETAILS: + ApplicationPage_OnViewDetails(); + break; + case ID_VIEW_SHOWKERNELTIMES: + PerformancePage_OnViewShowKernelTimes(); + break; + case ID_VIEW_CPUHISTORY_ONEGRAPHALL: + PerformancePage_OnViewCPUHistoryOneGraphAll(); + break; + case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU: + PerformancePage_OnViewCPUHistoryOneGraphPerCPU(); + break; + case ID_VIEW_UPDATESPEED_HIGH: + TaskManager_OnViewUpdateSpeedHigh(); + break; + case ID_VIEW_UPDATESPEED_NORMAL: + TaskManager_OnViewUpdateSpeedNormal(); + break; + case ID_VIEW_UPDATESPEED_LOW: + TaskManager_OnViewUpdateSpeedLow(); + break; + case ID_VIEW_UPDATESPEED_PAUSED: + TaskManager_OnViewUpdateSpeedPaused(); + break; + case ID_VIEW_SELECTCOLUMNS: + ProcessPage_OnViewSelectColumns(); + break; + case ID_VIEW_REFRESH: + PostMessage(hDlg, WM_TIMER, 0, 0); + break; + case ID_WINDOWS_TILEHORIZONTALLY: + ApplicationPage_OnWindowsTileHorizontally(); + break; + case ID_WINDOWS_TILEVERTICALLY: + ApplicationPage_OnWindowsTileVertically(); + break; + case ID_WINDOWS_MINIMIZE: + ApplicationPage_OnWindowsMinimize(); + break; + case ID_WINDOWS_MAXIMIZE: + ApplicationPage_OnWindowsMaximize(); + break; + case ID_WINDOWS_CASCADE: + ApplicationPage_OnWindowsCascade(); + break; + case ID_WINDOWS_BRINGTOFRONT: + ApplicationPage_OnWindowsBringToFront(); + break; + case ID_APPLICATION_PAGE_SWITCHTO: + ApplicationPage_OnSwitchTo(); + break; + case ID_APPLICATION_PAGE_ENDTASK: + ApplicationPage_OnEndTask(); + break; + case ID_APPLICATION_PAGE_GOTOPROCESS: + ApplicationPage_OnGotoProcess(); + break; + case ID_PROCESS_PAGE_ENDPROCESS: + ProcessPage_OnEndProcess(); + break; + case ID_PROCESS_PAGE_ENDPROCESSTREE: + ProcessPage_OnEndProcessTree(); + break; + case ID_PROCESS_PAGE_DEBUG: + ProcessPage_OnDebug(); + break; + case ID_PROCESS_PAGE_SETAFFINITY: + ProcessPage_OnSetAffinity(); + break; + case ID_PROCESS_PAGE_SETPRIORITY_REALTIME: + ProcessPage_OnSetPriorityRealTime(); + break; + case ID_PROCESS_PAGE_SETPRIORITY_HIGH: + ProcessPage_OnSetPriorityHigh(); + break; + case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL: + ProcessPage_OnSetPriorityAboveNormal(); + break; + case ID_PROCESS_PAGE_SETPRIORITY_NORMAL: + ProcessPage_OnSetPriorityNormal(); + break; + case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL: + ProcessPage_OnSetPriorityBelowNormal(); + break; + case ID_PROCESS_PAGE_SETPRIORITY_LOW: + ProcessPage_OnSetPriorityLow(); + break; + case ID_PROCESS_PAGE_DEBUGCHANNELS: + ProcessPage_OnDebugChannels(); + break; + case ID_HELP_ABOUT: + OnAbout(); + break; + case ID_FILE_EXIT: + DestroyWindow(hDlg); + break; + } + break; + + case WM_NOTIFY: + idctrl = (int)wParam; + pnmh = (LPNMHDR)lParam; + if ((pnmh->hwndFrom == hTabWnd) && + (pnmh->idFrom == IDC_TAB) && + (pnmh->code == TCN_SELCHANGE)) + { + TaskManager_OnTabWndSelChange(); + } + break; + + case WM_NCPAINT: + hdc = GetDC(hDlg); + GetClientRect(hDlg, &rc); + Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); + ReleaseDC(hDlg, hdc); + break; + + case WM_PAINT: + hdc = BeginPaint(hDlg, &ps); + GetClientRect(hDlg, &rc); + Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); + EndPaint(hDlg, &ps); + break; + + case WM_SIZING: + /* Make sure the user is sizing the dialog */ + /* in an acceptable range */ + pRC = (LPRECT)lParam; + if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) { + /* If the width is too small enlarge it to the minimum */ + if (nMinimumWidth > (pRC->right - pRC->left)) + pRC->left = pRC->right - nMinimumWidth; + } else { + /* If the width is too small enlarge it to the minimum */ + if (nMinimumWidth > (pRC->right - pRC->left)) + pRC->right = pRC->left + nMinimumWidth; + } + if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) { + /* If the height is too small enlarge it to the minimum */ + if (nMinimumHeight > (pRC->bottom - pRC->top)) + pRC->top = pRC->bottom - nMinimumHeight; + } else { + /* If the height is too small enlarge it to the minimum */ + if (nMinimumHeight > (pRC->bottom - pRC->top)) + pRC->bottom = pRC->top + nMinimumHeight; + } + return TRUE; + break; + + case WM_SIZE: + /* Handle the window sizing in it's own function */ + OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); + break; + + case WM_MOVE: + /* Handle the window moving in it's own function */ + OnMove(wParam, LOWORD(lParam), HIWORD(lParam)); + break; + + case WM_DESTROY: + ShowWindow(hDlg, SW_HIDE); + TrayIcon_ShellRemoveTrayIcon(); + wp.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(hDlg, &wp); + TaskManagerSettings.Left = wp.rcNormalPosition.left; + TaskManagerSettings.Top = wp.rcNormalPosition.top; + TaskManagerSettings.Right = wp.rcNormalPosition.right; + TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom; + if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED)) + TaskManagerSettings.Maximized = TRUE; + else + TaskManagerSettings.Maximized = FALSE; + return DefWindowProc(hDlg, message, wParam, lParam); + + case WM_TIMER: + /* Refresh the performance data */ + PerfDataRefresh(); + RefreshApplicationPage(); + RefreshProcessPage(); + RefreshPerformancePage(); + TrayIcon_ShellUpdateTrayIcon(); + break; + + case WM_ENTERMENULOOP: + TaskManager_OnEnterMenuLoop(hDlg); + break; + case WM_EXITMENULOOP: + TaskManager_OnExitMenuLoop(hDlg); + break; + case WM_MENUSELECT: + TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam); + break; + } + + return 0; +} + +void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr) +{ + SetBkColor(hDC, clr); + ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL); +} + +void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr) +{ + RECT rect; + + SetBkColor(hDC, clr); + rect.left = x; + rect.top = y; + rect.right = x + cx; + rect.bottom = y + cy; + ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); +} + +void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight) +{ + FillSolidRect2(hDC, x, y, cx - 1, 1, clrTopLeft); + FillSolidRect2(hDC, x, y, 1, cy - 1, clrTopLeft); + FillSolidRect2(hDC, x + cx, y, -1, cy, clrBottomRight); + FillSolidRect2(hDC, x, y + cy, cx, -1, clrBottomRight); +} + +void Draw3dRect2(HDC hDC, LPRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight) +{ + Draw3dRect(hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left, + lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight); +} + +void Font_DrawText(HDC hDC, LPCTSTR lpszText, int x, int y) +{ + HDC hFontDC; + HBITMAP hFontBitmap; + HBITMAP hOldBitmap; + int i; + + hFontDC = CreateCompatibleDC(hDC); + hFontBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FONT)); + hOldBitmap = (HBITMAP)SelectObject(hFontDC, hFontBitmap); + + for (i = 0; i < (int)_tcslen(lpszText); i++) { + if ((lpszText[i] >= '0') && (lpszText[i] <= '9')) { + BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, (lpszText[i] - '0') * 8, 0, SRCCOPY); + } + else if (lpszText[i] == 'K') + { + BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY); + } + else if (lpszText[i] == '%') + { + BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY); + } + } + SelectObject(hFontDC, hOldBitmap); + DeleteObject(hFontBitmap); + DeleteDC(hFontDC); +} + +BOOL OnCreate(HWND hWnd) +{ + HMENU hMenu; + HMENU hEditMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; + HMENU hCPUHistoryMenu; + int nActivePage; + int nParts[3]; + RECT rc; + TCHAR szTemp[256]; + TCITEM item; + + SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER))); + + /* Initialize the Windows Common Controls DLL */ + InitCommonControls(); + + /* Get the minimum window sizes */ + GetWindowRect(hWnd, &rc); + nMinimumWidth = (rc.right - rc.left); + nMinimumHeight = (rc.bottom - rc.top); + + /* Create the status bar */ + hStatusWnd = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, _T(""), hWnd, STATUS_WINDOW); + if(!hStatusWnd) + return FALSE; + + /* Create the status bar panes */ + nParts[0] = 100; + nParts[1] = 210; + nParts[2] = 400; + SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts); + + /* Create tab pages */ + hTabWnd = GetDlgItem(hWnd, IDC_TAB); +#if 1 + hApplicationPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_APPLICATION_PAGE), hWnd, (DLGPROC)ApplicationPageWndProc); + hProcessPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROCESS_PAGE), hWnd, (DLGPROC)ProcessPageWndProc); + hPerformancePage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE), hWnd, (DLGPROC)PerformancePageWndProc); +#else + hApplicationPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_APPLICATION_PAGE), hTabWnd, (DLGPROC)ApplicationPageWndProc); + hProcessPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROCESS_PAGE), hTabWnd, (DLGPROC)ProcessPageWndProc); + hPerformancePage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE), hTabWnd, (DLGPROC)PerformancePageWndProc); +#endif + + /* Insert tabs */ + _tcscpy(szTemp, _T("Applications")); + memset(&item, 0, sizeof(TCITEM)); + item.mask = TCIF_TEXT; + item.pszText = szTemp; + TabCtrl_InsertItem(hTabWnd, 0, &item); + _tcscpy(szTemp, _T("Processes")); + memset(&item, 0, sizeof(TCITEM)); + item.mask = TCIF_TEXT; + item.pszText = szTemp; + TabCtrl_InsertItem(hTabWnd, 1, &item); + _tcscpy(szTemp, _T("Performance")); + memset(&item, 0, sizeof(TCITEM)); + item.mask = TCIF_TEXT; + item.pszText = szTemp; + TabCtrl_InsertItem(hTabWnd, 2, &item); + + /* Size everything correctly */ + GetClientRect(hWnd, &rc); + nOldWidth = rc.right; + nOldHeight = rc.bottom; + /* nOldStartX = rc.left; */ + /*nOldStartY = rc.top; */ + +#define PAGE_OFFSET_LEFT 17 +#define PAGE_OFFSET_TOP 72 +#define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2) +#define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32) + + if ((TaskManagerSettings.Left != 0) || + (TaskManagerSettings.Top != 0) || + (TaskManagerSettings.Right != 0) || + (TaskManagerSettings.Bottom != 0)) + { + MoveWindow(hWnd, TaskManagerSettings.Left, TaskManagerSettings.Top, TaskManagerSettings.Right - TaskManagerSettings.Left, TaskManagerSettings.Bottom - TaskManagerSettings.Top, TRUE); +#ifdef __GNUC__TEST__ + MoveWindow(hApplicationPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE); + MoveWindow(hProcessPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE); + MoveWindow(hPerformancePage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE); +#endif + } + if (TaskManagerSettings.Maximized) + ShowWindow(hWnd, SW_MAXIMIZE); + + /* Set the always on top style */ + hMenu = GetMenu(hWnd); + hEditMenu = GetSubMenu(hMenu, 1); + hViewMenu = GetSubMenu(hMenu, 2); + hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + hCPUHistoryMenu = GetSubMenu(hViewMenu, 7); + + /* Check or uncheck the always on top menu item */ + if (TaskManagerSettings.AlwaysOnTop) { + CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED); + SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + } else { + CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED); + SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + } + + /* Check or uncheck the minimize on use menu item */ + if (TaskManagerSettings.MinimizeOnUse) + CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED); + else + CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED); + + /* Check or uncheck the hide when minimized menu item */ + if (TaskManagerSettings.HideWhenMinimized) + CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED); + else + CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED); + + /* Check or uncheck the show 16-bit tasks menu item */ + if (TaskManagerSettings.Show16BitTasks) + CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED); + else + CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED); + + if (TaskManagerSettings.View_LargeIcons) + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND); + else if (TaskManagerSettings.View_SmallIcons) + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND); + else + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND); + + if (TaskManagerSettings.ShowKernelTimes) + CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED); + else + CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED); + + if (TaskManagerSettings.UpdateSpeed == 1) + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND); + else if (TaskManagerSettings.UpdateSpeed == 2) + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND); + else if (TaskManagerSettings.UpdateSpeed == 4) + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND); + else + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND); + + if (TaskManagerSettings.CPUHistory_OneGraphPerCPU) + CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND); + else + CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND); + + nActivePage = TaskManagerSettings.ActiveTabPage; + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 0); + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1); + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2); + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage); + + if (TaskManagerSettings.UpdateSpeed == 0) + KillTimer(hWnd, 1); + else if (TaskManagerSettings.UpdateSpeed == 1) + { + KillTimer(hWnd, 1); + SetTimer(hWnd, 1, 1000, NULL); + } + else if (TaskManagerSettings.UpdateSpeed == 2) + { + KillTimer(hWnd, 1); + SetTimer(hWnd, 1, 2000, NULL); + } + else if (TaskManagerSettings.UpdateSpeed == 4) + { + KillTimer(hWnd, 1); + SetTimer(hWnd, 1, 4000, NULL); + } + + /* + * Refresh the performance data + * Sample it twice so we can establish + * the delta values & cpu usage + */ + PerfDataRefresh(); + PerfDataRefresh(); + + RefreshApplicationPage(); + RefreshProcessPage(); + RefreshPerformancePage(); + + TrayIcon_ShellAddTrayIcon(); + + return TRUE; +} + +/* OnMove() + * This function handles all the moving events for the application + * It moves every child window that needs moving + */ +void OnMove( UINT nType, int cx, int cy ) +{ +#ifdef __GNUC__TEST__ + MoveWindow(hApplicationPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE); + MoveWindow(hProcessPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE); + MoveWindow(hPerformancePage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE); +#endif +} + +/* OnSize() + * This function handles all the sizing events for the application + * It re-sizes every window, and child window that needs re-sizing + */ +void OnSize( UINT nType, int cx, int cy ) +{ + int nParts[3]; + int nXDifference; + int nYDifference; + RECT rc; + + if (nType == SIZE_MINIMIZED) + return; + + nXDifference = cx - nOldWidth; + nYDifference = cy - nOldHeight; + nOldWidth = cx; + nOldHeight = cy; + + /* Update the status bar size */ + GetWindowRect(hStatusWnd, &rc); + SendMessage(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top))); + + /* Update the status bar pane sizes */ + nParts[0] = bInMenuLoop ? -1 : 100; + nParts[1] = 210; + nParts[2] = cx; + SendMessage(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (long)nParts); + + /* Resize the tab control */ + GetWindowRect(hTabWnd, &rc); + cx = (rc.right - rc.left) + nXDifference; + cy = (rc.bottom - rc.top) + nYDifference; + SetWindowPos(hTabWnd, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + + /* Resize the application page */ + GetWindowRect(hApplicationPage, &rc); + cx = (rc.right - rc.left) + nXDifference; + cy = (rc.bottom - rc.top) + nYDifference; + SetWindowPos(hApplicationPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + + /* Resize the process page */ + GetWindowRect(hProcessPage, &rc); + cx = (rc.right - rc.left) + nXDifference; + cy = (rc.bottom - rc.top) + nYDifference; + SetWindowPos(hProcessPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + + /* Resize the performance page */ + GetWindowRect(hPerformancePage, &rc); + cx = (rc.right - rc.left) + nXDifference; + cy = (rc.bottom - rc.top) + nYDifference; + SetWindowPos(hPerformancePage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); +} + +void LoadSettings(void) +{ + HKEY hKey; + TCHAR szSubKey[] = _T("Software\\ReactWare\\TaskManager"); + int i; + DWORD dwSize; + + /* Window size & position settings */ + TaskManagerSettings.Maximized = FALSE; + TaskManagerSettings.Left = 0; + TaskManagerSettings.Top = 0; + TaskManagerSettings.Right = 0; + TaskManagerSettings.Bottom = 0; + + /* Tab settings */ + TaskManagerSettings.ActiveTabPage = 0; + + /* Options menu settings */ + TaskManagerSettings.AlwaysOnTop = FALSE; + TaskManagerSettings.MinimizeOnUse = TRUE; + TaskManagerSettings.HideWhenMinimized = TRUE; + TaskManagerSettings.Show16BitTasks = TRUE; + + /* Update speed settings */ + TaskManagerSettings.UpdateSpeed = 2; + + /* Applications page settings */ + TaskManagerSettings.View_LargeIcons = FALSE; + TaskManagerSettings.View_SmallIcons = FALSE; + TaskManagerSettings.View_Details = TRUE; + + /* Processes page settings */ + TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; /* Server-only? */ + TaskManagerSettings.Column_ImageName = TRUE; + TaskManagerSettings.Column_PID = TRUE; + TaskManagerSettings.Column_CPUUsage = TRUE; + TaskManagerSettings.Column_CPUTime = TRUE; + TaskManagerSettings.Column_MemoryUsage = TRUE; + TaskManagerSettings.Column_MemoryUsageDelta = FALSE; + TaskManagerSettings.Column_PeakMemoryUsage = FALSE; + TaskManagerSettings.Column_PageFaults = FALSE; + TaskManagerSettings.Column_USERObjects = FALSE; + TaskManagerSettings.Column_IOReads = FALSE; + TaskManagerSettings.Column_IOReadBytes = FALSE; + TaskManagerSettings.Column_SessionID = FALSE; /* Server-only? */ + TaskManagerSettings.Column_UserName = FALSE; /* Server-only? */ + TaskManagerSettings.Column_PageFaultsDelta = FALSE; + TaskManagerSettings.Column_VirtualMemorySize = FALSE; + TaskManagerSettings.Column_PagedPool = FALSE; + TaskManagerSettings.Column_NonPagedPool = FALSE; + TaskManagerSettings.Column_BasePriority = FALSE; + TaskManagerSettings.Column_HandleCount = FALSE; + TaskManagerSettings.Column_ThreadCount = FALSE; + TaskManagerSettings.Column_GDIObjects = FALSE; + TaskManagerSettings.Column_IOWrites = FALSE; + TaskManagerSettings.Column_IOWriteBytes = FALSE; + TaskManagerSettings.Column_IOOther = FALSE; + TaskManagerSettings.Column_IOOtherBytes = FALSE; + + for (i = 0; i < 25; i++) { + TaskManagerSettings.ColumnOrderArray[i] = i; + } + TaskManagerSettings.ColumnSizeArray[0] = 105; + TaskManagerSettings.ColumnSizeArray[1] = 50; + TaskManagerSettings.ColumnSizeArray[2] = 107; + TaskManagerSettings.ColumnSizeArray[3] = 70; + TaskManagerSettings.ColumnSizeArray[4] = 35; + TaskManagerSettings.ColumnSizeArray[5] = 70; + TaskManagerSettings.ColumnSizeArray[6] = 70; + TaskManagerSettings.ColumnSizeArray[7] = 100; + TaskManagerSettings.ColumnSizeArray[8] = 70; + TaskManagerSettings.ColumnSizeArray[9] = 70; + TaskManagerSettings.ColumnSizeArray[10] = 70; + TaskManagerSettings.ColumnSizeArray[11] = 70; + TaskManagerSettings.ColumnSizeArray[12] = 70; + TaskManagerSettings.ColumnSizeArray[13] = 70; + TaskManagerSettings.ColumnSizeArray[14] = 60; + TaskManagerSettings.ColumnSizeArray[15] = 60; + TaskManagerSettings.ColumnSizeArray[16] = 60; + TaskManagerSettings.ColumnSizeArray[17] = 60; + TaskManagerSettings.ColumnSizeArray[18] = 60; + TaskManagerSettings.ColumnSizeArray[19] = 70; + TaskManagerSettings.ColumnSizeArray[20] = 70; + TaskManagerSettings.ColumnSizeArray[21] = 70; + TaskManagerSettings.ColumnSizeArray[22] = 70; + TaskManagerSettings.ColumnSizeArray[23] = 70; + TaskManagerSettings.ColumnSizeArray[24] = 70; + + TaskManagerSettings.SortColumn = 1; + TaskManagerSettings.SortAscending = TRUE; + + /* Performance page settings */ + TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE; + TaskManagerSettings.ShowKernelTimes = FALSE; + + /* Open the key */ + if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS) + return; + /* Read the settings */ + dwSize = sizeof(TASKMANAGER_SETTINGS); + RegQueryValueEx(hKey, _T("Preferences"), NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize); + + /* Close the key */ + RegCloseKey(hKey); +} + +void SaveSettings(void) +{ + HKEY hKey; + TCHAR szSubKey1[] = _T("Software"); + TCHAR szSubKey2[] = _T("Software\\ReactWare"); + TCHAR szSubKey3[] = _T("Software\\ReactWare\\TaskManager"); + + /* Open (or create) the key */ + hKey = NULL; + RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey1, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); + RegCloseKey(hKey); + hKey = NULL; + RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey2, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); + RegCloseKey(hKey); + hKey = NULL; + if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS) + return; + /* Save the settings */ + RegSetValueEx(hKey, _T("Preferences"), 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS)); + /* Close the key */ + RegCloseKey(hKey); +} + +void TaskManager_OnEnterMenuLoop(HWND hWnd) +{ + int nParts; + + /* Update the status bar pane sizes */ + nParts = -1; + SendMessage(hStatusWnd, SB_SETPARTS, 1, (long)&nParts); + bInMenuLoop = TRUE; + SendMessage(hStatusWnd, SB_SETTEXT, (WPARAM)0, (LPARAM)_T("")); +} + +void TaskManager_OnExitMenuLoop(HWND hWnd) +{ + RECT rc; + int nParts[3]; + TCHAR text[260]; + + bInMenuLoop = FALSE; + /* Update the status bar pane sizes */ + GetClientRect(hWnd, &rc); + nParts[0] = 100; + nParts[1] = 210; + nParts[2] = rc.right; + SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts); + SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)_T("")); + wsprintf(text, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage()); + SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); + wsprintf(text, _T("Processes: %d"), PerfDataGetProcessCount()); + SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); +} + +void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu) +{ + TCHAR str[100]; + + _tcscpy(str, TEXT("")); + if (LoadString(hInst, nItemID, str, 100)) { + /* load appropriate string */ + LPTSTR lpsz = str; + /* first newline terminates actual string */ + lpsz = _tcschr(lpsz, '\n'); + if (lpsz != NULL) + *lpsz = '\0'; + } + SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)str); +} + +void TaskManager_OnViewUpdateSpeedHigh(void) +{ + HMENU hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + + TaskManagerSettings.UpdateSpeed = 1; + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND); + + KillTimer(hMainWnd, 1); + SetTimer(hMainWnd, 1, 1000, NULL); +} + +void TaskManager_OnViewUpdateSpeedNormal(void) +{ + HMENU hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + + TaskManagerSettings.UpdateSpeed = 2; + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND); + + KillTimer(hMainWnd, 1); + SetTimer(hMainWnd, 1, 2000, NULL); +} + +void TaskManager_OnViewUpdateSpeedLow(void) +{ + HMENU hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + + TaskManagerSettings.UpdateSpeed = 4; + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND); + + KillTimer(hMainWnd, 1); + SetTimer(hMainWnd, 1, 4000, NULL); +} + +void TaskManager_OnViewRefresh(void) +{ + PostMessage(hMainWnd, WM_TIMER, 0, 0); +} + +void TaskManager_OnViewUpdateSpeedPaused(void) +{ + HMENU hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + TaskManagerSettings.UpdateSpeed = 0; + CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND); + KillTimer(hMainWnd, 1); +} + +void TaskManager_OnTabWndSelChange(void) +{ + int i; + HMENU hMenu; + HMENU hOptionsMenu; + HMENU hViewMenu; + HMENU hSubMenu; + + hMenu = GetMenu(hMainWnd); + hViewMenu = GetSubMenu(hMenu, 2); + hOptionsMenu = GetSubMenu(hMenu, 1); + TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd); + for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) { + hSubMenu = GetSubMenu(hViewMenu, i); + if (hSubMenu) + DestroyMenu(hSubMenu); + RemoveMenu(hViewMenu, i, MF_BYPOSITION); + } + RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION); + switch (TaskManagerSettings.ActiveTabPage) { + case 0: + ShowWindow(hApplicationPage, SW_SHOW); + ShowWindow(hProcessPage, SW_HIDE); + ShowWindow(hPerformancePage, SW_HIDE); + BringWindowToTop(hApplicationPage); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_LARGE, _T("Lar&ge Icons")); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SMALL, _T("S&mall Icons")); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_DETAILS, _T("&Details")); + + if (GetMenuItemCount(hMenu) <= 4) { + hSubMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_WINDOWSMENU)); + InsertMenu(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT)hSubMenu, _T("&Windows")); + DrawMenuBar(hMainWnd); + } + if (TaskManagerSettings.View_LargeIcons) + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND); + else if (TaskManagerSettings.View_SmallIcons) + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND); + else + CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND); + /* + * Give the application list control focus + */ + SetFocus(hApplicationPageListCtrl); + break; + + case 1: + ShowWindow(hApplicationPage, SW_HIDE); + ShowWindow(hProcessPage, SW_SHOW); + ShowWindow(hPerformancePage, SW_HIDE); + BringWindowToTop(hProcessPage); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, _T("&Select Columns...")); + AppendMenu(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, _T("&Show 16-bit tasks")); + if (TaskManagerSettings.Show16BitTasks) + CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED); + if (GetMenuItemCount(hMenu) > 4) + { + RemoveMenu(hMenu, 3, MF_BYPOSITION); + DrawMenuBar(hMainWnd); + } + /* + * Give the process list control focus + */ + SetFocus(hProcessPageListCtrl); + break; + + case 2: + ShowWindow(hApplicationPage, SW_HIDE); + ShowWindow(hProcessPage, SW_HIDE); + ShowWindow(hPerformancePage, SW_SHOW); + BringWindowToTop(hPerformancePage); + if (GetMenuItemCount(hMenu) > 4) { + RemoveMenu(hMenu, 3, MF_BYPOSITION); + DrawMenuBar(hMainWnd); + } + hSubMenu = CreatePopupMenu(); + AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, _T("&One Graph, All CPUs")); + AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, _T("One Graph &Per CPU")); + AppendMenu(hViewMenu, MF_STRING|MF_POPUP, (UINT)hSubMenu, _T("&CPU History")); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, _T("&Show Kernel Times")); + if (TaskManagerSettings.ShowKernelTimes) + CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED); + else + CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED); + if (TaskManagerSettings.CPUHistory_OneGraphPerCPU) + CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND); + else + CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND); + /* + * Give the tab control focus + */ + SetFocus(hTabWnd); + break; + } +} + +LPTSTR GetLastErrorText(LPTSTR lpszBuf, DWORD dwSize) +{ + DWORD dwRet; + LPTSTR lpszTemp = NULL; + + dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY, + NULL, + GetLastError(), + LANG_NEUTRAL, + (LPTSTR)&lpszTemp, + 0, + NULL ); + + /* supplied buffer is not long enough */ + if (!dwRet || ( (long)dwSize < (long)dwRet+14)) { + lpszBuf[0] = TEXT('\0'); + } else { + lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); /*remove cr and newline character */ + _stprintf(lpszBuf, TEXT("%s (0x%x)"), lpszTemp, (int)GetLastError()); + } + if (lpszTemp) { + LocalFree((HLOCAL)lpszTemp); + } + return lpszBuf; +} diff --git a/programs/taskmgr/taskmgr.h b/programs/taskmgr/taskmgr.h new file mode 100644 index 00000000000..20dcbb80035 --- /dev/null +++ b/programs/taskmgr/taskmgr.h @@ -0,0 +1,226 @@ +/* + * ReactOS Task Manager + * + * taskmgr.h + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __TASKMGR_H__ +#define __TASKMGR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _MSC_VER +/*MF +typedef struct _IO_COUNTERS { + ULONGLONG ReadOperationCount; + ULONGLONG WriteOperationCount; + ULONGLONG OtherOperationCount; + ULONGLONG ReadTransferCount; + ULONGLONG WriteTransferCount; + ULONGLONG OtherTransferCount; +} IO_COUNTERS, *PIO_COUNTERS; +*/ +#endif /* _MSC_VER */ + +#include "resource.h" + +#define RUN_APPS_PAGE +#define RUN_PROC_PAGE +#define RUN_PERF_PAGE + +#define STATUS_WINDOW 2001 + +typedef struct +{ + /* Window size & position settings */ + BOOL Maximized; + int Left; + int Top; + int Right; + int Bottom; + + /* Tab settings */ + int ActiveTabPage; + + /* Options menu settings */ + BOOL AlwaysOnTop; + BOOL MinimizeOnUse; + BOOL HideWhenMinimized; + BOOL Show16BitTasks; + + /* Update speed settings */ + /* How many half-seconds in between updates (i.e. 0 - Paused, 1 - High, 2 - Normal, 4 - Low) */ + int UpdateSpeed; + + /* Applications page settings */ + BOOL View_LargeIcons; + BOOL View_SmallIcons; + BOOL View_Details; + + /* Processes page settings */ + BOOL ShowProcessesFromAllUsers; /* Server-only? */ + BOOL Column_ImageName; + BOOL Column_PID; + BOOL Column_CPUUsage; + BOOL Column_CPUTime; + BOOL Column_MemoryUsage; + BOOL Column_MemoryUsageDelta; + BOOL Column_PeakMemoryUsage; + BOOL Column_PageFaults; + BOOL Column_USERObjects; + BOOL Column_IOReads; + BOOL Column_IOReadBytes; + BOOL Column_SessionID; /* Server-only? */ + BOOL Column_UserName; /* Server-only? */ + BOOL Column_PageFaultsDelta; + BOOL Column_VirtualMemorySize; + BOOL Column_PagedPool; + BOOL Column_NonPagedPool; + BOOL Column_BasePriority; + BOOL Column_HandleCount; + BOOL Column_ThreadCount; + BOOL Column_GDIObjects; + BOOL Column_IOWrites; + BOOL Column_IOWriteBytes; + BOOL Column_IOOther; + BOOL Column_IOOtherBytes; + int ColumnOrderArray[25]; + int ColumnSizeArray[25]; + int SortColumn; + BOOL SortAscending; + + /* Performance page settings */ + BOOL CPUHistory_OneGraphPerCPU; + BOOL ShowKernelTimes; + +} TASKMANAGER_SETTINGS, *LPTASKMANAGER_SETTINGS; + +/* Global Variables: */ +extern HINSTANCE hInst; /* current instance */ +extern HWND hMainWnd; /* Main Window */ +extern HWND hStatusWnd; /* Status Bar Window */ +extern HWND hTabWnd; /* Tab Control Window */ +extern int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */ +extern int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */ +extern int nOldWidth; /* Holds the previous client area width */ +extern int nOldHeight; /* Holds the previous client area height */ +extern TASKMANAGER_SETTINGS TaskManagerSettings; + +extern LONG OldProcessListWndProc; +extern LONG OldGraphWndProc; + +extern HWND hProcessPage; /* Process List Property Page */ +extern HWND hProcessPageListCtrl; /* Process ListCtrl Window */ +extern HWND hProcessPageHeaderCtrl; /* Process Header Control */ +extern HWND hProcessPageEndProcessButton; /* Process End Process button */ +extern HWND hProcessPageShowAllProcessesButton; /* Process Show All Processes checkbox */ +extern HWND hPerformancePage; /* Performance Property Page */ + +extern HWND hApplicationPage; /* Application List Property Page */ +extern HWND hApplicationPageListCtrl; /* Application ListCtrl Window */ +extern HWND hApplicationPageEndTaskButton; /* Application End Task button */ +extern HWND hApplicationPageSwitchToButton; /* Application Switch To button */ +extern HWND hApplicationPageNewTaskButton; /* Application New Task button */ + + +/* Foward declarations of functions included in this code module: */ +LRESULT CALLBACK TaskManagerWndProc(HWND, UINT, WPARAM, LPARAM); +BOOL OnCreate(HWND hWnd); +void OnSize(UINT nType, int cx, int cy); +void OnMove(UINT nType, int cx, int cy); +void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr); +void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr); +void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight); +void Draw3dRect2(HDC hDC, LPRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight); +void Font_DrawText(HDC hDC, LPCTSTR lpszText, int x, int y); +void LoadSettings(void); +void SaveSettings(void); +void TaskManager_OnEnterMenuLoop(HWND hWnd); +void TaskManager_OnExitMenuLoop(HWND hWnd); +void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu); +void TaskManager_OnViewUpdateSpeedHigh(void); +void TaskManager_OnViewUpdateSpeedNormal(void); +void TaskManager_OnViewUpdateSpeedLow(void); +void TaskManager_OnViewUpdateSpeedPaused(void); +void TaskManager_OnViewRefresh(void); +void TaskManager_OnTabWndSelChange(void); +void TaskManager_OnOptionsAlwaysOnTop(void); +void TaskManager_OnOptionsMinimizeOnUse(void); +void TaskManager_OnOptionsHideWhenMinimized(void); +void TaskManager_OnOptionsShow16BitTasks(void); +void TaskManager_OnFileNew(void); + +LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); + +void OnAbout(void); + +BOOL AreDebugChannelsSupported(void); + +void ProcessPage_OnSetAffinity(void); +void ProcessPage_OnDebug(void); +void ProcessPage_OnEndProcess(void); +void ProcessPage_OnEndProcessTree(void); +void ProcessPage_OnSetPriorityRealTime(void); +void ProcessPage_OnSetPriorityHigh(void); +void ProcessPage_OnSetPriorityAboveNormal(void); +void ProcessPage_OnSetPriorityNormal(void); +void ProcessPage_OnSetPriorityBelowNormal(void); +void ProcessPage_OnSetPriorityLow(void); +void ProcessPage_OnDebugChannels(void); + +HICON TrayIcon_GetProcessorUsageIcon(void); +BOOL TrayIcon_ShellAddTrayIcon(void); +BOOL TrayIcon_ShellRemoveTrayIcon(void); +BOOL TrayIcon_ShellUpdateTrayIcon(void); + +void PerformancePage_OnViewShowKernelTimes(void); +void PerformancePage_OnViewCPUHistoryOneGraphAll(void); +void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void); + +void ApplicationPage_OnViewLargeIcons(void); +void ApplicationPage_OnViewSmallIcons(void); +void ApplicationPage_OnViewDetails(void); +void ApplicationPage_OnWindowsTileHorizontally(void); +void ApplicationPage_OnWindowsTileVertically(void); +void ApplicationPage_OnWindowsMinimize(void); +void ApplicationPage_OnWindowsMaximize(void); +void ApplicationPage_OnWindowsCascade(void); +void ApplicationPage_OnWindowsBringToFront(void); +void ApplicationPage_OnSwitchTo(void); +void ApplicationPage_OnEndTask(void); +void ApplicationPage_OnGotoProcess(void); + +void RefreshApplicationPage(void); +void UpdateApplicationListControlViewSetting(void); +void RefreshPerformancePage(void); +void RefreshProcessPage(void); + +LRESULT CALLBACK ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK Graph_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK ProcessPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); + +#ifdef __cplusplus +} +#endif + +#endif /* __TASKMGR_H__ */ diff --git a/programs/taskmgr/taskmgr.rc b/programs/taskmgr/taskmgr.rc new file mode 100644 index 00000000000..5e5e6e0b3c5 --- /dev/null +++ b/programs/taskmgr/taskmgr.rc @@ -0,0 +1,938 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#define APSTUDIO_HIDDEN_SYMBOLS +#ifdef __GNUC__ +#include +//#include +//#include +#else +#include "windows.h" +#endif +#undef APSTUDIO_HIDDEN_SYMBOLS +#include "resource.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDR_TASKMANAGER MENU DISCARDABLE +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&New Task (Run...)", ID_FILE_NEW + MENUITEM SEPARATOR + MENUITEM "E&xit Task Manager", ID_FILE_EXIT + END + POPUP "&Options" + BEGIN + MENUITEM "&Always On Top", ID_OPTIONS_ALWAYSONTOP + , CHECKED + MENUITEM "&Minimize On Use", ID_OPTIONS_MINIMIZEONUSE + , CHECKED + MENUITEM "&Hide When Minimized", ID_OPTIONS_HIDEWHENMINIMIZED + , CHECKED + MENUITEM "&Show 16-bit tasks", ID_OPTIONS_SHOW16BITTASKS + , CHECKED + END + POPUP "&View" + BEGIN + MENUITEM "&Refresh Now", ID_VIEW_REFRESH + POPUP "&Update Speed" + BEGIN + MENUITEM "&High", ID_VIEW_UPDATESPEED_HIGH + MENUITEM "&Normal", ID_VIEW_UPDATESPEED_NORMAL + , CHECKED + MENUITEM "&Low", ID_VIEW_UPDATESPEED_LOW + MENUITEM "&Paused", ID_VIEW_UPDATESPEED_PAUSED + + END + MENUITEM SEPARATOR + MENUITEM "Lar&ge Icons", ID_VIEW_LARGE + MENUITEM "S&mall Icons", ID_VIEW_SMALL + MENUITEM "&Details", ID_VIEW_DETAILS, CHECKED + MENUITEM "&Select Columns...", ID_VIEW_SELECTCOLUMNS + POPUP "&CPU History" + BEGIN + MENUITEM "&One Graph, All CPUs", ID_VIEW_CPUHISTORY_ONEGRAPHALL + + MENUITEM "One Graph &Per CPU", ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU + , CHECKED + END + MENUITEM "&Show Kernel Times", ID_VIEW_SHOWKERNELTIMES + END + POPUP "&Windows" + BEGIN + MENUITEM "Tile &Horizontally", ID_WINDOWS_TILEHORIZONTALLY + MENUITEM "Tile &Vertically", ID_WINDOWS_TILEVERTICALLY + MENUITEM "&Minimize", ID_WINDOWS_MINIMIZE + MENUITEM "Ma&ximize", ID_WINDOWS_MAXIMIZE + MENUITEM "&Cascade", ID_WINDOWS_CASCADE + MENUITEM "&Bring To Front", ID_WINDOWS_BRINGTOFRONT + END + POPUP "&Help" + BEGIN + MENUITEM "Task Manager &Help Topics", ID_HELP_TOPICS + MENUITEM SEPARATOR + MENUITEM "&About Task Manager", ID_HELP_ABOUT + END +END + +IDR_WINDOWSMENU MENU DISCARDABLE +BEGIN + MENUITEM "Tile &Horizontally", ID_WINDOWS_TILEHORIZONTALLY + MENUITEM "Tile &Vertically", ID_WINDOWS_TILEVERTICALLY + MENUITEM "&Minimize", ID_WINDOWS_MINIMIZE + MENUITEM "Ma&ximize", ID_WINDOWS_MAXIMIZE + MENUITEM "&Cascade", ID_WINDOWS_CASCADE + MENUITEM "&Bring To Front", ID_WINDOWS_BRINGTOFRONT +END + +IDR_APPLICATION_PAGE_CONTEXT1 MENU DISCARDABLE +BEGIN + POPUP "DUMMY" + BEGIN + MENUITEM "&New Task (Run...)", ID_FILE_NEW + MENUITEM SEPARATOR + MENUITEM "Lar&ge Icons", ID_VIEW_LARGE + MENUITEM "S&mall Icons", ID_VIEW_SMALL + MENUITEM "&Details", ID_VIEW_DETAILS, CHECKED + END +END + +IDR_APPLICATION_PAGE_CONTEXT2 MENU DISCARDABLE +BEGIN + POPUP "DUMMY" + BEGIN + MENUITEM "&Switch To", ID_APPLICATION_PAGE_SWITCHTO + MENUITEM "&Bring To Front", ID_WINDOWS_BRINGTOFRONT + MENUITEM SEPARATOR + MENUITEM "Tile &Horizontally", ID_WINDOWS_TILEHORIZONTALLY + MENUITEM "Tile &Vertically", ID_WINDOWS_TILEVERTICALLY + MENUITEM "&Minimize", ID_WINDOWS_MINIMIZE + MENUITEM "Ma&ximize", ID_WINDOWS_MAXIMIZE + MENUITEM "&Cascade", ID_WINDOWS_CASCADE + MENUITEM SEPARATOR + MENUITEM "&End Task", ID_APPLICATION_PAGE_ENDTASK + MENUITEM "&Go To Process", ID_APPLICATION_PAGE_GOTOPROCESS + + END +END + +IDR_TRAY_POPUP MENU DISCARDABLE +BEGIN + MENUITEM "&Restore", ID_RESTORE + MENUITEM "&Close", ID_FILE_EXIT + MENUITEM SEPARATOR + MENUITEM "&Always On Top", ID_OPTIONS_ALWAYSONTOP, CHECKED +END + +IDR_PROCESS_PAGE_CONTEXT MENU DISCARDABLE +BEGIN + POPUP "DUMMY" + BEGIN + MENUITEM "&End Process", ID_PROCESS_PAGE_ENDPROCESS + MENUITEM "End Process &Tree", ID_PROCESS_PAGE_ENDPROCESSTREE + + MENUITEM "&Debug", ID_PROCESS_PAGE_DEBUG + MENUITEM SEPARATOR + POPUP "Set &Priority" + BEGIN + MENUITEM "&Realtime", ID_PROCESS_PAGE_SETPRIORITY_REALTIME + + MENUITEM "&High", ID_PROCESS_PAGE_SETPRIORITY_HIGH + + MENUITEM "&AboveNormal", ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL + + MENUITEM "&Normal", ID_PROCESS_PAGE_SETPRIORITY_NORMAL + + MENUITEM "&BelowNormal", ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL + + MENUITEM "&Low", ID_PROCESS_PAGE_SETPRIORITY_LOW + + END + MENUITEM "Set &Affinity...", ID_PROCESS_PAGE_SETAFFINITY + MENUITEM "Edit Debug &Channels...", ID_PROCESS_PAGE_DEBUGCHANNELS + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_ABOUTBOX DIALOG DISCARDABLE 22, 17, 259, 210 +STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU +CAPTION "About Task Manager" +FONT 8, "Tahoma" +BEGIN + CONTROL "Task Manager v1.0\nCopyright (C) 1999 - 2001\nby Brian Palmer (brianp@reactos.org)", + IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,53,28, + 122,26 + DEFPUSHBUTTON "OK",IDOK,183,189,44,14,WS_GROUP + ICON IDI_TASKMANAGER,IDC_STATIC,19,30,20,20 + EDITTEXT IDC_LICENSE_EDIT,53,63,174,107,ES_MULTILINE | + ES_READONLY | WS_VSCROLL +END + +IDD_TASKMGR_DIALOG DIALOG DISCARDABLE 0, 0, 264, 246 +STYLE DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | + WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | + WS_THICKFRAME +CAPTION "Task Manager" +MENU IDR_TASKMANAGER +FONT 8, "Tahoma" +BEGIN + CONTROL "Tab1",IDC_TAB,"SysTabControl32",WS_TABSTOP,3,3,257,228 +END + +IDD_APPLICATION_PAGE DIALOG DISCARDABLE 0, 0, 247, 210 +STYLE DS_CONTROL | WS_CHILD | WS_CLIPCHILDREN +FONT 8, "Tahoma" +BEGIN + CONTROL "List2",IDC_APPLIST,"SysListView32",LVS_REPORT | + LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,7,7,233,177 + PUSHBUTTON "&New Task...",IDC_NEWTASK,187,189,53,14 + PUSHBUTTON "&Switch To",IDC_SWITCHTO,131,189,53,14,WS_DISABLED + PUSHBUTTON "&End Task",IDC_ENDTASK,75,189,53,14,WS_DISABLED +END + +IDD_PROCESS_PAGE DIALOG DISCARDABLE 0, 0, 247, 210 +STYLE DS_CONTROL | WS_CHILD | WS_CLIPCHILDREN +FONT 8, "Tahoma" +BEGIN + CONTROL "List2",IDC_PROCESSLIST,"SysListView32",LVS_REPORT | + LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_OWNERDATA | + WS_BORDER | WS_TABSTOP,7,7,233,177 + PUSHBUTTON "&End Process",IDC_ENDPROCESS,171,189,69,14 + CONTROL "&Show processes from all users",IDC_SHOWALLPROCESSES, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,191,111,10 +END + +//IDD_PERFORMANCE_PAGE DIALOGEX 0, 0, 247, 210 +IDD_PERFORMANCE_PAGE DIALOGEX DISCARDABLE 0, 0, 247, 210 +STYLE DS_CONTROL | WS_CHILD | WS_CLIPCHILDREN +FONT 8, "Tahoma" +BEGIN + GROUPBOX "CPU Usage",IDC_CPU_USAGE_FRAME,5,5,60,54,WS_TABSTOP, WS_EX_TRANSPARENT + GROUPBOX "MEM Usage",IDC_MEM_USAGE_FRAME,5,63,60,54,BS_LEFTTEXT, WS_EX_TRANSPARENT + GROUPBOX "Totals",IDC_TOTALS_FRAME,5,122,111,39,0,WS_EX_TRANSPARENT + GROUPBOX "Commit Charge (K)",IDC_COMMIT_CHARGE_FRAME,5,166,111,39,0,WS_EX_TRANSPARENT + GROUPBOX "Physical Memory (K)",IDC_PHYSICAL_MEMORY_FRAME,131,122,111,39,0,WS_EX_TRANSPARENT + GROUPBOX "Kernel Memory (K)",IDC_KERNEL_MEMORY_FRAME,131,166,111,39,0,WS_EX_TRANSPARENT + LTEXT "Handles",IDS_TOTALS_HANDLE_COUNT,12,131,27,8 + LTEXT "Threads",IDS_TOTALS_THREAD_COUNT,12,140,27,8 + LTEXT "Processes",IDS_TOTALS_PROCESS_COUNT,12,149,34,8 + EDITTEXT IDC_TOTALS_HANDLE_COUNT,65,131,45,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_TOTALS_THREAD_COUNT,65,140,45,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_TOTALS_PROCESS_COUNT,65,149,45,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + LTEXT "Total",IDS_COMMIT_CHARGE_TOTAL,12,175,27,8 + LTEXT "Limit",IDS_COMMIT_CHARGE_LIMIT,12,184,15,8 + LTEXT "Peak",IDS_COMMIT_CHARGE_PEAK,12,193,34,8 + EDITTEXT IDC_COMMIT_CHARGE_TOTAL,65,174,45,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_COMMIT_CHARGE_LIMIT,65,184,45,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_COMMIT_CHARGE_PEAK,65,193,45,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + LTEXT "Total",IDS_PHYSICAL_MEMORY_TOTAL,137,131,27,8 + LTEXT "Available",IDS_PHYSICAL_MEMORY_AVAILABLE,137,140,30,8 + LTEXT "System Cache",IDS_PHYSICAL_MEMORY_SYSTEM_CACHE,137,149,46,8 + EDITTEXT IDC_PHYSICAL_MEMORY_TOTAL,185,131,48,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_PHYSICAL_MEMORY_AVAILABLE,185,140,48,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_PHYSICAL_MEMORY_SYSTEM_CACHE,185,149,48,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + LTEXT "Total",IDS_KERNEL_MEMORY_TOTAL,137,174,27,8 + LTEXT "Paged",IDS_KERNEL_MEMORY_PAGED,137,184,21,8 + LTEXT "Nonpaged",IDS_KERNEL_MEMORY_NONPAGED,137,193,34,8 + EDITTEXT IDC_KERNEL_MEMORY_TOTAL,185,174,48,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_KERNEL_MEMORY_PAGED,185,184,48,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + EDITTEXT IDC_KERNEL_MEMORY_NONPAGED,185,193,48,8,ES_RIGHT | + ES_READONLY | ES_NUMBER | NOT WS_BORDER + GROUPBOX "CPU Usage History",IDC_CPU_USAGE_HISTORY_FRAME,74,5,168,54,0,WS_EX_TRANSPARENT + GROUPBOX "Memory Usage History",IDC_MEMORY_USAGE_HISTORY_FRAME,74,63,168,54,0,WS_EX_TRANSPARENT + PUSHBUTTON "CPU Usage Display",IDC_CPU_USAGE_GRAPH,12,17,47,37,0, + WS_EX_CLIENTEDGE + PUSHBUTTON "MEM Usage Display",IDC_MEM_USAGE_GRAPH,12,75,47,37,0, + WS_EX_CLIENTEDGE + PUSHBUTTON "CPU Usage History",IDC_CPU_USAGE_HISTORY_GRAPH,81,17, + 153,37,0,WS_EX_CLIENTEDGE + PUSHBUTTON "MEM Usage History",IDC_MEM_USAGE_HISTORY_GRAPH,81,75, + 153,37,0,WS_EX_CLIENTEDGE +END + +IDD_DEBUG_CHANNELS_DIALOG DIALOG DISCARDABLE 0, 0, 247, 210 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Debug Channels" +FONT 8, "Tahoma" +BEGIN + CONTROL "List2",IDC_DEBUG_CHANNELS_LIST,"SysListView32",LVS_REPORT | + LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP | + LVS_SORTASCENDING,7,7,233,177 + PUSHBUTTON "Close",IDOK,171,189,69,14 +END + +IDD_AFFINITY_DIALOG DIALOG DISCARDABLE 0, 0, 231, 154 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Processor Affinity" +FONT 8, "Tahoma" +BEGIN + DEFPUSHBUTTON "OK",IDOK,120,133,50,14 + PUSHBUTTON "Cancel",IDCANCEL,174,133,50,14 + LTEXT "The Processor Affinity setting controls which CPUs the process will be allowed to execute on.", + IDC_STATIC,5,5,220,16 + CONTROL "CPU 0",IDC_CPU0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, + 11,28,37,10 + CONTROL "CPU 1",IDC_CPU1,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,41,37,10 + CONTROL "CPU 2",IDC_CPU2,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,54,37,10 + CONTROL "CPU 3",IDC_CPU3,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,67,37,10 + CONTROL "CPU 4",IDC_CPU4,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,80,37,10 + CONTROL "CPU 5",IDC_CPU5,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,93,37,10 + CONTROL "CPU 6",IDC_CPU6,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,106,37,10 + CONTROL "CPU 7",IDC_CPU7,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,11,119,37,10 + CONTROL "CPU 8",IDC_CPU8,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,61,28,37,10 + CONTROL "CPU 9",IDC_CPU9,"Button",BS_AUTOCHECKBOX | WS_DISABLED | + WS_TABSTOP,61,41,37,10 + CONTROL "CPU 10",IDC_CPU10,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,61,54,41,10 + CONTROL "CPU 11",IDC_CPU11,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,61,67,41,10 + CONTROL "CPU 12",IDC_CPU12,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,61,80,41,10 + CONTROL "CPU 13",IDC_CPU13,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,61,93,41,10 + CONTROL "CPU 14",IDC_CPU14,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,61,106,41,10 + CONTROL "CPU 15",IDC_CPU15,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,61,119,41,10 + CONTROL "CPU 16",IDC_CPU16,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,28,41,10 + CONTROL "CPU 17",IDC_CPU17,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,41,41,10 + CONTROL "CPU 18",IDC_CPU18,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,54,41,10 + CONTROL "CPU 19",IDC_CPU19,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,67,41,10 + CONTROL "CPU 20",IDC_CPU20,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,80,41,10 + CONTROL "CPU 21",IDC_CPU21,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,93,41,10 + CONTROL "CPU 22",IDC_CPU22,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,106,41,10 + CONTROL "CPU 23",IDC_CPU23,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,116,119,41,10 + CONTROL "CPU 24",IDC_CPU24,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,28,41,10 + CONTROL "CPU 25",IDC_CPU25,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,41,41,10 + CONTROL "CPU 26",IDC_CPU26,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,54,41,10 + CONTROL "CPU 27",IDC_CPU27,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,67,41,10 + CONTROL "CPU 28",IDC_CPU28,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,80,41,10 + CONTROL "CPU 29",IDC_CPU29,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,93,41,10 + CONTROL "CPU 30",IDC_CPU30,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,106,41,10 + CONTROL "CPU 31",IDC_CPU31,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,175,119,41,10 +END + +IDD_COLUMNS_DIALOG DIALOG DISCARDABLE 0, 0, 195, 199 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Select Columns" +FONT 8, "Tahoma" +BEGIN + DEFPUSHBUTTON "OK",IDOK,84,178,50,14 + PUSHBUTTON "Cancel",IDCANCEL,138,178,50,14 + LTEXT "Select the columns that will appear on the Process page of the Task Manager.", + IDC_STATIC,7,7,181,17 + CONTROL "&Image Name",IDC_IMAGENAME,"Button",BS_AUTOCHECKBOX | + WS_DISABLED | WS_TABSTOP,7,28,56,10 + CONTROL "&PID (Process Identifier)",IDC_PID,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,39,88,10 + CONTROL "&CPU Usage",IDC_CPUUSAGE,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,50,53,10 + CONTROL "CPU Tim&e",IDC_CPUTIME,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,61,48,10 + CONTROL "&Memory Usage",IDC_MEMORYUSAGE,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,72,63,10 + CONTROL "Memory Usage &Delta",IDC_MEMORYUSAGEDELTA,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,83,82,10 + CONTROL "Pea&k Memory Usage",IDC_PEAKMEMORYUSAGE,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,94,82,10 + CONTROL "Page &Faults",IDC_PAGEFAULTS,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,105,53,10 + CONTROL "&USER Objects",IDC_USEROBJECTS,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,116,62,10 + CONTROL "I/O Reads",IDC_IOREADS,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,127,49,10 + CONTROL "I/O Read Bytes",IDC_IOREADBYTES,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,138,65,10 + CONTROL "&Session ID",IDC_SESSIONID,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,149,50,10 + CONTROL "User &Name",IDC_USERNAME,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,7,160,51,10 + CONTROL "Page F&aults Delta",IDC_PAGEFAULTSDELTA,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,107,28,72,10 + CONTROL "&Virtual Memory Size",IDC_VIRTUALMEMORYSIZE,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,107,39,77,10 + CONTROL "Pa&ged Pool",IDC_PAGEDPOOL,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,107,50,53,10 + CONTROL "N&on-paged Pool",IDC_NONPAGEDPOOL,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,107,61,67,10 + CONTROL "Base P&riority",IDC_BASEPRIORITY,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,107,72,55,10 + CONTROL "&Handle Count",IDC_HANDLECOUNT,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,107,83,59,10 + CONTROL "&Thread Count",IDC_THREADCOUNT,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,107,94,59,10 + CONTROL "GDI Objects",IDC_GDIOBJECTS,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,107,105,55,10 + CONTROL "I/O Writes",IDC_IOWRITES,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,107,116,49,10 + CONTROL "I/O Write Bytes",IDC_IOWRITEBYTES,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,107,127,65,10 + CONTROL "I/O Other",IDC_IOOTHER,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,107,138,46,10 + CONTROL "I/O Other Bytes",IDC_IOOTHERBYTES,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,107,149,65,10 +END + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""windows.h""\r\n" + "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""resource.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_ABOUTBOX, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 252 + TOPMARGIN, 7 + BOTTOMMARGIN, 203 + END + + IDD_TASKMGR_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 3 + RIGHTMARGIN, 260 + TOPMARGIN, 3 + BOTTOMMARGIN, 231 + END + + IDD_APPLICATION_PAGE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 240 + TOPMARGIN, 7 + BOTTOMMARGIN, 203 + END + + IDD_PROCESS_PAGE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 240 + TOPMARGIN, 7 + BOTTOMMARGIN, 203 + END + + IDD_PERFORMANCE_PAGE, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 242 + VERTGUIDE, 12 + VERTGUIDE, 65 + VERTGUIDE, 110 + TOPMARGIN, 5 + BOTTOMMARGIN, 205 + END + + IDD_AFFINITY_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 224 + VERTGUIDE, 11 + VERTGUIDE, 61 + VERTGUIDE, 116 + VERTGUIDE, 175 + TOPMARGIN, 7 + BOTTOMMARGIN, 147 + HORZGUIDE, 28 + HORZGUIDE, 38 + HORZGUIDE, 51 + HORZGUIDE, 64 + HORZGUIDE, 77 + HORZGUIDE, 90 + HORZGUIDE, 103 + HORZGUIDE, 116 + HORZGUIDE, 129 + END + + IDD_COLUMNS_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 188 + VERTGUIDE, 107 + TOPMARGIN, 7 + BOTTOMMARGIN, 192 + HORZGUIDE, 28 + END +END +#endif // APSTUDIO_INVOKED + +#ifdef WINE +#define res_dir . +#else +#define res_dir res +#endif + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +/* BINRES taskmgr.ico */ +IDI_TASKMANAGER ICON DISCARDABLE taskmgr.ico +/* { + '00 00 01 00 02 00 20 20 10 00 00 00 00 00 E8 02' + '00 00 26 00 00 00 10 10 10 00 00 00 00 00 28 01' + '00 00 0E 03 00 00 28 00 00 00 20 00 00 00 40 00' + '00 00 01 00 04 00 00 00 00 00 80 02 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 80 00 00 80 00 00 00 80 80 00 80 00' + '00 00 80 00 80 00 80 80 00 00 C0 C0 C0 00 80 80' + '80 00 00 00 FF 00 00 FF 00 00 00 FF FF 00 FF 00' + '00 00 FF 00 FF 00 FF FF 00 00 FF FF FF 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 FF F7 77 88 80 00 00 00 00 F7' + '77 77 77 80 00 00 07 77 88 88 00 00 00 00 00 F7' + '77 87 87 88 00 00 00 88 88 80 00 00 00 00 00 F7' + '77 87 87 88 80 00 00 00 00 00 00 00 00 00 00 F7' + '77 87 87 88 08 88 88 88 88 88 88 88 00 00 00 F7' + '97 87 87 80 87 77 77 77 77 77 77 77 70 00 00 F7' + '77 87 87 80 77 FF FF FF FF FF FF F7 70 00 00 F7' + '77 87 87 80 78 00 00 00 00 00 0A AF 70 00 00 F7' + '27 87 87 80 78 AA 00 00 00 00 A2 0F 70 00 00 F7' + 'A2 77 77 80 78 02 A0 0A 00 0A 20 0F 70 00 00 F7' + '77 77 77 80 78 00 2A A2 A0 0A 00 0F 70 00 00 F7' + '00 07 87 80 78 00 00 00 A0 0A 00 0F 70 00 00 F7' + '88 77 F7 80 78 00 08 00 2A 0A 00 0F 70 00 00 F7' + '77 77 77 80 78 00 8F 80 0A A2 00 0F 70 00 00 F7' + '77 77 77 80 78 00 08 00 02 A0 00 0F 70 00 00 F7' + '00 00 07 80 78 00 00 00 00 A0 00 0F 70 00 00 F7' + '88 88 77 80 7F 88 88 88 88 88 88 87 70 00 00 F7' + '77 77 77 80 FF 77 77 77 77 77 77 77 70 00 00 F7' + '00 00 07 88 07 FF FF FF FF FF FF FF 00 00 00 F7' + '88 88 77 88 80 00 00 00 00 00 00 00 00 00 00 F7' + '77 77 77 88 80 00 00 00 00 00 00 00 00 00 00 0F' + 'FF FF FF 88 80 00 00 00 00 00 00 00 00 00 00 07' + '77 77 77 78 80 00 00 00 00 00 00 00 00 00 00 00' + '77 77 77 77 80 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF' + 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF' + '00 7F C0 3C 00 1F 80 0F 00 7F 80 07 80 FF 80 00' + '00 0F 80 00 00 07 80 00 00 03 80 00 00 03 80 00' + '00 03 80 00 00 03 80 00 00 03 80 00 00 03 80 00' + '00 03 80 00 00 03 80 00 00 03 80 00 00 03 80 00' + '00 03 80 00 00 03 80 00 00 03 80 00 00 07 80 00' + '00 0F 80 03 FF FF 80 03 FF FF C0 03 FF FF E0 03' + 'FF FF F0 03 FF FF FF FF FF FF FF FF FF FF 28 00' + '00 00 10 00 00 00 20 00 00 00 01 00 04 00 00 00' + '00 00 C0 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80' + '00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80' + '00 00 C0 C0 C0 00 80 80 80 00 00 00 FF 00 00 FF' + '00 00 00 FF FF 00 FF 00 00 00 FF 00 FF 00 FF FF' + '00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 F8 78 80 00 0F 77' + '78 00 0F 78 00 00 0F 78 70 88 88 88 80 00 0F 78' + '70 F7 77 77 77 00 0F 78 70 F2 A0 00 A8 00 0F AF' + '70 F0 2A 0A 08 00 0F 77 70 F0 00 A2 08 00 0F 00' + '70 F0 F0 A0 08 00 0F 77 70 F8 88 88 88 00 0F 00' + '70 FF FF FF FF 00 0F FF F8 00 00 00 00 00 08 77' + '78 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 FF FF 00 00 FF 07 00 00 82 03' + '00 00 01 07 00 00 00 03 00 00 00 01 00 00 00 01' + '00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01' + '00 00 00 01 00 00 00 03 00 00 01 FF 00 00 81 FF' + '00 00 FF FF 00 00' +} */ + +/* BINRES window.ico */ +IDI_WINDOW ICON DISCARDABLE window.ico +/* { + '00 00 01 00 01 00 20 20 10 00 00 00 00 00 E8 02' + '00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00' + '00 00 01 00 04 00 00 00 00 00 80 02 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 80 00 00 80 00 00 00 80 80 00 80 00' + '00 00 80 00 80 00 80 80 00 00 C0 C0 C0 00 80 80' + '80 00 00 00 FF 00 00 FF 00 00 00 FF FF 00 FF 00' + '00 00 FF 00 FF 00 FF FF 00 00 FF FF FF 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 88 88' + '88 88 88 88 88 88 88 88 88 88 88 88 88 80 87 77' + '77 77 77 77 77 77 77 77 77 77 77 77 77 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 8F' + 'FF FF FF FF FF FF FF FF FF FF FF FF F7 80 87 88' + '88 88 88 88 88 88 88 88 88 88 88 88 87 80 87 77' + '77 77 77 77 77 77 77 77 77 77 77 77 77 80 87 44' + '44 44 44 44 44 44 44 44 40 00 00 00 00 80 87 44' + '44 44 44 44 44 44 44 44 47 70 77 07 70 80 87 44' + '44 44 44 44 44 44 44 44 47 70 77 07 70 80 87 44' + '44 44 44 44 44 44 44 44 44 44 44 44 44 80 87 77' + '77 77 77 77 77 77 77 77 77 77 77 77 77 80 88 88' + '88 88 88 88 88 88 88 88 88 88 88 88 88 80 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF' + 'FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 FF FF FF FF' +} */ + +/* BINRES windowsm.ico */ +IDI_WINDOWSM ICON DISCARDABLE windowsm.ico +/* { + '00 00 01 00 01 00 10 10 10 00 00 00 00 00 28 01' + '00 00 16 00 00 00 28 00 00 00 10 00 00 00 20 00' + '00 00 01 00 04 00 00 00 00 00 C0 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 80 00 00 80 00 00 00 80 80 00 80 00' + '00 00 80 00 80 00 80 80 00 00 C0 C0 C0 00 80 80' + '80 00 00 00 FF 00 00 FF 00 00 00 FF FF 00 FF 00' + '00 00 FF 00 FF 00 FF FF 00 00 FF FF FF 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 88 88' + '88 88 88 88 88 80 87 FF FF FF FF FF FF 80 87 FF' + 'FF FF FF FF FF 80 87 FF FF FF FF FF FF 80 87 FF' + 'FF FF FF FF FF 80 87 FF FF FF FF FF FF 80 87 FF' + 'FF FF FF FF FF 80 87 FF FF FF FF FF FF 80 87 88' + '88 88 88 88 88 80 87 44 44 44 F0 F0 F0 80 87 44' + '44 44 44 44 44 80 87 77 77 77 77 77 77 80 88 88' + '88 88 88 88 88 88 00 00 00 00 00 00 00 00 FF FF' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 FF FF 00 00' +} */ + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Brian Palmer\0" + VALUE "FileDescription", "Task Manager by Brian Palmer\0" + VALUE "FileVersion", "1.0.0.1\0" + VALUE "InternalName", "taskmgr\0" + VALUE "LegalCopyright", "Copyright © Brian Palmer 2000\0" + VALUE "OriginalFilename", "taskmgr.exe\0" + VALUE "ProductName", "Task Manager by Brian Palmer\0" + VALUE "ProductVersion", "1.0.0.1\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// +/* BINRES traymask.bmp */ +IDB_TRAYMASK BITMAP DISCARDABLE traymask.bmp +/* { + '42 4D F6 00 00 00 00 00 00 00 76 00 00 00 28 00' + '00 00 10 00 00 00 10 00 00 00 01 00 04 00 00 00' + '00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80' + '00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80' + '00 00 C0 C0 C0 00 80 80 80 00 00 00 FF 00 00 FF' + '00 00 00 FF FF 00 FF 00 00 00 FF 00 FF 00 FF FF' + '00 00 FF FF FF 00 FF FF FF FF FF FF FF FF FF FF' + 'FF FF FF FF FF FF FF 00 00 00 00 00 00 FF FF 00' + '00 00 00 00 00 FF FF 00 00 00 00 00 00 FF FF 00' + '00 00 00 00 00 FF FF 00 00 00 00 00 00 FF FF 00' + '00 00 00 00 00 FF FF 00 00 00 00 00 00 FF FF 00' + '00 00 00 00 00 FF FF 00 00 00 00 00 00 FF FF 00' + '00 00 00 00 00 FF FF 00 00 00 00 00 00 FF FF 00' + '00 00 00 00 00 FF FF 00 00 00 00 00 00 FF FF FF' + 'FF FF FF FF FF FF' +} */ + +/* BINRES trayicon.bmp */ +IDB_TRAYICON BITMAP DISCARDABLE trayicon.bmp +/* { + '42 4D F6 00 00 00 00 00 00 00 76 00 00 00 28 00' + '00 00 10 00 00 00 10 00 00 00 01 00 04 00 00 00' + '00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80' + '00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80' + '00 00 C0 C0 C0 00 80 80 80 00 00 00 FF 00 00 FF' + '00 00 00 FF FF 00 FF 00 00 00 FF 00 FF 00 FF FF' + '00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00' + '00 00 00 00 00 00 00 8F FF FF FF FF FF 00 00 80' + '20 20 20 20 2F 00 00 82 22 22 22 22 2F 00 00 80' + '20 20 20 20 2F 00 00 82 22 22 22 22 2F 00 00 80' + '20 20 20 20 2F 00 00 82 22 22 22 22 2F 00 00 80' + '20 20 20 20 2F 00 00 82 22 22 22 22 2F 00 00 80' + '20 20 20 20 2F 00 00 82 22 22 22 22 2F 00 00 80' + '20 20 20 20 2F 00 00 88 88 88 88 88 8F 00 00 00' + '00 00 00 00 00 00' +} */ + +/* BINRES font.bmp */ +IDB_FONT BITMAP DISCARDABLE font.bmp +/* { + '42 4D 86 02 00 00 00 00 00 00 76 00 00 00 28 00' + '00 00 60 00 00 00 0B 00 00 00 01 00 04 00 00 00' + '00 00 10 02 00 00 74 12 00 00 74 12 00 00 00 00' + '00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80' + '00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80' + '00 00 C0 C0 C0 00 80 80 80 00 00 00 FF 00 00 FF' + '00 00 00 FF FF 00 FF 00 00 00 FF 00 FF 00 FF FF' + '00 00 FF FF FF 00 AA AA AA A0 00 00 0A 00 AA AA' + 'AA A0 AA AA AA A0 00 00 00 A0 AA AA AA A0 AA AA' + 'AA A0 00 00 00 A0 AA AA AA A0 AA AA AA A0 A0 00' + '00 A0 00 00 00 00 A0 00 00 A0 00 00 0A 00 A0 00' + '00 00 00 00 00 A0 00 00 00 A0 00 00 00 A0 A0 00' + '00 A0 00 00 00 A0 A0 00 00 A0 00 00 00 A0 A0 00' + '0A 00 00 00 AA 00 A0 00 00 A0 00 00 0A 00 A0 00' + '00 00 00 00 00 A0 00 00 00 A0 00 00 00 A0 A0 00' + '00 A0 00 00 00 A0 A0 00 00 A0 00 00 00 A0 A0 00' + 'A0 00 A0 0A 00 A0 A0 00 00 A0 00 00 0A 00 A0 00' + '00 00 00 00 00 A0 00 00 00 A0 00 00 00 A0 A0 00' + '00 A0 00 00 00 A0 A0 00 00 A0 00 00 00 A0 A0 0A' + '00 00 0A 00 AA 00 A0 00 00 A0 00 00 0A 00 A0 00' + '00 00 00 00 00 A0 00 00 00 A0 00 00 00 A0 A0 00' + '00 A0 00 00 00 A0 A0 00 00 A0 00 00 00 A0 A0 A0' + '00 00 00 A0 00 00 A0 00 00 A0 00 00 0A 00 AA AA' + 'AA A0 0A AA AA A0 AA AA AA A0 AA AA AA A0 AA AA' + 'AA A0 00 00 00 A0 AA AA AA A0 AA AA AA A0 AA 00' + '00 00 00 0A 00 00 A0 00 00 A0 00 00 0A 00 00 00' + '00 A0 00 00 00 A0 A0 00 00 A0 A0 00 00 00 A0 00' + '00 00 00 00 00 A0 A0 00 00 A0 A0 00 00 A0 A0 A0' + '00 00 00 00 A0 00 A0 00 00 A0 00 00 0A 00 00 00' + '00 A0 00 00 00 A0 A0 00 00 A0 A0 00 00 00 A0 00' + '00 00 00 00 00 A0 A0 00 00 A0 A0 00 00 A0 A0 0A' + '00 00 0A A0 0A 00 A0 00 00 A0 00 00 0A 00 00 00' + '00 A0 00 00 00 A0 A0 00 00 A0 A0 00 00 00 A0 00' + '00 00 00 00 00 A0 A0 00 00 A0 A0 00 00 A0 A0 00' + 'A0 00 A0 0A 00 A0 A0 00 00 A0 00 00 0A 00 00 00' + '00 A0 00 00 00 A0 A0 00 00 A0 A0 00 00 00 A0 00' + '00 00 00 00 00 A0 A0 00 00 A0 A0 00 00 A0 A0 00' + '0A 00 0A A0 00 00 AA AA AA A0 00 00 0A 00 AA AA' + 'AA A0 AA AA AA A0 A0 00 00 A0 AA AA AA A0 AA AA' + 'AA A0 AA AA AA A0 AA AA AA A0 AA AA AA A0 A0 00' + '00 A0 00 00 00 00' +} */ + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE DISCARDABLE +BEGIN + IDS_APP_TITLE "Task Manager" + IDC_TASKMGR "Task Manager" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_FILE_NEW "Runs a new program" + ID_OPTIONS_ALWAYSONTOP "Task Manager remains in front of all other windows unless minimized" + ID_OPTIONS_MINIMIZEONUSE + "Task Manager is minimized when a SwitchTo operation is performed" + ID_OPTIONS_HIDEWHENMINIMIZED "Hide the Task Manager when it is minimized" + ID_VIEW_REFRESH "Force Task Manager to update now, regardless of Update Speed setting" + ID_VIEW_LARGE "Displays tasks by using large icons" + ID_VIEW_SMALL "Displays tasks by using small icons" + ID_VIEW_DETAILS "Displays information about each task" + ID_VIEW_UPDATESPEED_HIGH "Updates the display twice per second" + ID_VIEW_UPDATESPEED_NORMAL "Updates the display every two seconds" + ID_VIEW_UPDATESPEED_LOW "Updates the display every four seconds" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_VIEW_UPDATESPEED_PAUSED "Does not automatically update" + ID_WINDOWS_TILEHORIZONTALLY + "Tiles the windows horizontally on the desktop" + ID_WINDOWS_TILEVERTICALLY "Tiles the windows vertically on the desktop" + ID_WINDOWS_MINIMIZE "Minimizes the windows" + ID_WINDOWS_MAXIMIZE "Maximizes the windows" + ID_WINDOWS_CASCADE "Cascades the windows diagonally on the desktop" + ID_WINDOWS_BRINGTOFRONT "Brings the window front, but does not switch to it" + ID_HELP_TOPICS "Displays Task Manager help topics" + ID_HELP_ABOUT "Displays program information, version number, and copyright" + ID_FILE_EXIT "Exits the Task Manager application" + ID_OPTIONS_SHOW16BITTASKS + "Shows 16-bit tasks under the associated ntvdm.exe" + ID_VIEW_SELECTCOLUMNS "Select which columns will be visible on the Process page" + ID_VIEW_SHOWKERNELTIMES "Displays kernel time in the performance graphs" + ID_VIEW_CPUHISTORY_ONEGRAPHALL + "A single history graph shows total CPU usage" + ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU "Each CPU has its own history graph" + ID_APPLICATION_PAGE_SWITCHTO + "Brings a task to the foreground, switch focus to that task" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_ENDTASK "Tells the selected tasks to close" + ID_GOTOPROCESS "Switches the focus to the process of the selected task" + ID_RESTORE "Restores the Task Manager from its hidden state" + ID_PROCESS_PAGE_ENDPROCESS "Removes the process from the system" + ID_PROCESS_PAGE_ENDPROCESSTREE + "Removes this process and all descendants from the system" + ID_PROCESS_PAGE_DEBUG "Attaches the debugger to this process" + ID_PROCESS_PAGE_SETAFFINITY + "Controls which processors the process will be allowed to run on" + ID_PROCESS_PAGE_SETPRIORITY_REALTIME + "Sets process to the REALTIME priority class" + ID_PROCESS_PAGE_SETPRIORITY_HIGH "Sets process to the HIGH priority class" + ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL + "Sets process to the ABOVE NORMAL priority class" + ID_PROCESS_PAGE_SETPRIORITY_NORMAL + "Sets process to the NORMAL priority class" + ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL + "Sets process to the BELOW NORMAL priority class" + ID_PROCESS_PAGE_SETPRIORITY_LOW "Sets process to the LOW priority class" + IDS_LICENSE "This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.\r\n\r\nThis 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.\r\n\r\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA." +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/programs/taskmgr/trayicon.c b/programs/taskmgr/trayicon.c new file mode 100644 index 00000000000..6dbb50401eb --- /dev/null +++ b/programs/taskmgr/trayicon.c @@ -0,0 +1,212 @@ +/* + * ReactOS Task Manager + * + * trayicon.c + * + * Copyright (C) 1999 - 2001 Brian Palmer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taskmgr.h" +#include "perfdata.h" +#include "shellapi.h" + +HICON TrayIcon_GetProcessorUsageIcon(void) +{ + HICON hTrayIcon = NULL; + HDC hScreenDC = NULL; + HDC hDC = NULL; + HBITMAP hBitmap = NULL; + HBITMAP hOldBitmap = NULL; + HBITMAP hBitmapMask = NULL; + ICONINFO iconInfo; + ULONG ProcessorUsage; + int nLinesToDraw; + HBRUSH hBitmapBrush = NULL; + RECT rc; + + /* + * Get a handle to the screen DC + */ + hScreenDC = GetDC(NULL); + if (!hScreenDC) + goto done; + + /* + * Create our own DC from it + */ + hDC = CreateCompatibleDC(hScreenDC); + if (!hDC) + goto done; + + /* + * Load the bitmaps + */ + hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYICON)); + hBitmapMask = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYMASK)); + if (!hBitmap || !hBitmapMask) + goto done; + + hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0)); + if (!hBitmapBrush) + goto done; + + /* + * Select the bitmap into our device context + * so we can draw on it. + */ + hOldBitmap = (HBITMAP) SelectObject(hDC, hBitmap); + + /* + * Get the cpu usage + */ + ProcessorUsage = PerfDataGetProcessorUsage(); + + /* + * Calculate how many lines to draw + * since we have 11 rows of space + * to draw the cpu usage instead of + * just having 10. + */ + nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11; + rc.left = 3; + rc.top = 12 - nLinesToDraw; + rc.right = 13; + rc.bottom = 13; + + /* + * Now draw the cpu usage + */ + if (nLinesToDraw) + FillRect(hDC, &rc, hBitmapBrush); + + /* + * Now that we are done drawing put the + * old bitmap back. + */ + SelectObject(hDC, hOldBitmap); + hOldBitmap = NULL; + + iconInfo.fIcon = TRUE; + iconInfo.xHotspot = 0; + iconInfo.yHotspot = 0; + iconInfo.hbmMask = hBitmapMask; + iconInfo.hbmColor = hBitmap; + + hTrayIcon = CreateIconIndirect(&iconInfo); + +done: + /* + * Cleanup + */ + if (hScreenDC) + ReleaseDC(NULL, hScreenDC); + if (hOldBitmap) + SelectObject(hDC, hOldBitmap); + if (hDC) + DeleteDC(hDC); + if (hBitmapBrush) + DeleteObject(hBitmapBrush); + if (hBitmap) + DeleteObject(hBitmap); + if (hBitmapMask) + DeleteObject(hBitmapMask); + + /* + * Return the newly created tray icon (if successful) + */ + return hTrayIcon; +} + +BOOL TrayIcon_ShellAddTrayIcon(void) +{ + NOTIFYICONDATA nid; + HICON hIcon = NULL; + BOOL bRetVal; + + memset(&nid, 0, sizeof(NOTIFYICONDATA)); + + hIcon = TrayIcon_GetProcessorUsageIcon(); + + nid.cbSize = sizeof(NOTIFYICONDATA); + nid.hWnd = hMainWnd; + nid.uID = 0; + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + /* nid.uCallbackMessage = ??; */ + nid.hIcon = hIcon; + wsprintf(nid.szTip, _T("CPU Usage: %d%%"), PerfDataGetProcessorUsage()); + + bRetVal = Shell_NotifyIcon(NIM_ADD, &nid); + + if (hIcon) + DestroyIcon(hIcon); + + return bRetVal; +} + +BOOL TrayIcon_ShellRemoveTrayIcon(void) +{ + NOTIFYICONDATA nid; + BOOL bRetVal; + + memset(&nid, 0, sizeof(NOTIFYICONDATA)); + + nid.cbSize = sizeof(NOTIFYICONDATA); + nid.hWnd = hMainWnd; + nid.uID = 0; + nid.uFlags = 0; + /* nid.uCallbackMessage = ??; */ + + bRetVal = Shell_NotifyIcon(NIM_DELETE, &nid); + + return bRetVal; +} + +BOOL TrayIcon_ShellUpdateTrayIcon(void) +{ + NOTIFYICONDATA nid; + HICON hIcon = NULL; + BOOL bRetVal; + + memset(&nid, 0, sizeof(NOTIFYICONDATA)); + + hIcon = TrayIcon_GetProcessorUsageIcon(); + + nid.cbSize = sizeof(NOTIFYICONDATA); + nid.hWnd = hMainWnd; + nid.uID = 0; + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + /* nid.uCallbackMessage = ??; */ + nid.hIcon = hIcon; + wsprintf(nid.szTip, _T("CPU Usage: %d%%"), PerfDataGetProcessorUsage()); + + bRetVal = Shell_NotifyIcon(NIM_MODIFY, &nid); + + if (hIcon) + DestroyIcon(hIcon); + + return bRetVal; +}