diff --git a/rosapps/taskmgr/ApplicationPage.cpp b/rosapps/taskmgr/ApplicationPage.cpp index 14f1d13eda6..f6d714e2811 100644 --- a/rosapps/taskmgr/ApplicationPage.cpp +++ b/rosapps/taskmgr/ApplicationPage.cpp @@ -20,41 +20,54 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" -#include "TASKMGR.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "TaskMgr.h" #include "ApplicationPage.h" #include "ProcessPage.h" typedef struct { - HWND hWnd; - char szTitle[260]; - HICON hIcon; - BOOL bHung; + HWND hWnd; + char szTitle[260]; + HICON hIcon; + BOOL bHung; } APPLICATION_PAGE_LIST_ITEM, *LPAPPLICATION_PAGE_LIST_ITEM; -HWND hApplicationPage; // Application List Property Page +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 +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 int nApplicationPageWidth; +static int nApplicationPageHeight; -static HANDLE hApplicationPageEvent = NULL; // When this event becomes signaled then we refresh the app list +static HANDLE hApplicationPageEvent = NULL; // When this event becomes signaled then we refresh the app list -static BOOL bSortAscending = TRUE; +static BOOL bSortAscending = TRUE; -void ApplicationPageRefreshThread(void *lpParameter); -BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam); -void AddOrUpdateHwnd(HWND hWnd, char *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); +void ApplicationPageRefreshThread(void *lpParameter); +BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam); +void AddOrUpdateHwnd(HWND hWnd, char *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); void SwitchToThisWindow ( HWND hWnd, // Handle to the window that should be activated @@ -63,954 +76,954 @@ BOOL bRestore // Restore the window if it is minimized LRESULT CALLBACK ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - RECT rc; - int nXDifference; - int nYDifference; - LV_COLUMN column; - char szTemp[256]; + RECT rc; + int nXDifference; + int nYDifference; + LV_COLUMN column; + char szTemp[256]; - switch (message) - { - case WM_INITDIALOG: + switch (message) + { + case WM_INITDIALOG: - // Save the width and height - GetClientRect(hDlg, &rc); - nApplicationPageWidth = rc.right; - nApplicationPageHeight = rc.bottom; + // 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); + // 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); + // 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, "Tasks"); + SetWindowText(hApplicationPageListCtrl, "Tasks"); - // Initialize the application page's controls - column.mask = LVCF_TEXT|LVCF_WIDTH; - strcpy(szTemp, "Task"); - column.pszText = szTemp; - column.cx = 250; - ListView_InsertColumn(hApplicationPageListCtrl, 0, &column); // Add the "Task" column - column.mask = LVCF_TEXT|LVCF_WIDTH; - strcpy(szTemp, "Status"); - column.pszText = szTemp; - column.cx = 95; - ListView_InsertColumn(hApplicationPageListCtrl, 1, &column); // Add the "Status" column + // Initialize the application page's controls + column.mask = LVCF_TEXT|LVCF_WIDTH; + strcpy(szTemp, "Task"); + column.pszText = szTemp; + column.cx = 250; + ListView_InsertColumn(hApplicationPageListCtrl, 0, &column); // Add the "Task" column + column.mask = LVCF_TEXT|LVCF_WIDTH; + strcpy(szTemp, "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); + 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(); + UpdateApplicationListControlViewSetting(); - // Start our refresh thread - _beginthread(ApplicationPageRefreshThread, 0, NULL); + // Start our refresh thread + _beginthread(ApplicationPageRefreshThread, 0, NULL); - return TRUE; + 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_DESTROY: + // Close the event handle, this will make the + // refresh thread exit when the wait fails + CloseHandle(hApplicationPageEvent); + break; - case WM_COMMAND: + 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; - } + // 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; + break; - case WM_SIZE: - int cx, cy; + case WM_SIZE: + int cx, cy; - if (wParam == SIZE_MINIMIZED) - return 0; + if (wParam == SIZE_MINIMIZED) + return 0; - cx = LOWORD(lParam); - cy = HIWORD(lParam); - nXDifference = cx - nApplicationPageWidth; - nYDifference = cy - nApplicationPageHeight; - nApplicationPageWidth = cx; - nApplicationPageHeight = cy; + 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); + // 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; + break; - case WM_NOTIFY: + case WM_NOTIFY: + ApplicationPageOnNotify(wParam, lParam); + break; + + } - ApplicationPageOnNotify(wParam, lParam); - break; - } - - return 0; + return 0; } void RefreshApplicationPage(void) { - // Signal the event so that our refresh thread - // will wake up and refresh the application page - SetEvent(hApplicationPageEvent); + // 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); + DWORD dwStyle = GetWindowLong(hApplicationPageListCtrl, GWL_STYLE); - dwStyle &= ~LVS_REPORT; - dwStyle &= ~LVS_ICON; - dwStyle &= ~LVS_LIST; - dwStyle &= ~LVS_SMALLICON; + 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; + if (TaskManagerSettings.View_LargeIcons) + dwStyle |= LVS_ICON; + else if (TaskManagerSettings.View_SmallIcons) + dwStyle |= LVS_SMALLICON; + else + dwStyle |= LVS_REPORT; - SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle); + SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle); - RefreshApplicationPage(); + RefreshApplicationPage(); } void ApplicationPageRefreshThread(void *lpParameter) { - // Create the event - hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, "Application Page Event"); + // Create the event + hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, "Application Page Event"); - // If we couldn't create the event then exit the thread - if (!hApplicationPageEvent) - return; + // If we couldn't create the event then exit the thread + if (!hApplicationPageEvent) + return; - while (1) - { - DWORD dwWaitVal; + while (1) + { + DWORD dwWaitVal; - // Wait on the event - dwWaitVal = WaitForSingleObject(hApplicationPageEvent, INFINITE); + // 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; + // 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; - if (dwWaitVal == WAIT_OBJECT_0) - { - // Reset our event - ResetEvent(hApplicationPageEvent); + if (dwWaitVal == WAIT_OBJECT_0) + { + // Reset our event + ResetEvent(hApplicationPageEvent); - /* - * FIXME: - * - * Should this be EnumDesktopWindows() instead? - */ - EnumWindows(EnumWindowsProc, 0); - } - } + /* + * FIXME: + * + * Should this be EnumDesktopWindows() instead? + */ + EnumWindows(EnumWindowsProc, 0); + } + } } BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { - HICON hIcon; - char szText[260]; - BOOL bLargeIcon; + HICON hIcon; + char szText[260]; + BOOL bLargeIcon; - // Skip our window - if (hWnd == hMainWnd) - return TRUE; + // Skip our window + if (hWnd == hMainWnd) + return TRUE; - bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE; + bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE; - GetWindowText(hWnd, szText, 260); // Get the window text + GetWindowText(hWnd, szText, 260); // Get the window text - // 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); + // 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 = (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)); + if (!hIcon) + hIcon = LoadIcon(hInst, bLargeIcon ? MAKEINTRESOURCE(IDI_WINDOW) : MAKEINTRESOURCE(IDI_WINDOWSM)); - // Check and see if this is a top-level app window - if ((strlen(szText) <= 0) || - !IsWindowVisible(hWnd) || - (GetParent(hWnd) != NULL) || - (GetWindow(hWnd, GW_OWNER) != NULL) || - (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) - { - return TRUE; // Skip this window - } + // Check and see if this is a top-level app window + if ((strlen(szText) <= 0) || + !IsWindowVisible(hWnd) || + (GetParent(hWnd) != NULL) || + (GetWindow(hWnd, GW_OWNER) != NULL) || + (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) + { + return TRUE; // Skip this window + } - BOOL bHung = FALSE; + BOOL bHung = FALSE; - typedef int (FAR __stdcall *IsHungAppWindowProc)(HWND); - IsHungAppWindowProc IsHungAppWindow; + typedef int (FAR __stdcall *IsHungAppWindowProc)(HWND); + IsHungAppWindowProc IsHungAppWindow; - IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandle("USER32.DLL"), "IsHungAppWindow"); + IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandle("USER32.DLL"), "IsHungAppWindow"); - if (IsHungAppWindow) - bHung = IsHungAppWindow(hWnd); + if (IsHungAppWindow) + bHung = IsHungAppWindow(hWnd); - AddOrUpdateHwnd(hWnd, szText, hIcon, bHung); + AddOrUpdateHwnd(hWnd, szText, hIcon, bHung); - return TRUE; + return TRUE; } void AddOrUpdateHwnd(HWND hWnd, char *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; + 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)); + memset(&item, 0, sizeof(LV_ITEM)); - // Get the image lists - hImageListLarge = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_NORMAL); - hImageListSmall = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_SMALL); + // 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; - } - } + pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam; + if (pAPLI->hWnd == 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) || - (stricmp(pAPLI->szTitle, szTitle) != 0) || - (pAPLI->bHung != bHung)) - { - // Update the structure - pAPLI->hIcon = hIcon; - pAPLI->bHung = bHung; - strcpy(pAPLI->szTitle, szTitle); + // 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) || + (stricmp(pAPLI->szTitle, szTitle) != 0) || + (pAPLI->bHung != bHung)) + { + // Update the structure + pAPLI->hIcon = hIcon; + pAPLI->bHung = bHung; + strcpy(pAPLI->szTitle, szTitle); - // Update the image list - ImageList_ReplaceIcon(hImageListLarge, item.iItem, hIcon); - ImageList_ReplaceIcon(hImageListSmall, item.iItem, hIcon); + // 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); - } - } - // It is not already in the list so add it - else - { - pAPLI = new APPLICATION_PAGE_LIST_ITEM; + // 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 = new APPLICATION_PAGE_LIST_ITEM; - pAPLI->hWnd = hWnd; - pAPLI->hIcon = hIcon; - pAPLI->bHung = bHung; - strcpy(pAPLI->szTitle, szTitle); + pAPLI->hWnd = hWnd; + pAPLI->hIcon = hIcon; + pAPLI->bHung = bHung; + strcpy(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); - } + // 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); + // 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)|| - (strlen(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); + pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam; + if (!IsWindow(pAPLI->hWnd)|| + (strlen(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); - delete pAPLI; - bItemRemoved = TRUE; - } - } + ListView_DeleteItem(hApplicationPageListCtrl, item.iItem); + delete 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); - } - } + // Only one item selected + if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1) + { + 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_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); + EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED); + } + // More than one item selected + else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 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; + int idctrl; + LPNMHDR pnmh; + LPNM_LISTVIEW pnmv; + LV_DISPINFO* pnmdi; - idctrl = (int) wParam; - pnmh = (LPNMHDR) lParam; - pnmv = (LPNM_LISTVIEW) lParam; - pnmdi = (LV_DISPINFO*) lParam; + 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: - LPAPPLICATION_PAGE_LIST_ITEM pAPLI; + if (pnmh->hwndFrom == hApplicationPageListCtrl) + { + switch (pnmh->code) + { + case LVN_ITEMCHANGED: + ApplicationPageUpdate(); + break; + + case LVN_GETDISPINFO: + LPAPPLICATION_PAGE_LIST_ITEM pAPLI; - pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)pnmdi->item.lParam; + pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)pnmdi->item.lParam; - // Update the item text - if (pnmdi->item.iSubItem == 0) - { - strncpy(pnmdi->item.pszText, pAPLI->szTitle, pnmdi->item.cchTextMax); - } + // Update the item text + if (pnmdi->item.iSubItem == 0) + { + strncpy(pnmdi->item.pszText, pAPLI->szTitle, pnmdi->item.cchTextMax); + } - // Update the item status - else if (pnmdi->item.iSubItem == 1) - { - if (pAPLI->bHung) - strncpy(pnmdi->item.pszText, "Not Responding", pnmdi->item.cchTextMax); - else - strncpy(pnmdi->item.pszText, "Running", pnmdi->item.cchTextMax); - } + // Update the item status + else if (pnmdi->item.iSubItem == 1) + { + if (pAPLI->bHung) + strncpy(pnmdi->item.pszText, "Not Responding", pnmdi->item.cchTextMax); + else + strncpy(pnmdi->item.pszText, "Running", pnmdi->item.cchTextMax); + } - break; + break; - case NM_RCLICK: + case NM_RCLICK: - if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1) - { - ApplicationPageShowContextMenu1(); - } - else - { - ApplicationPageShowContextMenu2(); - } + if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1) + { + ApplicationPageShowContextMenu1(); + } + else + { + ApplicationPageShowContextMenu2(); + } - break; + break; - case NM_DBLCLK: + case NM_DBLCLK: - ApplicationPage_OnSwitchTo(); + ApplicationPage_OnSwitchTo(); - break; - } - } - else if (pnmh->hwndFrom == ListView_GetHeader(hApplicationPageListCtrl)) - { - switch (pnmh->code) - { - case NM_RCLICK: + break; + } + } + else if (pnmh->hwndFrom == ListView_GetHeader(hApplicationPageListCtrl)) + { + switch (pnmh->code) + { + case NM_RCLICK: - if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1) - { - ApplicationPageShowContextMenu1(); - } - else - { - ApplicationPageShowContextMenu2(); - } + if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1) + { + ApplicationPageShowContextMenu1(); + } + else + { + ApplicationPageShowContextMenu2(); + } - break; + break; - case HDN_ITEMCLICK: + case HDN_ITEMCLICK: - ListView_SortItems(hApplicationPageListCtrl, ApplicationPageCompareFunc, 0); - bSortAscending = !bSortAscending; + ListView_SortItems(hApplicationPageListCtrl, ApplicationPageCompareFunc, 0); + bSortAscending = !bSortAscending; - break; - } - } + break; + } + } } void ApplicationPageShowContextMenu1(void) { - HMENU hMenu; - HMENU hSubMenu; - POINT pt; + HMENU hMenu; + HMENU hSubMenu; + POINT pt; - GetCursorPos(&pt); + GetCursorPos(&pt); - hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1)); - hSubMenu = GetSubMenu(hMenu, 0); + 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); + 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); + TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); - DestroyMenu(hMenu); + DestroyMenu(hMenu); } void ApplicationPageShowContextMenu2(void) { - HMENU hMenu; - HMENU hSubMenu; - POINT pt; + HMENU hMenu; + HMENU hSubMenu; + POINT pt; - GetCursorPos(&pt); + GetCursorPos(&pt); - hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2)); - hSubMenu = GetSubMenu(hMenu, 0); + 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); - } + 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); + SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND); - TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); + TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); - DestroyMenu(hMenu); + DestroyMenu(hMenu); } void ApplicationPage_OnViewLargeIcons(void) { - HMENU hMenu; - HMENU hViewMenu; + HMENU hMenu; + HMENU hViewMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); + 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); + 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(); + UpdateApplicationListControlViewSetting(); } void ApplicationPage_OnViewSmallIcons(void) { - HMENU hMenu; - HMENU hViewMenu; + HMENU hMenu; + HMENU hViewMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); + 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); + 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(); + UpdateApplicationListControlViewSetting(); } void ApplicationPage_OnViewDetails(void) { - HMENU hMenu; - HMENU hViewMenu; + HMENU hMenu; + HMENU hViewMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); + 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); + 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(); + UpdateApplicationListControlViewSetting(); } void ApplicationPage_OnWindowsTileHorizontally(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; - HWND* hWndArray; - int nWndCount; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + HWND* hWndArray; + int nWndCount; - hWndArray = new HWND[ListView_GetItemCount(hApplicationPageListCtrl)]; - nWndCount = 0; + hWndArray = new HWND[ListView_GetItemCount(hApplicationPageListCtrl)]; + nWndCount = 0; - for (i=0; ihWnd; - nWndCount++; - } - } - } + if (pAPLI) + { + hWndArray[nWndCount] = pAPLI->hWnd; + nWndCount++; + } + } + } - TileWindows(NULL, MDITILE_HORIZONTAL, NULL, nWndCount, hWndArray); + TileWindows(NULL, MDITILE_HORIZONTAL, NULL, nWndCount, hWndArray); - delete[] hWndArray; + delete[] hWndArray; } void ApplicationPage_OnWindowsTileVertically(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; - HWND* hWndArray; - int nWndCount; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + HWND* hWndArray; + int nWndCount; - hWndArray = new HWND[ListView_GetItemCount(hApplicationPageListCtrl)]; - nWndCount = 0; + hWndArray = new HWND[ListView_GetItemCount(hApplicationPageListCtrl)]; + nWndCount = 0; - for (i=0; ihWnd; - nWndCount++; - } - } - } + if (pAPLI) + { + hWndArray[nWndCount] = pAPLI->hWnd; + nWndCount++; + } + } + } - TileWindows(NULL, MDITILE_VERTICAL, NULL, nWndCount, hWndArray); + TileWindows(NULL, MDITILE_VERTICAL, NULL, nWndCount, hWndArray); - delete[] hWndArray; + delete[] hWndArray; } void ApplicationPage_OnWindowsMinimize(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; - for (i=0; ihWnd, SW_MINIMIZE); - } - } - } + if (pAPLI) + { + ShowWindow(pAPLI->hWnd, SW_MINIMIZE); + } + } + } } void ApplicationPage_OnWindowsMaximize(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; - for (i=0; ihWnd, SW_MAXIMIZE); - } - } - } + if (pAPLI) + { + ShowWindow(pAPLI->hWnd, SW_MAXIMIZE); + } + } + } } void ApplicationPage_OnWindowsCascade(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; - HWND* hWndArray; - int nWndCount; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + HWND* hWndArray; + int nWndCount; - hWndArray = new HWND[ListView_GetItemCount(hApplicationPageListCtrl)]; - nWndCount = 0; + hWndArray = new HWND[ListView_GetItemCount(hApplicationPageListCtrl)]; + nWndCount = 0; - for (i=0; ihWnd; - nWndCount++; - } - } - } + if (pAPLI) + { + hWndArray[nWndCount] = pAPLI->hWnd; + nWndCount++; + } + } + } - CascadeWindows(NULL, 0, NULL, nWndCount, hWndArray); + CascadeWindows(NULL, 0, NULL, nWndCount, hWndArray); - delete[] hWndArray; + delete[] hWndArray; } void ApplicationPage_OnWindowsBringToFront(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; - for (i=0; ihWnd)) - ShowWindow(pAPLI->hWnd, SW_RESTORE); + if (pAPLI) + { + if (IsIconic(pAPLI->hWnd)) + ShowWindow(pAPLI->hWnd, SW_RESTORE); - BringWindowToTop(pAPLI->hWnd); - } + BringWindowToTop(pAPLI->hWnd); + } } void ApplicationPage_OnSwitchTo(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; + 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); + if (SwitchToThisWindow) + SwitchToThisWindow(pAPLI->hWnd, TRUE); + else + { + if (IsIconic(pAPLI->hWnd)) + ShowWindow(pAPLI->hWnd, SW_RESTORE); - BringWindowToTop(pAPLI->hWnd); - SetForegroundWindow(pAPLI->hWnd); - } + BringWindowToTop(pAPLI->hWnd); + SetForegroundWindow(pAPLI->hWnd); + } - if (TaskManagerSettings.MinimizeOnUse) - ShowWindow(hMainWnd, SW_MINIMIZE); - } + if (TaskManagerSettings.MinimizeOnUse) + ShowWindow(hMainWnd, SW_MINIMIZE); + } } void ApplicationPage_OnEndTask(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; - for (i=0; ihWnd, WM_CLOSE, 0, 0); - } - } - } + if (pAPLI) + { + PostMessage(pAPLI->hWnd, WM_CLOSE, 0, 0); + } + } + } } void ApplicationPage_OnGotoProcess(void) { - LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; - LV_ITEM item; - int i; - NMHDR nmhdr; + LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL; + LV_ITEM item; + int i; + NMHDR nmhdr; - for (i=0; ihWnd, &dwProcessId); + GetWindowThreadProcessId(pAPLI->hWnd, &dwProcessId); - // - // Switch to the process tab - // - TabCtrl_SetCurFocus(hTabWnd, 1); + // + // Switch to the process tab + // + TabCtrl_SetCurFocus(hTabWnd, 1); - // - // FIXME: Select the process item in the list - // - for (i=0; iszTitle, Param2->szTitle); + Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2; + Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1; + } + return strcmp(Param1->szTitle, Param2->szTitle); } diff --git a/rosapps/taskmgr/GraphCtrl.cpp b/rosapps/taskmgr/GraphCtrl.cpp new file mode 100644 index 00000000000..f802522e819 --- /dev/null +++ b/rosapps/taskmgr/GraphCtrl.cpp @@ -0,0 +1,722 @@ +/* + * ReactOS Task Manager + * + * GraphCtrl.cpp + * + * Copyright (C) 2002 Robert Dickenson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "stdafx.h" +#include "math.h" +#include "GraphCtrl.h" +#include "TaskMgr.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +LONG OldGraphCtrlWndProc; + + +TGraphCtrl::TGraphCtrl() : + m_hWnd(0), + m_hParentWnd(0), + m_dcGrid(0), + m_dcPlot(0), + m_bitmapOldGrid(0), + m_bitmapOldPlot(0), + m_bitmapGrid(0), + m_bitmapPlot(0), + m_brushBack(0) +{ + //RECT m_rectClient; + //RECT m_rectPlot; + m_penPlot[0] = 0; + m_penPlot[1] = 0; + m_penPlot[2] = 0; + 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. + m_dPreviousPosition[0] = 0.0; + m_dPreviousPosition[1] = 0.0; + m_dPreviousPosition[2] = 0.0; + m_dPreviousPosition[3] = 0.0; + + // public variable for the number of decimal places on the y axis + 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; + m_dLowerLimit = 0.0; + m_dUpperLimit = 100.0; + m_dRange = m_dUpperLimit - 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 + m_nShiftPixels = 4; + m_nHalfShiftPixels = m_nShiftPixels/2; // protected + m_nPlotShiftPixels = m_nShiftPixels + m_nHalfShiftPixels; // protected + + // background, grid and data colors + // these are public variables and can be set directly + m_crBackColor = RGB( 0, 0, 0); // see also SetBackgroundColor + m_crGridColor = RGB( 0, 255, 255); // see also SetGridColor + m_crPlotColor[0] = RGB(255, 255, 255); // see also SetPlotColor + m_crPlotColor[1] = RGB(100, 255, 255); // see also SetPlotColor + m_crPlotColor[2] = RGB(255, 100, 255); // see also SetPlotColor + m_crPlotColor[3] = RGB(255, 255, 100); // see also SetPlotColor + + // protected variables + int i; + for (i = 0; i < MAX_PLOTS; i++) { + m_penPlot[i] = CreatePen(PS_SOLID, 0, m_crPlotColor[i]); + } + m_brushBack = CreateSolidBrush(m_crBackColor); + + // public member variables, can be set directly + strcpy(m_strXUnitsString, "Samples"); // can also be set with SetXUnits + strcpy(m_strYUnitsString, "Y units"); // can also be set with SetYUnits + + // protected bitmaps to restore the memory DC's + m_bitmapOldGrid = NULL; + m_bitmapOldPlot = NULL; +#if 0 + for (i = 0; i < MAX_CTRLS; i++) { + if (pCtrlArray[i] == 0) { + pCtrlArray[i] = this; + } + } +#endif +} + +///////////////////////////////////////////////////////////////////////////// +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); +#if 0 + for (int i = 0; i < MAX_CTRLS; i++) { + if (pCtrlArray[i] == this) { + pCtrlArray[i] = 0; + } + } +#endif +} + +///////////////////////////////////////////////////////////////////////////// +BOOL TGraphCtrl::Create(HWND hWnd, HWND hParentWnd, UINT nID) +{ + BOOL result = 0; + + m_hParentWnd = hParentWnd; + m_hWnd = hWnd; + Resize(); + if (result != 0) + InvalidateCtrl(); + return result; +} + +/* +BOOL TGraphCtrl::Create(DWORD dwStyle, const RECT& rect, + HWND hParentWnd, UINT nID) +{ + BOOL result = 0; + + m_hParentWnd = hParentWnd; +// GetClientRect(m_hParentWnd, &m_rectClient); + + // set some member variables to avoid multiple function calls + m_nClientHeight = rect.bottom - rect.top;//rect.Height(); + m_nClientWidth = rect.right - rect.left;//rect.Width(); +// m_nClientHeight = cx; +// m_nClientWidth = cy; + + // the "left" coordinate and "width" will be modified in + // InvalidateCtrl to be based on the width of the y axis scaling +#if 0 + m_rectPlot.left = 20; + m_rectPlot.top = 10; + m_rectPlot.right = rect.right-10; + m_rectPlot.bottom = rect.bottom-25; +#else + m_rectPlot.left = -1; + m_rectPlot.top = -1; + m_rectPlot.right = rect.right-0; + m_rectPlot.bottom = rect.bottom-0; +#endif + // set some member variables to avoid multiple function calls + m_nPlotHeight = m_rectPlot.bottom - m_rectPlot.top;//m_rectPlot.Height(); + m_nPlotWidth = m_rectPlot.right - m_rectPlot.left;//m_rectPlot.Width(); + + // set the scaling factor for now, this can be adjusted + // in the SetRange functions + m_dVerticalFactor = (double)m_nPlotHeight / m_dRange; + + if (result != 0) + InvalidateCtrl(); + return result; +} + */ +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::SetRange(double dLower, double dUpper, int nDecimalPlaces) +{ + //ASSERT(dUpper > dLower); + m_dLowerLimit = dLower; + m_dUpperLimit = dUpper; + m_nYDecimals = nDecimalPlaces; + m_dRange = m_dUpperLimit - m_dLowerLimit; + m_dVerticalFactor = (double)m_nPlotHeight / m_dRange; + // clear out the existing garbage, re-start with a clean plot + InvalidateCtrl(); +} + + +///////////////////////////////////////////////////////////////////////////// +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(); +} + +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::SetGridColor(COLORREF color) +{ + m_crGridColor = color; + // clear out the existing garbage, re-start with a clean plot + InvalidateCtrl(); +} + +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::SetPlotColor(int plot, COLORREF color) +{ + m_crPlotColor[plot] = color; + DeleteObject(m_penPlot[plot]); + m_penPlot[plot] = CreatePen(PS_SOLID, 0, m_crPlotColor[plot]); + // clear out the existing garbage, re-start with a clean plot + InvalidateCtrl(); +} + +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::SetBackgroundColor(COLORREF color) +{ + m_crBackColor = color; + DeleteObject(m_brushBack); + m_brushBack = CreateSolidBrush(m_crBackColor); + // clear out the existing garbage, re-start with a clean plot + InvalidateCtrl(); + +} + +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::InvalidateCtrl() +{ + // 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, 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(m_hParentWnd); + + // if we don't have one yet, set up a memory dc for the grid + if (m_dcGrid == NULL) { + m_dcGrid = CreateCompatibleDC(dc); + m_bitmapGrid = CreateCompatibleBitmap(dc, m_nClientWidth, m_nClientHeight); + m_bitmapOldGrid = (HBITMAP)SelectObject(m_dcGrid, m_bitmapGrid); + } + + SetBkColor(m_dcGrid, m_crBackColor); + + // fill the grid background + FillRect(m_dcGrid, &m_rectClient, m_brushBack); + + // draw the plot rectangle: + // determine how wide the y axis scaling values are + nCharacters = abs((int)log10(fabs(m_dUpperLimit))); + nCharacters = max(nCharacters, abs((int)log10(fabs(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 + 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); + m_rectPlot.left = m_rectClient.left; + m_nPlotWidth = m_rectPlot.right - m_rectPlot.left;//m_rectPlot.Width(); + + // draw the plot rectangle + oldPen = (HPEN)SelectObject(m_dcGrid, solidPen); + MoveToEx(m_dcGrid, m_rectPlot.left, m_rectPlot.top, NULL); + LineTo(m_dcGrid, m_rectPlot.right+1, m_rectPlot.top); + LineTo(m_dcGrid, m_rectPlot.right+1, m_rectPlot.bottom+1); + LineTo(m_dcGrid, m_rectPlot.left, m_rectPlot.bottom+1); +// LineTo(m_dcGrid, m_rectPlot.left, m_rectPlot.top); + SelectObject(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 = (m_rectPlot.top + m_rectPlot.bottom)/2; + nTopGridPix = nMidGridPix - m_nPlotHeight/4; + nBottomGridPix = nMidGridPix + m_nPlotHeight/4; + + for (i=m_rectPlot.left; i= m_rectPlot.bottom) || (currY >= m_rectPlot.bottom)) { + RECT rc; + rc.bottom = m_rectClient.bottom+1; + rc.left = prevX; + rc.right = currX+1; + rc.top = m_rectPlot.bottom+1; + //RECT rc(prevX, m_rectPlot.bottom+1, currX+1, m_rectClient.bottom+1); + FillRect(m_dcPlot, &rc, m_brushBack); + } + + // store the current point for connection to the next point + m_dPreviousPosition[i] = m_dCurrentPosition[i]; + } + } +} + +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::Resize(void) +{ + // NOTE: Resize automatically gets called during the setup of the control + GetClientRect(m_hWnd, &m_rectClient); + + // set some member variables to avoid multiple function calls + m_nClientHeight = m_rectClient.bottom - m_rectClient.top;//m_rectClient.Height(); + m_nClientWidth = m_rectClient.right - 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 + m_rectPlot.left = 20; + m_rectPlot.top = 10; + m_rectPlot.right = m_rectClient.right-10; + m_rectPlot.bottom = m_rectClient.bottom-25; +#else + m_rectPlot.left = 0; + m_rectPlot.top = -1; + m_rectPlot.right = m_rectClient.right-0; + m_rectPlot.bottom = m_rectClient.bottom-0; +#endif + + // set some member variables to avoid multiple function calls + m_nPlotHeight = m_rectPlot.bottom - m_rectPlot.top;//m_rectPlot.Height(); + m_nPlotWidth = m_rectPlot.right - m_rectPlot.left;//m_rectPlot.Width(); + + // set the scaling factor for now, this can be adjusted + // in the SetRange functions + m_dVerticalFactor = (double)m_nPlotHeight / m_dRange; +} + + +///////////////////////////////////////////////////////////////////////////// +void TGraphCtrl::Reset() +{ + // to clear the existing data (in the form of a bitmap) + // simply invalidate the entire control + InvalidateCtrl(); +} + + +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; + //LONG WindowId; + //TGraphCtrl* pGraphCtrl; + + 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_PAINT: + hdc = BeginPaint(hWnd, &ps); +// pGraphCtrl = TGraphCtrl::LookupGraphCtrl(hWnd); +// if (pGraphCtrl) pGraphCtrl->Paint(hdc); + GetClientRect(hWnd, &rcClient); + if (hWnd == hPerformancePageMemUsageHistoryGraph) { + PerformancePageMemUsageHistoryGraph.Paint(hWnd, hdc); + } + if (hWnd == hPerformancePageCpuUsageHistoryGraph) { + PerformancePageCpuUsageHistoryGraph.Paint(hWnd, hdc); + } + EndPaint(hWnd, &ps); + return 0; +/* + 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; + } + */ + + case WM_SIZE: +// pGraphCtrl = TGraphCtrl::LookupGraphCtrl(hWnd); +// if (pGraphCtrl) pGraphCtrl->Resize(wParam, HIWORD(lParam), LOWORD(lParam)); + if (hWnd == hPerformancePageMemUsageHistoryGraph) { + PerformancePageMemUsageHistoryGraph.Resize(); + } + if (hWnd == hPerformancePageCpuUsageHistoryGraph) { + PerformancePageCpuUsageHistoryGraph.Resize(); + } + return 0; + } + + + // + // We pass on all non-handled messages + // + return CallWindowProc((WNDPROC)OldGraphCtrlWndProc, hWnd, message, wParam, lParam); +} + + +#if 0 + +#include "GraphCtrl.h" + +TGraphCtrl* TGraphCtrl::pCtrlArray[] = { 0, 0, 0, 0 }; +int TGraphCtrl::CtrlCount = 0; + +TGraphCtrl* TGraphCtrl::LookupGraphCtrl(HWND hWnd) +{ + for (int i = 0; i < MAX_CTRLS; i++) { + if (pCtrlArray[i] != 0) { + if (pCtrlArray[i]->m_hParentWnd == hWnd) { + return pCtrlArray[i]; + } + } + } + return NULL; +} + +#endif + diff --git a/rosapps/taskmgr/GraphCtrl.h b/rosapps/taskmgr/GraphCtrl.h new file mode 100644 index 00000000000..b9037053e2f --- /dev/null +++ b/rosapps/taskmgr/GraphCtrl.h @@ -0,0 +1,112 @@ +/* + * ReactOS Task Manager + * + * GraphCtrl.h + * + * Copyright (C) 2002 Robert Dickenson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __GRAPH_CTRL_H__ +#define __GRAPH_CTRL_H__ + +#define MAX_PLOTS 4 +#define MAX_CTRLS 4 + + +class TGraphCtrl +{ +// Attributes +public: + double AppendPoint(double dNewPoint0, double dNewPoint1 = 0.0, + double dNewPoint2 = 0.0, double dNewPoint3 = 0.0); + void SetRange(double dLower, double dUpper, int nDecimalPlaces=1); + void SetXUnits(const char* string); + void SetYUnits(const char* string); + void SetGridColor(COLORREF color); + void SetPlotColor(int plot, COLORREF color); + void SetBackgroundColor(COLORREF color); + void InvalidateCtrl(); + void DrawPoint(); + void Reset(); + + // Operations +public: + BOOL Create(DWORD dwStyle, const RECT& rect, HWND hParentWnd, UINT nID=NULL); + BOOL Create(HWND hWnd, HWND hParentWnd, UINT nID=NULL); + void Paint(HWND hWnd, HDC dc); + void Resize(void); + +#if 0 + static TGraphCtrl* LookupGraphCtrl(HWND hWnd); + static TGraphCtrl* pCtrlArray[MAX_CTRLS]; + static int CtrlCount; +#endif + +// Implementation +public: + 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 + +// Construction +public: + TGraphCtrl(); + virtual ~TGraphCtrl(); + +protected: + 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; +}; + +extern LONG OldGraphCtrlWndProc; + +LRESULT CALLBACK GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + + +#endif /* __GRAPH_CTRL_H__ */ +///////////////////////////////////////////////////////////////////////////// diff --git a/rosapps/taskmgr/PerformancePage.cpp b/rosapps/taskmgr/PerformancePage.cpp index e96b9e5bc4a..3c6517d4ed9 100644 --- a/rosapps/taskmgr/PerformancePage.cpp +++ b/rosapps/taskmgr/PerformancePage.cpp @@ -20,16 +20,35 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" -#include "TASKMGR.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "TaskMgr.h" #include "PerformancePage.h" #include "perfdata.h" + #include "graph.h" +#include "GraphCtrl.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 @@ -37,6 +56,11 @@ 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 @@ -52,6 +76,21 @@ HWND hPerformancePagePhysicalMemorySystemCacheEdit; // Physical Memory System C HWND hPerformancePageTotalsHandleCountEdit; // Total Handles Edit Control HWND hPerformancePageTotalsProcessCountEdit; // Total Processes Edit Control HWND hPerformancePageTotalsThreadCountEdit; // Total Threads Edit Control +#if 0 +HWND hPerformancePageCommitChargeTotalLabel; +HWND hPerformancePageCommitChargeLimitLabel; +HWND hPerformancePageCommitChargePeakLabel; +HWND hPerformancePageKernelMemoryTotalLabel; +HWND hPerformancePageKernelMemoryPagedLabel; +HWND hPerformancePageKernelMemoryNonPagedLabel; +HWND hPerformancePagePhysicalMemoryTotalLabel; +HWND hPerformancePagePhysicalMemoryAvailableLabel; +HWND hPerformancePagePhysicalMemorySystemCacheLabel; +HWND hPerformancePageTotalsHandleCountLabel; +HWND hPerformancePageTotalsProcessCountLabel; +HWND hPerformancePageTotalsThreadCountLabel; +#endif + static int nPerformancePageWidth; static int nPerformancePageHeight; @@ -60,6 +99,54 @@ static HANDLE hPerformancePageEvent = NULL; // When this event becomes signaled void PerformancePageRefreshThread(void *lpParameter); +void AdjustFramePostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference) +{ + RECT rc; + int cx, cy; + GetClientRect(hCntrl, &rc); + MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hCntrl, NULL, TRUE); +} + +void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference) +{ + RECT rc; + int cx, cy, sx, sy; + GetClientRect(hCntrl, &rc); + MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) ); +// cx = rc.left + nXDifference; +// cy = rc.top + nYDifference; + cx = rc.left; + cy = rc.top; + sx = rc.right - rc.left + nXDifference; + sy = rc.bottom - rc.top + nYDifference; +// SetWindowPos(hCntrl, NULL, 0, 0, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); +// SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER); + InvalidateRect(hCntrl, NULL, TRUE); +} + +void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference) +{ + RECT rc; + int cx, cy; + + GetClientRect(hCntrl, &rc); + MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT))); + cx = rc.left + nXDifference; + cy = rc.top + nYDifference; + SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + InvalidateRect(hCntrl, NULL, TRUE); +} + +void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference) +{ + AdjustControlPostion(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference); +} + LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc; @@ -85,6 +172,12 @@ LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, 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); @@ -97,20 +190,63 @@ LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT); hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT); hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT); +#if 0 + hPerformancePageCommitChargeTotalLabel = GetDlgItem(hDlg, IDS_COMMIT_CHARGE_TOTAL); + hPerformancePageCommitChargeLimitLabel = GetDlgItem(hDlg, IDS_COMMIT_CHARGE_LIMIT); + hPerformancePageCommitChargePeakLabel = GetDlgItem(hDlg, IDS_COMMIT_CHARGE_PEAK); + hPerformancePageKernelMemoryTotalLabel = GetDlgItem(hDlg, IDS_KERNEL_MEMORY_TOTAL); + hPerformancePageKernelMemoryPagedLabel = GetDlgItem(hDlg, IDS_KERNEL_MEMORY_PAGED); + hPerformancePageKernelMemoryNonPagedLabel = GetDlgItem(hDlg, IDS_KERNEL_MEMORY_NONPAGED); + hPerformancePagePhysicalMemoryTotalLabel = GetDlgItem(hDlg, IDS_PHYSICAL_MEMORY_TOTAL); + hPerformancePagePhysicalMemoryAvailableLabel = GetDlgItem(hDlg, IDS_PHYSICAL_MEMORY_AVAILABLE); + hPerformancePagePhysicalMemorySystemCacheLabel = GetDlgItem(hDlg, IDS_PHYSICAL_MEMORY_SYSTEM_CACHE); + hPerformancePageTotalsHandleCountLabel = GetDlgItem(hDlg, IDS_TOTALS_HANDLE_COUNT); + hPerformancePageTotalsProcessCountLabel = GetDlgItem(hDlg, IDS_TOTALS_PROCESS_COUNT); + hPerformancePageTotalsThreadCountLabel = GetDlgItem(hDlg, IDS_TOTALS_THREAD_COUNT); +#endif 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); - // Start our refresh thread - _beginthread(PerformancePageRefreshThread, 0, NULL); + GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc); + // create the control + //PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); + PerformancePageCpuUsageHistoryGraph.Create(hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); + // customize the control + PerformancePageCpuUsageHistoryGraph.SetRange(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)) ; + PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 0)) ; + PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(152, 205, 152)) ; + PerformancePageCpuUsageHistoryGraph.SetPlotColor(0, RGB(255, 0, 0)) ; + PerformancePageCpuUsageHistoryGraph.SetPlotColor(1, RGB(0, 255, 0)) ; + GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc); + PerformancePageMemUsageHistoryGraph.Create(hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH); + PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; + PerformancePageMemUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 0)) ; + PerformancePageMemUsageHistoryGraph.SetGridColor(RGB(152, 215, 152)) ; + PerformancePageMemUsageHistoryGraph.SetPlotColor(0, RGB(255, 255, 0)) ; + + // Start our refresh thread +#ifdef RUN_PERF_PAGE + _beginthread(PerformancePageRefreshThread, 0, NULL); +#endif // // Subclass graph buttons // - OldGraphWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc); - SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc); - SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)Graph_WndProc); + OldGraphWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc); + SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc); +// SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)Graph_WndProc); +// OldGraphCtrlWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc); +// SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc); + OldGraphCtrlWndProc = SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc); + SetWindowLong(hPerformancePageCpuUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc); return TRUE; case WM_COMMAND: @@ -128,35 +264,63 @@ LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, nYDifference = cy - nPerformancePageHeight; nPerformancePageWidth = cx; nPerformancePageHeight = cy; +// SetWindowPos(hPerformancePageMemUsageHistoryGraph, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); +// SetWindowPos(hPerformancePageCpuUsageHistoryGraph, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); // Reposition the performance 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);*/ + AdjustFramePostion(hPerformancePageTotalsFrame, hDlg, nXDifference, nYDifference); + AdjustFramePostion(hPerformancePageCommitChargeFrame, hDlg, nXDifference, nYDifference); + AdjustFramePostion(hPerformancePageKernelMemoryFrame, hDlg, nXDifference, nYDifference); + AdjustFramePostion(hPerformancePagePhysicalMemoryFrame, hDlg, nXDifference, nYDifference); + AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference); +// AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference); +// AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference); +// AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference); +#if 0 + AdjustControlPostion(hPerformancePageCommitChargeTotalLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageCommitChargeLimitLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageCommitChargePeakLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryTotalLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryPagedLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryNonPagedLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemoryTotalLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageTotalsHandleCountLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageTotalsProcessCountLabel, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageTotalsThreadCountLabel, hDlg, nXDifference, nYDifference); +#else + AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, nXDifference, nYDifference); + AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, nXDifference, nYDifference); +#endif + AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, nXDifference, nYDifference); + AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, nXDifference, nYDifference); + +// AdjustControlPostion(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference); +// AdjustControlPostion(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference); +// AdjustControlPostion(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference); +// AdjustControlPostion(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference); break; } @@ -273,7 +437,45 @@ void PerformancePageRefreshThread(void *lpParameter) // InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); + + // + + ULONG CpuUsage; + ULONG CpuKernelUsage; + ULONGLONG CommitChargeTotal; + ULONGLONG CommitChargeLimit; + ULONG PhysicalMemoryTotal; + ULONG PhysicalMemoryAvailable; + int nBarsUsed1; + int nBarsUsed2; + + // + // 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 = ((CommitChargeTotal * 100) / CommitChargeLimit); + + PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); + PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); + nBarsUsed2 = ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal); + + + PerformancePageCpuUsageHistoryGraph.AppendPoint(CpuUsage, CpuKernelUsage); + PerformancePageMemUsageHistoryGraph.AppendPoint(nBarsUsed1, nBarsUsed2); + //PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); + InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } } diff --git a/rosapps/taskmgr/ProcessPage.cpp b/rosapps/taskmgr/ProcessPage.cpp index 9e527becff6..bf6d3ca2f7d 100644 --- a/rosapps/taskmgr/ProcessPage.cpp +++ b/rosapps/taskmgr/ProcessPage.cpp @@ -20,30 +20,43 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" -#include "TASKMGR.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "TaskMgr.h" #include "ProcessPage.h" #include "perfdata.h" #include "column.h" #include "proclist.h" #include -HWND hProcessPage; // Process List Property Page +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 +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); -void ProcessPageRefreshThread(void *lpParameter); +void ProcessPageOnNotify(WPARAM wParam, LPARAM lParam); +void CommaSeparateNumberString(LPTSTR strNumber, int nMaxCount); +void ProcessPageShowContextMenu(DWORD dwProcessId); +void ProcessPageRefreshThread(void *lpParameter); LRESULT CALLBACK ProcessPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { @@ -197,11 +210,15 @@ void ProcessPageOnNotify(WPARAM wParam, LPARAM lParam) if (ColumnDataHints[ColumnIndex] == COLUMN_CPUTIME) { time = PerfDataGetCPUTime(Index); - - DWORD dwHours = (DWORD)(time.QuadPart / 36000000000LL); - DWORD dwMinutes = (DWORD)((time.QuadPart % 36000000000LL) / 600000000LL); - DWORD dwSeconds = (DWORD)(((time.QuadPart % 36000000000LL) % 600000000LL) / 10000000LL); - +#ifdef _MSC_VER + DWORD dwHours = (DWORD)(time.QuadPart / 36000000000L); + DWORD dwMinutes = (DWORD)((time.QuadPart % 36000000000L) / 600000000L); + DWORD dwSeconds = (DWORD)(((time.QuadPart % 36000000000L) % 600000000L) / 10000000L); +#else + DWORD dwHours = (DWORD)(time.QuadPart / 36000000000LL); + DWORD dwMinutes = (DWORD)((time.QuadPart % 36000000000LL) / 600000000LL); + DWORD dwSeconds = (DWORD)(((time.QuadPart % 36000000000LL) % 600000000LL) / 10000000LL); +#endif wsprintf(pnmdi->item.pszText, _T("%d:%02d:%02d"), dwHours, dwMinutes, dwSeconds); } if (ColumnDataHints[ColumnIndex] == COLUMN_MEMORYUSAGE) diff --git a/rosapps/taskmgr/TASKMGR.cpp b/rosapps/taskmgr/TASKMGR.cpp index 775df9a0d59..c98a5a98a3b 100644 --- a/rosapps/taskmgr/TASKMGR.cpp +++ b/rosapps/taskmgr/TASKMGR.cpp @@ -1,9 +1,22 @@ -// TASKMGR.cpp : Defines the entry point for the application. +// TaskMgr.cpp : Defines the entry point for the application. // +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "resource.h" -#include "TASKMGR.h" +#include "TaskMgr.h" #include "ApplicationPage.h" #include "ProcessPage.h" #include "PerformancePage.h" @@ -18,331 +31,357 @@ #include "about.h" #include "trayicon.h" -#define STATUS_WINDOW 2001 +#define STATUS_WINDOW 2001 // Global Variables: -HINSTANCE hInst; // current instance -HWND hMainWnd; // Main Window -HWND hStatusWnd; // Status Bar Window -HWND hTabWnd; // Tab Control Window +HINSTANCE hInst; // current instance -int nMinimumWidth; // Minimum width of the dialog (OnSize()'s cx) -int nMinimumHeight; // Minimum height of the dialog (OnSize()'s cy) +HWND hMainWnd; // Main Window +HWND hStatusWnd; // Status Bar Window +HWND hTabWnd; // Tab Control Window -int nOldWidth; // Holds the previous client area width -int nOldHeight; // Holds the previous client area height +int nMinimumWidth; // Minimum width of the dialog (OnSize()'s cx) +int nMinimumHeight; // Minimum height of the dialog (OnSize()'s cy) -BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop +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; -TASKMANAGER_SETTINGS TaskManagerSettings; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - // Initialize global variables - hInst = hInstance; + // Initialize global variables + hInst = hInstance; - // Change our priority class to HIGH - HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); - SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS); - CloseHandle(hProcess); + // Change our priority class to HIGH + HANDLE 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 - HANDLE hToken; - TOKEN_PRIVILEGES tkp; + // Now lets get the SE_DEBUG_NAME priviledge + // so that we can debug processes + HANDLE hToken; + TOKEN_PRIVILEGES tkp; - // Get a token for this process. + // 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); - 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; - 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); + } - // Get the debug privilege for this process. - AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); - } + // Load our settings from the registry + LoadSettings(); - // Load our settings from the registry - LoadSettings(); + // Initialize perf data + if (!PerfDataInitialize()) { + return -1; + } - // 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; + DialogBox(hInst, (LPCTSTR)IDD_TASKMGR_DIALOG, NULL, (DLGPROC)TaskManagerWndProc); + + // Save our settings to the registry + SaveSettings(); + PerfDataUninitialize(); + return 0; } +#define _USE_CMD_MAP + +#ifdef _USE_CMD_MAP +#define BEGIN_CMD_MAP(a) switch(##a) { +#define CMD_MAP_ENTRY(a, b) case a: b(); break; +#define END_CMD_MAP(a) } + +#endif + // Message handler for dialog box. LRESULT CALLBACK TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - HDC hdc; - PAINTSTRUCT ps; - LPRECT pRC; - RECT rc; + HDC hdc; + PAINTSTRUCT ps; + LPRECT pRC; + RECT rc; + switch (message) + { + case WM_INITDIALOG: + hMainWnd = hDlg; + return OnCreate(hDlg); - switch (message) - { - case WM_INITDIALOG: - hMainWnd = hDlg; + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; + } +#ifdef _USE_CMD_MAP + BEGIN_CMD_MAP(LOWORD(wParam)) + CMD_MAP_ENTRY(ID_FILE_NEW, TaskManager_OnFileNew) + CMD_MAP_ENTRY(ID_OPTIONS_ALWAYSONTOP, TaskManager_OnOptionsAlwaysOnTop) + CMD_MAP_ENTRY(ID_OPTIONS_MINIMIZEONUSE, TaskManager_OnOptionsMinimizeOnUse) + CMD_MAP_ENTRY(ID_OPTIONS_HIDEWHENMINIMIZED, TaskManager_OnOptionsHideWhenMinimized) + CMD_MAP_ENTRY(ID_OPTIONS_SHOW16BITTASKS, TaskManager_OnOptionsShow16BitTasks) + CMD_MAP_ENTRY(ID_VIEW_LARGE, ApplicationPage_OnViewLargeIcons) + CMD_MAP_ENTRY(ID_VIEW_SMALL, ApplicationPage_OnViewSmallIcons) + CMD_MAP_ENTRY(ID_VIEW_DETAILS, ApplicationPage_OnViewDetails) + CMD_MAP_ENTRY(ID_VIEW_SHOWKERNELTIMES, PerformancePage_OnViewShowKernelTimes) + CMD_MAP_ENTRY(ID_VIEW_CPUHISTORY_ONEGRAPHALL, PerformancePage_OnViewCPUHistoryOneGraphAll) + CMD_MAP_ENTRY(ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, PerformancePage_OnViewCPUHistoryOneGraphPerCPU) + CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_HIGH, TaskManager_OnViewUpdateSpeedHigh) + CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_NORMAL, TaskManager_OnViewUpdateSpeedNormal) + CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_LOW, TaskManager_OnViewUpdateSpeedLow) + CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_PAUSED, TaskManager_OnViewUpdateSpeedPaused) + CMD_MAP_ENTRY(ID_VIEW_SELECTCOLUMNS, ProcessPage_OnViewSelectColumns) + CMD_MAP_ENTRY(ID_VIEW_REFRESH, TaskManager_OnViewRefresh) + CMD_MAP_ENTRY(ID_WINDOWS_TILEHORIZONTALLY, ApplicationPage_OnWindowsTileHorizontally) + CMD_MAP_ENTRY(ID_WINDOWS_TILEVERTICALLY, ApplicationPage_OnWindowsTileVertically) + CMD_MAP_ENTRY(ID_WINDOWS_MINIMIZE, ApplicationPage_OnWindowsMinimize) + CMD_MAP_ENTRY(ID_WINDOWS_MAXIMIZE, ApplicationPage_OnWindowsMaximize) + CMD_MAP_ENTRY(ID_WINDOWS_CASCADE, ApplicationPage_OnWindowsCascade) + CMD_MAP_ENTRY(ID_WINDOWS_BRINGTOFRONT, ApplicationPage_OnWindowsBringToFront) + CMD_MAP_ENTRY(ID_APPLICATION_PAGE_SWITCHTO, ApplicationPage_OnSwitchTo) + CMD_MAP_ENTRY(ID_APPLICATION_PAGE_ENDTASK, ApplicationPage_OnEndTask) + CMD_MAP_ENTRY(ID_APPLICATION_PAGE_GOTOPROCESS, ApplicationPage_OnGotoProcess) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_ENDPROCESS, ProcessPage_OnEndProcess) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_ENDPROCESSTREE, ProcessPage_OnEndProcessTree) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_DEBUG, ProcessPage_OnDebug) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETAFFINITY, ProcessPage_OnSetAffinity) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ProcessPage_OnSetPriorityRealTime) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_HIGH, ProcessPage_OnSetPriorityHigh) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, ProcessPage_OnSetPriorityAboveNormal) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_NORMAL, ProcessPage_OnSetPriorityNormal) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, ProcessPage_OnSetPriorityBelowNormal) + CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_LOW, ProcessPage_OnSetPriorityLow) + CMD_MAP_ENTRY(ID_HELP_ABOUT, OnAbout) + END_CMD_MAP(0) +#else + // 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_HELP_ABOUT: + OnAbout(); + break; + } +#endif + break; - return OnCreate(hDlg); + case WM_NOTIFY: + int idctrl; + LPNMHDR pnmh; + idctrl = (int)wParam; + pnmh = (LPNMHDR)lParam; + if ((pnmh->hwndFrom == hTabWnd) && + (pnmh->idFrom == IDC_TAB) && + (pnmh->code == TCN_SELCHANGE)) + { + TaskManager_OnTabWndSelChange(); + } + break; - case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - } + 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; - // 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_HELP_ABOUT: - OnAbout(); - 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; - 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_NOTIFY: - int idctrl; - LPNMHDR pnmh; + case WM_SIZE: + // Handle the window sizing in it's own function + OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); + break; - idctrl = (int) wParam; - pnmh = (LPNMHDR) lParam; + case WM_MOVE: + // Handle the window moving in it's own function + OnMove(wParam, LOWORD(lParam), HIWORD(lParam)); + break; - if ((pnmh->hwndFrom == hTabWnd) && - (pnmh->idFrom == IDC_TAB) && - (pnmh->code == TCN_SELCHANGE)) - { - TaskManager_OnTabWndSelChange(); - } + case WM_DESTROY: + WINDOWPLACEMENT wp; + 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; - 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_DESTROY: - WINDOWPLACEMENT wp; - - 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; - } + 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; } @@ -356,203 +395,229 @@ void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr) void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr) { - SetBkColor(hDC, clr); - RECT rect; - rect.left = x; - rect.top = y; - rect.right = x + cx; - rect.bottom = y + cy; - ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); + SetBkColor(hDC, clr); + RECT rect; + 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) { - FillSolidRect(hDC, x, y, cx - 1, 1, clrTopLeft); - FillSolidRect(hDC, x, y, 1, cy - 1, clrTopLeft); - FillSolidRect(hDC, x + cx, y, -1, cy, clrBottomRight); - FillSolidRect(hDC, x, y + cy, cx, -1, clrBottomRight); + FillSolidRect(hDC, x, y, cx - 1, 1, clrTopLeft); + FillSolidRect(hDC, x, y, 1, cy - 1, clrTopLeft); + FillSolidRect(hDC, x + cx, y, -1, cy, clrBottomRight); + FillSolidRect(hDC, x, y + cy, cx, -1, clrBottomRight); } void Draw3dRect(HDC hDC, LPRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight) { - Draw3dRect(hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left, - lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight); + Draw3dRect(hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left, + lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight); } BOOL OnCreate(HWND hWnd) { - int nParts[3]; - RECT rc; - char szTemp[256]; - TCITEM item; + int nParts[3]; + RECT rc; + char szTemp[256]; + TCITEM item; - SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER))); + SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER))); - // Initialize the Windows Common Controls DLL - InitCommonControls(); + // 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); + // 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, "", hWnd, STATUS_WINDOW); - if(!hStatusWnd) - return FALSE; + // Create the status bar + hStatusWnd = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, "", 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 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); - 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); + // 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 + strcpy(szTemp, "Applications"); + memset(&item, 0, sizeof(TCITEM)); + item.mask = TCIF_TEXT; + item.pszText = szTemp; + TabCtrl_InsertItem(hTabWnd, 0, &item); + strcpy(szTemp, "Processes"); + memset(&item, 0, sizeof(TCITEM)); + item.mask = TCIF_TEXT; + item.pszText = szTemp; + TabCtrl_InsertItem(hTabWnd, 1, &item); + strcpy(szTemp, "Performance"); + memset(&item, 0, sizeof(TCITEM)); + item.mask = TCIF_TEXT; + item.pszText = szTemp; + TabCtrl_InsertItem(hTabWnd, 2, &item); - // Insert tabs - strcpy(szTemp, "Applications"); - memset(&item, 0, sizeof(TCITEM)); - item.mask = TCIF_TEXT; - item.pszText = szTemp; - TabCtrl_InsertItem(hTabWnd, 0, &item); - strcpy(szTemp, "Processes"); - memset(&item, 0, sizeof(TCITEM)); - item.mask = TCIF_TEXT; - item.pszText = szTemp; - TabCtrl_InsertItem(hTabWnd, 1, &item); - strcpy(szTemp, "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; - // Size everything correctly - GetClientRect(hWnd, &rc); - nOldWidth = rc.right; - nOldHeight = rc.bottom; + 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); + } + if (TaskManagerSettings.Maximized) + ShowWindow(hWnd, SW_MAXIMIZE); - 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); - } - if (TaskManagerSettings.Maximized) - ShowWindow(hWnd, SW_MAXIMIZE); + // Set the always on top style + HMENU hMenu; + HMENU hEditMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; + HMENU hCPUHistoryMenu; - // Set the always on top style - HMENU hMenu; - HMENU hEditMenu; - HMENU hViewMenu; - HMENU hUpdateSpeedMenu; - HMENU hCPUHistoryMenu; + hMenu = GetMenu(hWnd); + hEditMenu = GetSubMenu(hMenu, 1); + hViewMenu = GetSubMenu(hMenu, 2); + hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + hCPUHistoryMenu = GetSubMenu(hViewMenu, 7); - 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 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 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 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); - // 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.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.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.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); - 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); + int nActivePage = TaskManagerSettings.ActiveTabPage; + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 0); + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1); + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2); + TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage); - int 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); + } - if (TaskManagerSettings.UpdateSpeed == 0) - KillTimer(hWnd, 1); - else if (TaskManagerSettings.UpdateSpeed == 1) - { - KillTimer(hWnd, 1); - SetTimer(hWnd, 1, 500, 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(); - // - // Refresh the performance data - // Sample it twice so we can establish - // the delta values & cpu usage - // - PerfDataRefresh(); - PerfDataRefresh(); + RefreshApplicationPage(); + RefreshProcessPage(); + RefreshPerformancePage(); - RefreshApplicationPage(); - RefreshProcessPage(); - RefreshPerformancePage(); + TrayIcon_ShellAddTrayIcon(); - TrayIcon_ShellAddTrayIcon(); + return TRUE; +} - 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 ) +{ +#if 0 + RECT rc; + + nOldStartX = cx; + nOldStartY = cy; + + GetWindowRect(hTabWnd, &rc); + rc.left += 2;//nOldStartX; + rc.top += 2;//nOldStartY; + rc.right -= 4; + rc.bottom -= 4; + SetWindowPos(hApplicationPage, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + SetWindowPos(hProcessPage, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); + SetWindowPos(hPerformancePage, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); +#endif } // OnSize() @@ -560,431 +625,400 @@ BOOL OnCreate(HWND hWnd) // 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; + int nParts[3]; + int nXDifference; + int nYDifference; + RECT rc; - if (nType == SIZE_MINIMIZED) - return; + if (nType == SIZE_MINIMIZED) + return; - nXDifference = cx - nOldWidth; - nYDifference = cy - nOldHeight; - nOldWidth = cx; - nOldHeight = cy; + 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 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); + // 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 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); + // 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; - char szSubKey[] = "Software\\ReactWare\\TaskManager"; - int i; - DWORD dwSize; + HKEY hKey; + char szSubKey[] = "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; + // Window size & position settings + TaskManagerSettings.Maximized = FALSE; + TaskManagerSettings.Left = 0; + TaskManagerSettings.Top = 0; + TaskManagerSettings.Right = 0; + TaskManagerSettings.Bottom = 0; - // Tab settings - TaskManagerSettings.ActiveTabPage = 0; + // Tab settings + TaskManagerSettings.ActiveTabPage = 0; - // Options menu settings - TaskManagerSettings.AlwaysOnTop = FALSE; - TaskManagerSettings.MinimizeOnUse = TRUE; - TaskManagerSettings.HideWhenMinimized = TRUE; - TaskManagerSettings.Show16BitTasks = TRUE; + // Options menu settings + TaskManagerSettings.AlwaysOnTop = FALSE; + TaskManagerSettings.MinimizeOnUse = TRUE; + TaskManagerSettings.HideWhenMinimized = TRUE; + TaskManagerSettings.Show16BitTasks = TRUE; - // Update speed settings - TaskManagerSettings.UpdateSpeed = 2; + // Update speed settings + TaskManagerSettings.UpdateSpeed = 2; - // Applications page settings - TaskManagerSettings.View_LargeIcons = FALSE; - TaskManagerSettings.View_SmallIcons = FALSE; - TaskManagerSettings.View_Details = TRUE; + // 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; + // 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; + 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.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; - TaskManagerSettings.SortColumn = 1; - TaskManagerSettings.SortAscending = TRUE; + // Performance page settings + TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE; + TaskManagerSettings.ShowKernelTimes = FALSE; - // 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, "Preferences", NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize); - // 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, "Preferences", NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize); - - // Close the key - RegCloseKey(hKey); + // Close the key + RegCloseKey(hKey); } void SaveSettings(void) { - HKEY hKey; - char szSubKey1[] = "Software"; - char szSubKey2[] = "Software\\ReactWare"; - char szSubKey3[] = "Software\\ReactWare\\TaskManager"; + HKEY hKey; + char szSubKey1[] = "Software"; + char szSubKey2[] = "Software\\ReactWare"; + char szSubKey3[] = "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, "Preferences", NULL, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS)); - - // Close the key - RegCloseKey(hKey); + // 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, "Preferences", 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS)); + // Close the key + RegCloseKey(hKey); } void TaskManager_OnEnterMenuLoop(HWND hWnd) { - int nParts; + 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("")); + // 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]; + 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); + 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]; + TCHAR str[100]; - strcpy(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); + strcpy(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 hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); - hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + 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); + 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, 500, NULL); + KillTimer(hMainWnd, 1); + SetTimer(hMainWnd, 1, 1000, NULL); } void TaskManager_OnViewUpdateSpeedNormal(void) { - HMENU hMenu; - HMENU hViewMenu; - HMENU hUpdateSpeedMenu; + HMENU hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); - hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + 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); + 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); + KillTimer(hMainWnd, 1); + SetTimer(hMainWnd, 1, 2000, NULL); } void TaskManager_OnViewUpdateSpeedLow(void) { - HMENU hMenu; - HMENU hViewMenu; - HMENU hUpdateSpeedMenu; + HMENU hMenu; + HMENU hViewMenu; + HMENU hUpdateSpeedMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); - hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1); + 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); + 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); + 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 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); + 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; + int i; + HMENU hMenu; + HMENU hOptionsMenu; + HMENU hViewMenu; + HMENU hSubMenu; - hMenu = GetMenu(hMainWnd); - hViewMenu = GetSubMenu(hMenu, 2); - hOptionsMenu = GetSubMenu(hMenu, 1); + 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, "Lar&ge Icons"); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SMALL, "S&mall Icons"); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_DETAILS, "&Details"); - TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd); + if (GetMenuItemCount(hMenu) <= 4) { + hSubMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_WINDOWSMENU)); + InsertMenu(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT)hSubMenu, "&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; - for (i=GetMenuItemCount(hViewMenu)-1; i>2; i--) - { - hSubMenu = GetSubMenu(hViewMenu, i); + case 1: + ShowWindow(hApplicationPage, SW_HIDE); + ShowWindow(hProcessPage, SW_SHOW); + ShowWindow(hPerformancePage, SW_HIDE); + BringWindowToTop(hProcessPage); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, "&Select Columns..."); + AppendMenu(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, "&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; - 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, "Lar&ge Icons"); - AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SMALL, "S&mall Icons"); - AppendMenu(hViewMenu, MF_STRING, ID_VIEW_DETAILS, "&Details"); - - if (GetMenuItemCount(hMenu) <= 4) - { - hSubMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_WINDOWSMENU)); - InsertMenu(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT)hSubMenu, "&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, "&Select Columns..."); - AppendMenu(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, "&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, "&One Graph, All CPUs"); - AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, "One Graph &Per CPU"); - AppendMenu(hViewMenu, MF_STRING|MF_POPUP, (UINT)hSubMenu, "&CPU History"); - AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, "&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; - } + 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, "&One Graph, All CPUs"); + AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, "One Graph &Per CPU"); + AppendMenu(hViewMenu, MF_STRING|MF_POPUP, (UINT)hSubMenu, "&CPU History"); + AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, "&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; + DWORD dwRet; LPTSTR lpszTemp = NULL; dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY, @@ -996,16 +1030,14 @@ LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ) NULL ); // supplied buffer is not long enough - if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) ) + if (!dwRet || ( (long)dwSize < (long)dwRet+14 )) { lpszBuf[0] = TEXT('\0'); - else - { + } else { lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() ); } - - if ( lpszTemp ) - LocalFree((HLOCAL) lpszTemp ); - + if (lpszTemp) { + LocalFree((HLOCAL)lpszTemp); + } return lpszBuf; } diff --git a/rosapps/taskmgr/about.cpp b/rosapps/taskmgr/about.cpp index b0118f07011..fc2bf6e9615 100644 --- a/rosapps/taskmgr/about.cpp +++ b/rosapps/taskmgr/about.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "about.h" diff --git a/rosapps/taskmgr/affinity.cpp b/rosapps/taskmgr/affinity.cpp index 3375d36f050..a78745f5617 100644 --- a/rosapps/taskmgr/affinity.cpp +++ b/rosapps/taskmgr/affinity.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "ProcessPage.h" #include "affinity.h" diff --git a/rosapps/taskmgr/column.cpp b/rosapps/taskmgr/column.cpp index 0afac9949d9..6f6b5121bec 100644 --- a/rosapps/taskmgr/column.cpp +++ b/rosapps/taskmgr/column.cpp @@ -19,8 +19,21 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "column.h" #include "ProcessPage.h" diff --git a/rosapps/taskmgr/debug.cpp b/rosapps/taskmgr/debug.cpp index a7c44e7ae26..32fb6b0f06b 100644 --- a/rosapps/taskmgr/debug.cpp +++ b/rosapps/taskmgr/debug.cpp @@ -19,8 +19,21 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "debug.h" #include "ProcessPage.h" diff --git a/rosapps/taskmgr/endproc.cpp b/rosapps/taskmgr/endproc.cpp index 87d52de2b09..d262f5052e9 100644 --- a/rosapps/taskmgr/endproc.cpp +++ b/rosapps/taskmgr/endproc.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "endproc.h" #include "ProcessPage.h" diff --git a/rosapps/taskmgr/font.cpp b/rosapps/taskmgr/font.cpp index 1e7816232c6..eb09a965bba 100644 --- a/rosapps/taskmgr/font.cpp +++ b/rosapps/taskmgr/font.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "font.h" @@ -32,15 +45,11 @@ void Font_DrawText(HDC hDC, LPCTSTR lpszText, int x, int y) 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')) - { + 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') @@ -52,7 +61,6 @@ void Font_DrawText(HDC hDC, LPCTSTR lpszText, int x, int y) BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY); } } - SelectObject(hFontDC, hOldBitmap); DeleteObject(hFontBitmap); DeleteDC(hFontDC); diff --git a/rosapps/taskmgr/graph.cpp b/rosapps/taskmgr/graph.cpp index 06bba82fb2d..cdd31a42386 100644 --- a/rosapps/taskmgr/graph.cpp +++ b/rosapps/taskmgr/graph.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "graph.h" #include "font.h" @@ -160,7 +173,11 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) // 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. @@ -215,6 +232,15 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) 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 // @@ -235,6 +261,8 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) // for (i=0; i 5000) nBarsUsed = 5000; + FillSolidRect(hDC, &rcBarLeft, BRIGHT_GREEN); FillSolidRect(hDC, &rcBarRight, BRIGHT_GREEN); @@ -250,7 +278,7 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) // rcBarLeft.bottom--; rcBarRight.bottom--; - if (nBarsUsedKernel % 2) + if (nBarsUsedKernel && nBarsUsedKernel % 2) { rcBarLeft.top -= 2; rcBarLeft.bottom -= 2; @@ -271,6 +299,8 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) } for (i=0; i 5000) nBarsUsedKernel = 5000; + FillSolidRect(hDC, &rcBarLeft, RED); FillSolidRect(hDC, &rcBarRight, RED); @@ -336,6 +366,12 @@ void Graph_DrawMemUsageGraph(HDC hDC, HWND hWnd) 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 // diff --git a/rosapps/taskmgr/optnmenu.cpp b/rosapps/taskmgr/optnmenu.cpp index d44876e0932..b554d8bdf09 100644 --- a/rosapps/taskmgr/optnmenu.cpp +++ b/rosapps/taskmgr/optnmenu.cpp @@ -26,7 +26,20 @@ // Menu item handlers for the options menu. // +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "optnmenu.h" #include "ProcessPage.h" diff --git a/rosapps/taskmgr/perfdata.cpp b/rosapps/taskmgr/perfdata.cpp index a6954ea4b6a..929fcf6664d 100644 --- a/rosapps/taskmgr/perfdata.cpp +++ b/rosapps/taskmgr/perfdata.cpp @@ -20,8 +20,21 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" -#include "TASKMGR.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "TaskMgr.h" #include "perfdata.h" PROCNTQSI NtQuerySystemInformation = NULL; diff --git a/rosapps/taskmgr/priority.cpp b/rosapps/taskmgr/priority.cpp index b9eed6636e2..140114ce00a 100644 --- a/rosapps/taskmgr/priority.cpp +++ b/rosapps/taskmgr/priority.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "priority.h" #include "ProcessPage.h" diff --git a/rosapps/taskmgr/proclist.cpp b/rosapps/taskmgr/proclist.cpp index b5faff96a72..a2493ad071c 100644 --- a/rosapps/taskmgr/proclist.cpp +++ b/rosapps/taskmgr/proclist.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "ProcessPage.h" #include "proclist.h" diff --git a/rosapps/taskmgr/resource.h b/rosapps/taskmgr/resource.h index 0260e7bb813..a61ce7365e1 100644 --- a/rosapps/taskmgr/resource.h +++ b/rosapps/taskmgr/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. -// Used by TASKMGR.rc +// Used by TaskMgr.rc // #define IDD_TASKMGR_DIALOG 102 #define IDD_ABOUTBOX 103 @@ -117,7 +117,23 @@ #define IDC_MEM_USAGE_GRAPH 1048 #define IDC_CPU30 1049 #define IDC_MEM_USAGE_HISTORY_GRAPH 1049 -#define IDC_CPU31 1050 +#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 diff --git a/rosapps/taskmgr/run.cpp b/rosapps/taskmgr/run.cpp index ca6f00e8692..c536d9e535a 100644 --- a/rosapps/taskmgr/run.cpp +++ b/rosapps/taskmgr/run.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "run.h" diff --git a/rosapps/taskmgr/trayicon.cpp b/rosapps/taskmgr/trayicon.cpp index dcbc66fedfc..3682e1a87f8 100644 --- a/rosapps/taskmgr/trayicon.cpp +++ b/rosapps/taskmgr/trayicon.cpp @@ -20,7 +20,20 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef _MSC_VER #include "stdafx.h" +#else +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include "taskmgr.h" #include "trayicon.h" #include "perfdata.h"