static DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) { ULONG OldProcessorUsage = 0; ULONG OldProcessCount = 0; WCHAR wszCPU_Usage[255]; WCHAR wszProcesses[255]; LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR)); LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR)); /* Create the event */ hProcessPageEvent = CreateEventW(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hProcessPageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { WCHAR text[256]; /* Reset our event */ ResetEvent(hProcessPageEvent); if (SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount()) SendMessageW(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL); if (IsWindowVisible(hProcessPage)) InvalidateRect(hProcessPageListCtrl, NULL, FALSE); if (OldProcessorUsage != PerfDataGetProcessorUsage()) { OldProcessorUsage = PerfDataGetProcessorUsage(); wsprintfW(text, wszCPU_Usage, OldProcessorUsage); SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text); } if (OldProcessCount != PerfDataGetProcessCount()) { OldProcessCount = PerfDataGetProcessCount(); wsprintfW(text, wszProcesses, OldProcessCount); SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text); } } } return 0; }
static DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) { ULONG OldProcessorUsage = 0; ULONG OldProcessCount = 0; /* Create the event */ hProcessPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hProcessPageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { TCHAR text[260]; /* Reset our event */ ResetEvent(hProcessPageEvent); if ((ULONG)SendMessage(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount()) SendMessage(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL); if (IsWindowVisible(hProcessPage)) InvalidateRect(hProcessPageListCtrl, NULL, FALSE); if (OldProcessorUsage != PerfDataGetProcessorUsage()) { OldProcessorUsage = PerfDataGetProcessorUsage(); wsprintf(text, _T("CPU Usage: %3d%%"), OldProcessorUsage); SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); } if (OldProcessCount != PerfDataGetProcessCount()) { OldProcessCount = PerfDataGetProcessCount(); wsprintf(text, _T("Processes: %d"), OldProcessCount); SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); } } } return 0; }
BOOL TrayIcon_ShellUpdateTrayIcon(void) { NOTIFYICONDATAW nid; HICON hIcon = NULL; BOOL bRetVal; WCHAR wszCPU_Usage[255]; LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR)); memset(&nid, 0, sizeof(NOTIFYICONDATAW)); hIcon = TrayIcon_GetProcessorUsageIcon(); nid.cbSize = sizeof(NOTIFYICONDATAW); nid.hWnd = hMainWnd; nid.uID = 0; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_ONTRAYICON; nid.hIcon = hIcon; wsprintfW(nid.szTip, wszCPU_Usage, PerfDataGetProcessorUsage()); bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid); if (hIcon) DestroyIcon(hIcon); return bRetVal; }
static void TaskManager_OnExitMenuLoop(HWND hWnd) { RECT rc; int nParts[3]; WCHAR text[256]; WCHAR wszCPU_Usage[255]; WCHAR wszProcesses[255]; LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR)); LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR)); bInMenuLoop = FALSE; /* Update the status bar pane sizes */ GetClientRect(hWnd, &rc); nParts[0] = 100; nParts[1] = 210; nParts[2] = rc.right; SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts); SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0); wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage()); SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text); wsprintfW(text, wszProcesses, PerfDataGetProcessCount()); SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text); }
BOOL TrayIcon_ShellUpdateTrayIcon(void) { NOTIFYICONDATA nid; HICON hIcon = NULL; BOOL bRetVal; memset(&nid, 0, sizeof(NOTIFYICONDATA)); hIcon = TrayIcon_GetProcessorUsageIcon(); nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = hMainWnd; nid.uID = 0; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_ONTRAYICON; nid.hIcon = hIcon; wsprintf(nid.szTip, _T("CPU Usage: %d%%"), PerfDataGetProcessorUsage()); bRetVal = Shell_NotifyIcon(NIM_MODIFY, &nid); if (hIcon) DestroyIcon(hIcon); return bRetVal; }
BOOL TrayIcon_ShellUpdateTrayIcon(void) { NOTIFYICONDATAW nid; HICON hIcon = NULL; BOOL bRetVal; WCHAR wszCPU_Usage[] = {'C','P','U',' ','U','s','a','g','e',':',' ','%','d','%','%',0}; memset(&nid, 0, sizeof(NOTIFYICONDATAW)); hIcon = TrayIcon_GetProcessorUsageIcon(); nid.cbSize = sizeof(NOTIFYICONDATAW); nid.hWnd = hMainWnd; nid.uID = 0; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_ONTRAYICON; nid.hIcon = hIcon; wsprintfW(nid.szTip, wszCPU_Usage, PerfDataGetProcessorUsage()); bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid); if (hIcon) DestroyIcon(hIcon); return bRetVal; }
DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) { ULONG OldProcessorUsage = 0; ULONG OldProcessCount = 0; WCHAR szCpuUsage[256], szProcesses[256]; MSG msg; LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256); LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256); while (1) { /* Wait for an the event or application close */ if (GetMessage(&msg, NULL, 0, 0) <= 0) return 0; if (msg.message == WM_TIMER) { WCHAR text[260]; UpdateProcesses(); if (IsWindowVisible(hProcessPage)) InvalidateRect(hProcessPageListCtrl, NULL, FALSE); if (OldProcessorUsage != PerfDataGetProcessorUsage()) { OldProcessorUsage = PerfDataGetProcessorUsage(); wsprintfW(text, szCpuUsage, OldProcessorUsage); SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); } if (OldProcessCount != PerfDataGetProcessCount()) { OldProcessCount = PerfDataGetProcessCount(); wsprintfW(text, szProcesses, OldProcessCount); SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); } } } return 0; }
void TaskManager_OnExitMenuLoop(HWND hWnd) { RECT rc; int nParts[3]; WCHAR text[260]; WCHAR szCpuUsage[256], szProcesses[256]; LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256); LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256); bInMenuLoop = FALSE; /* Update the status bar pane sizes */ GetClientRect(hWnd, &rc); nParts[0] = STATUS_SIZE1; nParts[1] = STATUS_SIZE2; nParts[2] = rc.right; SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM) (LPINT) nParts); SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)L""); wsprintfW(text, szCpuUsage, PerfDataGetProcessorUsage()); SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); wsprintfW(text, szProcesses, PerfDataGetProcessCount()); SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); }
static DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) { ULONG CommitChargeTotal; ULONG CommitChargeLimit; ULONG CommitChargePeak; ULONG KernelMemoryTotal; ULONG KernelMemoryPaged; ULONG KernelMemoryNonPaged; ULONG PhysicalMemoryTotal; ULONG PhysicalMemoryAvailable; ULONG PhysicalMemorySystemCache; ULONG TotalHandles; ULONG TotalThreads; ULONG TotalProcesses; TCHAR Text[260]; /* Create the event */ hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hPerformancePageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { ULONG CpuUsage; ULONG CpuKernelUsage; int nBarsUsed1; int nBarsUsed2; /* Reset our event */ ResetEvent(hPerformancePageEvent); /* * Update the commit charge info */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); CommitChargePeak = PerfDataGetCommitChargePeakK(); _ultoa(CommitChargeTotal, Text, 10); SetWindowText(hPerformancePageCommitChargeTotalEdit, Text); _ultoa(CommitChargeLimit, Text, 10); SetWindowText(hPerformancePageCommitChargeLimitEdit, Text); _ultoa(CommitChargePeak, Text, 10); SetWindowText(hPerformancePageCommitChargePeakEdit, Text); wsprintf(Text, _T("Mem Usage: %dK / %dK"), CommitChargeTotal, CommitChargeLimit); SendMessage(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text); /* * Update the kernel memory info */ KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); _ultoa(KernelMemoryTotal, Text, 10); SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text); _ultoa(KernelMemoryPaged, Text, 10); SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text); _ultoa(KernelMemoryNonPaged, Text, 10); SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text); /* * Update the physical memory info */ PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); _ultoa(PhysicalMemoryTotal, Text, 10); SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text); _ultoa(PhysicalMemoryAvailable, Text, 10); SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text); _ultoa(PhysicalMemorySystemCache, Text, 10); SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text); /* * Update the totals info */ TotalHandles = PerfDataGetSystemHandleCount(); TotalThreads = PerfDataGetTotalThreadCount(); TotalProcesses = PerfDataGetProcessCount(); _ultoa(TotalHandles, Text, 10); SetWindowText(hPerformancePageTotalsHandleCountEdit, Text); _ultoa(TotalThreads, Text, 10); SetWindowText(hPerformancePageTotalsThreadCountEdit, Text); _ultoa(TotalProcesses, Text, 10); SetWindowText(hPerformancePageTotalsProcessCountEdit, Text); /* * Redraw the graphs */ InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); CpuKernelUsage = PerfDataGetProcessorSystemUsage(); /* * Get the memory usage */ CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK(); CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } return 0; }
static HICON TrayIcon_GetProcessorUsageIcon(void) { HICON hTrayIcon = NULL; HDC hScreenDC = NULL; HDC hDC = NULL; HBITMAP hBitmap = NULL; HBITMAP hOldBitmap; HBITMAP hBitmapMask = NULL; ICONINFO iconInfo; ULONG ProcessorUsage; int nLinesToDraw; HBRUSH hBitmapBrush = NULL; RECT rc; /* * Get a handle to the screen DC */ hScreenDC = GetDC(NULL); if (!hScreenDC) goto done; /* * Create our own DC from it */ hDC = CreateCompatibleDC(hScreenDC); if (!hDC) goto done; /* * Load the bitmaps */ hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYICON)); hBitmapMask = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYMASK)); if (!hBitmap || !hBitmapMask) goto done; hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0)); if (!hBitmapBrush) goto done; /* * Select the bitmap into our device context * so we can draw on it. */ hOldBitmap = SelectObject(hDC, hBitmap); /* * Get the cpu usage */ ProcessorUsage = PerfDataGetProcessorUsage(); /* * Calculate how many lines to draw * since we have 11 rows of space * to draw the cpu usage instead of * just having 10. */ nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11; rc.left = 3; rc.top = 12 - nLinesToDraw; rc.right = 13; rc.bottom = 13; /* * Now draw the cpu usage */ if (nLinesToDraw) FillRect(hDC, &rc, hBitmapBrush); /* * Now that we are done drawing put the * old bitmap back. */ SelectObject(hDC, hOldBitmap); iconInfo.fIcon = TRUE; iconInfo.xHotspot = 0; iconInfo.yHotspot = 0; iconInfo.hbmMask = hBitmapMask; iconInfo.hbmColor = hBitmap; hTrayIcon = CreateIconIndirect(&iconInfo); done: /* * Cleanup */ if (hScreenDC) ReleaseDC(NULL, hScreenDC); if (hDC) DeleteDC(hDC); if (hBitmapBrush) DeleteObject(hBitmapBrush); if (hBitmap) DeleteObject(hBitmap); if (hBitmapMask) DeleteObject(hBitmapMask); /* * Return the newly created tray icon (if successful) */ return hTrayIcon; }
DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) { ULONGLONG CommitChargeTotal; ULONGLONG CommitChargeLimit; ULONGLONG CommitChargePeak; ULONG CpuUsage; ULONG CpuKernelUsage; ULONGLONG KernelMemoryTotal; ULONGLONG KernelMemoryPaged; ULONGLONG KernelMemoryNonPaged; ULONGLONG PhysicalMemoryTotal; ULONGLONG PhysicalMemoryAvailable; ULONGLONG PhysicalMemorySystemCache; ULONG TotalHandles; ULONG TotalThreads; ULONG TotalProcesses; WCHAR Text[260]; WCHAR szMemUsage[256]; MSG msg; LoadStringW(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256); while (1) { int nBarsUsed1; int nBarsUsed2; WCHAR szChargeTotalFormat[256]; WCHAR szChargeLimitFormat[256]; /* Wait for an the event or application close */ if (GetMessage(&msg, NULL, 0, 0) <= 0) return 0; if (msg.message == WM_TIMER) { /* * Update the commit charge info */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); CommitChargePeak = PerfDataGetCommitChargePeakK(); _ultow(CommitChargeTotal, Text, 10); SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text); _ultow(CommitChargeLimit, Text, 10); SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text); _ultow(CommitChargePeak, Text, 10); SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text); StrFormatByteSizeW(CommitChargeTotal * 1024, szChargeTotalFormat, sizeof(szChargeTotalFormat)); StrFormatByteSizeW(CommitChargeLimit * 1024, szChargeLimitFormat, sizeof(szChargeLimitFormat)); wsprintfW(Text, szMemUsage, szChargeTotalFormat, szChargeLimitFormat, (CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0)); SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text); /* * Update the kernel memory info */ KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); _ultow(KernelMemoryTotal, Text, 10); SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text); _ultow(KernelMemoryPaged, Text, 10); SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text); _ultow(KernelMemoryNonPaged, Text, 10); SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text); /* * Update the physical memory info */ PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); _ultow(PhysicalMemoryTotal, Text, 10); SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text); _ultow(PhysicalMemoryAvailable, Text, 10); SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text); _ultow(PhysicalMemorySystemCache, Text, 10); SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text); /* * Update the totals info */ TotalHandles = PerfDataGetSystemHandleCount(); TotalThreads = PerfDataGetTotalThreadCount(); TotalProcesses = PerfDataGetProcessCount(); _ultow(TotalHandles, Text, 10); SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text); _ultow(TotalThreads, Text, 10); SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text); _ultow(TotalProcesses, Text, 10); SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text); /* * Redraw the graphs */ InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); if (CpuUsage <= 0 ) CpuUsage = 0; if (CpuUsage > 100) CpuUsage = 100; if (TaskManagerSettings.ShowKernelTimes) { CpuKernelUsage = PerfDataGetProcessorSystemUsage(); if (CpuKernelUsage <= 0) CpuKernelUsage = 0; if (CpuKernelUsage > 100) CpuKernelUsage = 100; } else { CpuKernelUsage = 0; } /* * Get the memory usage */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } return 0; }
void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd) { RECT rcClient; RECT rcBarLeft; RECT rcBarRight; RECT rcText; COLORREF crPrevForeground; WCHAR Text[260]; HFONT hOldFont; ULONG CpuUsage; ULONG CpuKernelUsage; int nBars; int nBarsUsed; /* Bottom bars that are "used", i.e. are bright green, representing used cpu time */ int nBarsUsedKernel; /* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */ int nBarsFree; /* Top bars that are "unused", i.e. are dark green, representing free cpu time */ int i; /* * Get the client area rectangle */ GetClientRect(hWnd, &rcClient); /* * Fill it with blackness */ FillSolidRect(hDC, &rcClient, RGB(0, 0, 0)); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); if (CpuUsage <= 0) CpuUsage = 0; if (CpuUsage > 100) CpuUsage = 100; wsprintfW(Text, L"%d%%", (int)CpuUsage); /* * Draw the font text onto the graph */ rcText = rcClient; InflateRect(&rcText, -2, -2); crPrevForeground = SetTextColor(hDC, RGB(0, 255, 0)); hOldFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT)); DrawTextW(hDC, Text, -1, &rcText, DT_BOTTOM | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE); SelectObject(hDC, hOldFont); SetTextColor(hDC, crPrevForeground); /* * Now we have to draw the graph * So first find out how many bars we can fit */ nBars = ((rcClient.bottom - rcClient.top) - 25) / 3; nBarsUsed = (nBars * CpuUsage) / 100; if ((CpuUsage) && (nBarsUsed == 0)) { nBarsUsed = 1; } nBarsFree = nBars - (nlastBarsUsed>nBarsUsed ? nlastBarsUsed : nBarsUsed); if (TaskManagerSettings.ShowKernelTimes) { CpuKernelUsage = PerfDataGetProcessorSystemUsage(); if (CpuKernelUsage <= 0) CpuKernelUsage = 0; if (CpuKernelUsage >= 100) CpuKernelUsage = 100; nBarsUsedKernel = (nBars * CpuKernelUsage) / 100; } else { nBarsUsedKernel = 0; } /* * Now draw the bar graph */ rcBarLeft.left = ((rcClient.right - rcClient.left) - 33) / 2; rcBarLeft.right = rcBarLeft.left + 16; rcBarRight.left = rcBarLeft.left + 17; rcBarRight.right = rcBarLeft.right + 17; rcBarLeft.top = rcBarRight.top = 5; rcBarLeft.bottom = rcBarRight.bottom = 7; if (nBarsUsed < 0) nBarsUsed = 0; if (nBarsUsed > nBars) nBarsUsed = nBars; if (nBarsFree < 0) nBarsFree = 0; if (nBarsFree > nBars) nBarsFree = nBars; if (nBarsUsedKernel < 0) nBarsUsedKernel = 0; if (nBarsUsedKernel > nBars) nBarsUsedKernel = nBars; /* * Draw the "free" bars */ for (i=0; i<nBarsFree; i++) { FillSolidRect(hDC, &rcBarLeft, DARK_GREEN); FillSolidRect(hDC, &rcBarRight, DARK_GREEN); rcBarLeft.top += 3; rcBarLeft.bottom += 3; rcBarRight.top += 3; rcBarRight.bottom += 3; } /* * Draw the last "used" bars */ if ((nlastBarsUsed - nBarsUsed) > 0) { for (i=0; i< (nlastBarsUsed - nBarsUsed); i++) { if (nlastBarsUsed > 5000) nlastBarsUsed = 5000; FillSolidRect(hDC, &rcBarLeft, MEDIUM_GREEN); FillSolidRect(hDC, &rcBarRight, MEDIUM_GREEN); rcBarLeft.top += 3; rcBarLeft.bottom += 3; rcBarRight.top += 3; rcBarRight.bottom += 3; } } nlastBarsUsed = nBarsUsed; /* * Draw the "used" bars */ for (i=0; i<nBarsUsed; i++) { if (nBarsUsed > 5000) nBarsUsed = 5000; FillSolidRect(hDC, &rcBarLeft, BRIGHT_GREEN); FillSolidRect(hDC, &rcBarRight, BRIGHT_GREEN); rcBarLeft.top += 3; rcBarLeft.bottom += 3; rcBarRight.top += 3; rcBarRight.bottom += 3; } /* * Draw the "used" kernel bars */ rcBarLeft.top -=3; rcBarLeft.bottom -=3; rcBarRight.top -=3; rcBarRight.bottom -=3; for (i=0; i<nBarsUsedKernel; i++) { FillSolidRect(hDC, &rcBarLeft, RED); FillSolidRect(hDC, &rcBarRight, RED); rcBarLeft.top -=3; rcBarLeft.bottom -=3; rcBarRight.top -=3; rcBarRight.bottom -=3; } SelectObject(hDC, hOldFont); }
static DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) { ULONG CommitChargeTotal; ULONG CommitChargeLimit; ULONG CommitChargePeak; ULONG KernelMemoryTotal; ULONG KernelMemoryPaged; ULONG KernelMemoryNonPaged; ULONG PhysicalMemoryTotal; ULONG PhysicalMemoryAvailable; ULONG PhysicalMemorySystemCache; ULONG TotalHandles; ULONG TotalThreads; ULONG TotalProcesses; WCHAR Text[256]; static const WCHAR wszFormatDigit[] = {'%','u',0}; WCHAR wszMemUsage[255]; LoadStringW(hInst, IDS_STATUS_BAR_MEMORY_USAGE, wszMemUsage, sizeof(wszMemUsage)/sizeof(WCHAR)); /* Create the event */ hPerformancePageEvent = CreateEventW(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hPerformancePageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { ULONG CpuUsage; ULONG CpuKernelUsage; int nBarsUsed1, nBarsUsed2; DWORD_PTR args[2]; /* Reset our event */ ResetEvent(hPerformancePageEvent); /* * Update the commit charge info */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); CommitChargePeak = PerfDataGetCommitChargePeakK(); wsprintfW(Text, wszFormatDigit, CommitChargeTotal); SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text); wsprintfW(Text, wszFormatDigit, CommitChargeLimit); SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text); wsprintfW(Text, wszFormatDigit, CommitChargePeak); SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text); args[0] = CommitChargeTotal; args[1] = CommitChargeLimit; FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, wszMemUsage, 0, 0, Text, sizeof(Text)/sizeof(*Text), (__ms_va_list*)args); SendMessageW(hStatusWnd, SB_SETTEXTW, 2, (LPARAM)Text); /* * Update the kernel memory info */ KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); wsprintfW(Text, wszFormatDigit, KernelMemoryTotal); SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text); wsprintfW(Text, wszFormatDigit, KernelMemoryPaged); SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text); wsprintfW(Text, wszFormatDigit, KernelMemoryNonPaged); SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text); /* * Update the physical memory info */ PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); wsprintfW(Text, wszFormatDigit, PhysicalMemoryTotal); SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text); wsprintfW(Text, wszFormatDigit, PhysicalMemoryAvailable); SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text); wsprintfW(Text, wszFormatDigit, PhysicalMemorySystemCache); SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text); /* * Update the totals info */ TotalHandles = PerfDataGetSystemHandleCount(); TotalThreads = PerfDataGetTotalThreadCount(); TotalProcesses = PerfDataGetProcessCount(); wsprintfW(Text, wszFormatDigit, TotalHandles); SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text); wsprintfW(Text, wszFormatDigit, TotalThreads); SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text); wsprintfW(Text, wszFormatDigit, TotalProcesses); SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text); /* * Redraw the graphs */ InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); CpuKernelUsage = PerfDataGetProcessorSystemUsage(); /* * Get the memory usage */ CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK(); CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } return 0; }