ToolStatus: reorganised code, bug fixes, drawing code fixes

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5250 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
dmex
2012-12-27 08:57:05 +00:00
parent 368586d222
commit d6caec6d5d
8 changed files with 1000 additions and 960 deletions
@@ -165,6 +165,8 @@
<ClCompile Include="main.c" />
<ClCompile Include="btncontrol.c" />
<ClCompile Include="options.c" />
<ClCompile Include="searchfilter.c" />
<ClCompile Include="statusbar.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="btncontrol.h" />
@@ -24,6 +24,12 @@
<ClCompile Include="btncontrol.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="searchfilter.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="statusbar.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
+15 -24
View File
@@ -19,6 +19,9 @@ BOOLEAN InsertButton(
context->DllBase = (HINSTANCE)PluginInstance->DllBase;
context->ImageList = ImageList_Create(18, 18, ILC_COLOR32 | ILC_MASK, 0, 0);
context->WhiteBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
context->BlackBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
// Set the number of images.
ImageList_SetImageCount(context->ImageList, 2);
PhSetImageListBitmap(context->ImageList, 0, context->DllBase, MAKEINTRESOURCE(IDB_SEARCH1));
@@ -73,14 +76,10 @@ VOID DrawInsertedButton(
)
{
HDC hdc;
HBRUSH brush;
hdc = GetWindowDC(WindowHandle);
brush = CreateSolidBrush(RGB(0, 0, 0));
//SetBkMode(hdc, TRANSPARENT);
FillRect(hdc, prect, (HBRUSH)(COLOR_WINDOW+1));
hdc = GetWindowDC(WindowHandle);
FillRect(hdc, prect, nc->WhiteBrush);
if (nc->ImageList)
{
@@ -113,7 +112,6 @@ VOID DrawInsertedButton(
}
}
DeleteObject(brush);
ReleaseDC(WindowHandle, hdc);
}
@@ -175,7 +173,7 @@ LRESULT CALLBACK InsButProc(
}
return FALSE;
case WM_NCPAINT:
{
{
// let the old window procedure draw the borders other non-client bits-and-pieces for us.
CallWindowProc(context->NCAreaWndProc, WindowHandle, uMsg, wParam, lParam);
@@ -183,28 +181,21 @@ LRESULT CALLBACK InsButProc(
GetWindowRect(WindowHandle, &context->rect);
// adjust the coordinates so they start from 0,0
OffsetRect(&context->rect, -context->rect.left, -context->rect.top);
// border - requires the edit control have the WS_EX_STATICEDGE style
// Draw border
{
HDC hdc;
HBRUSH brush;
HDC hdc = GetWindowDC(WindowHandle);
hdc = GetWindowDC(WindowHandle);
brush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &context->rect, (HBRUSH)(COLOR_WINDOW+1));
// Draw a single line around the outside
FrameRect(hdc, &context->rect, brush);
DeleteObject(brush);
FillRect(hdc, &context->rect, context->WhiteBrush);
FrameRect(hdc, &context->rect, context->BlackBrush);
ReleaseDC(WindowHandle, hdc);
}
// work out where to draw the button
GetButtonRect(context, &context->rect);
DrawInsertedButton(WindowHandle, context, &context->rect);
DrawInsertedButton(WindowHandle, context, &context->rect);
}
return FALSE;
case WM_NCHITTEST:
+7 -4
View File
@@ -5,6 +5,13 @@
typedef struct _NC_CONTROL
{
HWND ParentWindow;
HINSTANCE DllBase;
WNDPROC NCAreaWndProc;
HIMAGELIST ImageList;
HBRUSH WhiteBrush;
HBRUSH BlackBrush;
UINT uCmdId; // sent in a WM_COMMAND message
UINT uState;
BOOLEAN IsButtonDown; // is the button up/down?
@@ -22,10 +29,6 @@ typedef struct _NC_CONTROL
RECT rect;
RECT oldrect;
RECT* prect;
HWND ParentWindow;
HIMAGELIST ImageList;
HINSTANCE DllBase;
WNDPROC NCAreaWndProc;
} NC_CONTROL;
BOOLEAN InsertButton(
File diff suppressed because it is too large Load Diff
+274
View File
@@ -0,0 +1,274 @@
/*
* Process Hacker ToolStatus -
* search filter callbacks
*
* Copyright (C) 2010-2012 wj32
* Copyright (C) 2011-2012 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "toolstatus.h"
BOOLEAN WordMatch(
__in PPH_STRINGREF Text,
__in PPH_STRINGREF Search,
__in BOOLEAN IgnoreCase
)
{
PH_STRINGREF part;
PH_STRINGREF remainingPart;
remainingPart = *Search;
while (remainingPart.Length != 0)
{
PhSplitStringRefAtChar(&remainingPart, ' ', &part, &remainingPart);
if (part.Length != 0)
{
if (PhFindStringInStringRef(Text, &part, IgnoreCase) != -1)
return TRUE;
}
}
return FALSE;
}
BOOLEAN ProcessTreeFilterCallback(
__in PPH_TREENEW_NODE Node,
__in_opt PVOID Context
)
{
HWND textboxHandle = (HWND)Context;
PPH_PROCESS_NODE processNode = (PPH_PROCESS_NODE)Node;
// Check if the textbox actually contains anything.
if (GetWindowTextLength(textboxHandle) > 0)
{
BOOLEAN itemFound = FALSE;
PH_STRINGREF pidStringRef;
PPH_STRING textboxText;
textboxText = PhGetWindowText(textboxHandle);
if (textboxText)
{
PhInitializeStringRef(&pidStringRef, processNode->ProcessItem->ProcessIdString);
// Search process names
if (processNode->ProcessItem->ProcessName)
{
if (WordMatch(&processNode->ProcessItem->ProcessName->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
// Search process company
if (processNode->ProcessItem->VersionInfo.CompanyName)
{
if (WordMatch(&processNode->ProcessItem->VersionInfo.CompanyName->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
// Search process descriptions
if (processNode->ProcessItem->VersionInfo.FileDescription)
{
if (WordMatch(&processNode->ProcessItem->VersionInfo.FileDescription->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
// Search process PIDs
if (WordMatch(&pidStringRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
PhDereferenceObject(textboxText);
}
return itemFound;
}
// show all items
return TRUE;
}
BOOLEAN ServiceTreeFilterCallback(
__in PPH_TREENEW_NODE Node,
__in_opt PVOID Context
)
{
HWND textboxHandle = (HWND)Context;
PPH_SERVICE_NODE serviceNode = (PPH_SERVICE_NODE)Node;
// Check if the textbox actually contains anything.
if (GetWindowTextLength(textboxHandle) > 0)
{
BOOLEAN itemFound = FALSE;
PH_STRINGREF pidStringRef;
PPH_STRING textboxText;
textboxText = PhGetWindowText(textboxHandle);
if (textboxText)
{
PhInitializeStringRef(&pidStringRef, serviceNode->ServiceItem->ProcessIdString);
// Search service name.
if (serviceNode->ServiceItem->Name)
{
if (WordMatch(&serviceNode->ServiceItem->Name->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
// Search service display name.
if (serviceNode->ServiceItem->DisplayName)
{
if (WordMatch(&serviceNode->ServiceItem->DisplayName->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
// Search process PIDs.
if (WordMatch(&pidStringRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
PhDereferenceObject(textboxText);
}
return itemFound;
}
// show all items
return TRUE;
}
BOOLEAN NetworkTreeFilterCallback(
__in PPH_TREENEW_NODE Node,
__in_opt PVOID Context
)
{
HWND textboxHandle = (HWND)Context;
PPH_NETWORK_NODE networkNode = (PPH_NETWORK_NODE)Node;
// Check if the textbox actually contains anything.
if (GetWindowTextLength(textboxHandle) > 0)
{
PH_STRINGREF pidStringRef;
BOOLEAN itemFound = FALSE;
PPH_STRING textboxText;
WCHAR pidString[32];
textboxText = PhGetWindowText(textboxHandle);
if (textboxText)
{
// Search PID
PhPrintUInt32(pidString, (ULONG)networkNode->NetworkItem->ProcessId);
PhInitializeStringRef(&pidStringRef, pidString);
// Search network process PIDs
if (WordMatch(&pidStringRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
// Search connection process name
if (networkNode->NetworkItem->ProcessName)
{
if (WordMatch(&networkNode->NetworkItem->ProcessName->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
// Search connection local IP address
if (networkNode->NetworkItem->LocalAddressString)
{
PH_STRINGREF localAddressRef;
PhInitializeStringRef(&localAddressRef, networkNode->NetworkItem->LocalAddressString);
if (WordMatch(&localAddressRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
if (networkNode->NetworkItem->LocalPortString)
{
PH_STRINGREF localPortRef;
PhInitializeStringRef(&localPortRef, networkNode->NetworkItem->LocalPortString);
if (WordMatch(&localPortRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
if (networkNode->NetworkItem->RemoteAddressString)
{
PH_STRINGREF remoteAddressRef;
PhInitializeStringRef(&remoteAddressRef, networkNode->NetworkItem->RemoteAddressString);
if (WordMatch(&remoteAddressRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
if (networkNode->NetworkItem->RemotePortString)
{
PH_STRINGREF remotePortRef;
PhInitializeStringRef(&remotePortRef, networkNode->NetworkItem->RemotePortString);
if (WordMatch(&remotePortRef, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
if (networkNode->NetworkItem->RemoteHostString)
{
if (WordMatch(&networkNode->NetworkItem->RemoteHostString->sr, &textboxText->sr, TRUE))
{
itemFound = TRUE;
}
}
PhDereferenceObject(textboxText);
}
return itemFound;
}
// Textbox empty, allow all items to be shown.
return TRUE;
}
+331
View File
@@ -0,0 +1,331 @@
/*
* Process Hacker ToolStatus -
* statusbar main
*
* Copyright (C) 2010-2012 wj32
* Copyright (C) 2011-2012 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "toolstatus.h"
VOID ShowStatusMenu(
__in PPOINT Point
)
{
HMENU menu;
HMENU subMenu;
ULONG i;
ULONG id;
ULONG bit;
menu = LoadMenu(
(HINSTANCE)PluginInstance->DllBase,
MAKEINTRESOURCE(IDR_STATUS)
);
subMenu = GetSubMenu(menu, 0);
// Check the enabled items.
for (i = STATUS_MINIMUM; i != STATUS_MAXIMUM; i <<= 1)
{
if (StatusMask & i)
{
switch (i)
{
case STATUS_CPUUSAGE:
id = ID_STATUS_CPUUSAGE;
break;
case STATUS_COMMIT:
id = ID_STATUS_COMMITCHARGE;
break;
case STATUS_PHYSICAL:
id = ID_STATUS_PHYSICALMEMORY;
break;
case STATUS_NUMBEROFPROCESSES:
id = ID_STATUS_NUMBEROFPROCESSES;
break;
case STATUS_NUMBEROFTHREADS:
id = ID_STATUS_NUMBEROFTHREADS;
break;
case STATUS_NUMBEROFHANDLES:
id = ID_STATUS_NUMBEROFHANDLES;
break;
case STATUS_IOREADOTHER:
id = ID_STATUS_IO_RO;
break;
case STATUS_IOWRITE:
id = ID_STATUS_IO_W;
break;
case STATUS_MAXCPUPROCESS:
id = ID_STATUS_MAX_CPU_PROCESS;
break;
case STATUS_MAXIOPROCESS:
id = ID_STATUS_MAX_IO_PROCESS;
break;
}
CheckMenuItem(subMenu, id, MF_CHECKED);
}
}
id = (ULONG)TrackPopupMenu(
subMenu,
TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
Point->x,
Point->y,
0,
PhMainWndHandle,
NULL
);
DestroyMenu(menu);
switch (id)
{
case ID_STATUS_CPUUSAGE:
bit = STATUS_CPUUSAGE;
break;
case ID_STATUS_COMMITCHARGE:
bit = STATUS_COMMIT;
break;
case ID_STATUS_PHYSICALMEMORY:
bit = STATUS_PHYSICAL;
break;
case ID_STATUS_NUMBEROFPROCESSES:
bit = STATUS_NUMBEROFPROCESSES;
break;
case ID_STATUS_NUMBEROFTHREADS:
bit = STATUS_NUMBEROFTHREADS;
break;
case ID_STATUS_NUMBEROFHANDLES:
bit = STATUS_NUMBEROFHANDLES;
break;
case ID_STATUS_IO_RO:
bit = STATUS_IOREADOTHER;
break;
case ID_STATUS_IO_W:
bit = STATUS_IOWRITE;
break;
case ID_STATUS_MAX_CPU_PROCESS:
bit = STATUS_MAXCPUPROCESS;
break;
case ID_STATUS_MAX_IO_PROCESS:
bit = STATUS_MAXIOPROCESS;
break;
default:
return;
}
StatusMask ^= bit;
PhSetIntegerSetting(L"ProcessHacker.ToolStatus.StatusMask", StatusMask);
UpdateStatusBar();
}
VOID UpdateStatusBar(
VOID
)
{
static ULONG lastTickCount = 0;
PPH_STRING text[STATUS_COUNT];
ULONG widths[STATUS_COUNT];
ULONG i;
ULONG index;
ULONG count;
HDC hdc;
PH_PLUGIN_SYSTEM_STATISTICS statistics;
BOOLEAN resetMaxWidths = FALSE;
if (ProcessesUpdatedCount < 2)
return;
if (!(StatusMask & (STATUS_MAXIMUM - 1)))
{
// The status bar doesn't cope well with 0 parts.
widths[0] = -1;
SendMessage(StatusBarHandle, SB_SETPARTS, 1, (LPARAM)widths);
SendMessage(StatusBarHandle, SB_SETTEXT, 0, (LPARAM)L"");
return;
}
PhPluginGetSystemStatistics(&statistics);
hdc = GetDC(StatusBarHandle);
SelectObject(hdc, (HFONT)SendMessage(StatusBarHandle, WM_GETFONT, 0, 0));
// Reset max. widths for Max. CPU Process and Max. I/O Process parts once in a while.
{
ULONG tickCount;
tickCount = GetTickCount();
if (tickCount - lastTickCount >= 10000)
{
resetMaxWidths = TRUE;
lastTickCount = tickCount;
}
}
count = 0;
index = 0;
for (i = STATUS_MINIMUM; i != STATUS_MAXIMUM; i <<= 1)
{
if (StatusMask & i)
{
SIZE size;
PPH_PROCESS_ITEM processItem;
ULONG width;
switch (i)
{
case STATUS_CPUUSAGE:
text[count] = PhFormatString(L"CPU Usage: %.2f%%", (statistics.CpuKernelUsage + statistics.CpuUserUsage) * 100);
break;
case STATUS_COMMIT:
text[count] = PhFormatString(L"Commit Charge: %.2f%%",
(FLOAT)statistics.CommitPages * 100 / statistics.Performance->CommitLimit);
break;
case STATUS_PHYSICAL:
text[count] = PhFormatString(L"Physical Memory: %.2f%%",
(FLOAT)statistics.PhysicalPages * 100 / PhSystemBasicInformation.NumberOfPhysicalPages);
break;
case STATUS_NUMBEROFPROCESSES:
text[count] = PhConcatStrings2(L"Processes: ",
PhaFormatUInt64(statistics.NumberOfProcesses, TRUE)->Buffer);
break;
case STATUS_NUMBEROFTHREADS:
text[count] = PhConcatStrings2(L"Threads: ",
PhaFormatUInt64(statistics.NumberOfThreads, TRUE)->Buffer);
break;
case STATUS_NUMBEROFHANDLES:
text[count] = PhConcatStrings2(L"Handles: ",
PhaFormatUInt64(statistics.NumberOfHandles, TRUE)->Buffer);
break;
case STATUS_IOREADOTHER:
text[count] = PhConcatStrings2(L"I/O R+O: ", PhaFormatSize(
statistics.IoReadDelta.Delta + statistics.IoOtherDelta.Delta, -1)->Buffer);
break;
case STATUS_IOWRITE:
text[count] = PhConcatStrings2(L"I/O W: ", PhaFormatSize(
statistics.IoWriteDelta.Delta, -1)->Buffer);
break;
case STATUS_MAXCPUPROCESS:
if (statistics.MaxCpuProcessId && (processItem = PhReferenceProcessItem(statistics.MaxCpuProcessId)))
{
if (!PH_IS_FAKE_PROCESS_ID(processItem->ProcessId))
{
text[count] = PhFormatString(
L"%s (%u): %.2f%%",
processItem->ProcessName->Buffer,
(ULONG)processItem->ProcessId,
processItem->CpuUsage * 100
);
}
else
{
text[count] = PhFormatString(
L"%s: %.2f%%",
processItem->ProcessName->Buffer,
processItem->CpuUsage * 100
);
}
PhDereferenceObject(processItem);
}
else
{
text[count] = PhCreateString(L"-");
}
if (resetMaxWidths)
StatusBarMaxWidths[index] = 0;
break;
case STATUS_MAXIOPROCESS:
if (statistics.MaxIoProcessId && (processItem = PhReferenceProcessItem(statistics.MaxIoProcessId)))
{
if (!PH_IS_FAKE_PROCESS_ID(processItem->ProcessId))
{
text[count] = PhFormatString(
L"%s (%u): %s",
processItem->ProcessName->Buffer,
(ULONG)processItem->ProcessId,
PhaFormatSize(processItem->IoReadDelta.Delta + processItem->IoWriteDelta.Delta + processItem->IoOtherDelta.Delta, -1)->Buffer
);
}
else
{
text[count] = PhFormatString(
L"%s: %s",
processItem->ProcessName->Buffer,
PhaFormatSize(processItem->IoReadDelta.Delta + processItem->IoWriteDelta.Delta + processItem->IoOtherDelta.Delta, -1)->Buffer
);
}
PhDereferenceObject(processItem);
}
else
{
text[count] = PhCreateString(L"-");
}
if (resetMaxWidths)
StatusBarMaxWidths[index] = 0;
break;
}
if (!GetTextExtentPoint32(hdc, text[count]->Buffer, (ULONG)text[count]->Length / 2, &size))
size.cx = 200;
if (count != 0)
widths[count] = widths[count - 1];
else
widths[count] = 0;
width = size.cx + 10;
if (width <= StatusBarMaxWidths[index])
width = StatusBarMaxWidths[index];
else
StatusBarMaxWidths[index] = width;
widths[count] += width;
count++;
}
else
{
StatusBarMaxWidths[index] = 0;
}
index++;
}
ReleaseDC(StatusBarHandle, hdc);
SendMessage(StatusBarHandle, SB_SETPARTS, count, (LPARAM)widths);
for (i = 0; i < count; i++)
{
SendMessage(StatusBarHandle, SB_SETTEXT, i, (LPARAM)text[i]->Buffer);
PhDereferenceObject(text[i]);
}
}
+57 -7
View File
@@ -1,3 +1,26 @@
/*
* Process Hacker ToolStatus -
* toolstatus header
*
* Copyright (C) 2010-2012 wj32
* Copyright (C) 2011-2012 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOOLSTATUS_H
#define TOOLSTATUS_H
@@ -11,13 +34,9 @@
#include <phappresource.h>
#include <windowsx.h>
#define TIDC_REFRESH 0
#define TIDC_OPTIONS 1
#define TIDC_FINDOBJ 2
#define TIDC_SYSINFO 3
#define TIDC_FINDWINDOW 4
#define TIDC_FINDWINDOWTHREAD 5
#define TIDC_FINDWINDOWKILL 6
#define TIDC_FINDWINDOW (WM_USER + 1)
#define TIDC_FINDWINDOWTHREAD (WM_USER + 2)
#define TIDC_FINDWINDOWKILL (WM_USER + 3)
#define STATUS_COUNT 10
#define STATUS_MINIMUM 0x1
@@ -46,6 +65,19 @@ BOOLEAN EnableSearch;
TOOLBAR_DISPLAY_STYLE DisplayStyle;
RECT StatusBarRect;
ULONG StatusMask;
ULONG ProcessesUpdatedCount;
ULONG StatusBarMaxWidths[STATUS_COUNT];
HWND StatusBarHandle;
VOID UpdateStatusBar(
VOID
);
VOID ShowStatusMenu(
__in PPOINT Point
);
PPH_PLUGIN PluginInstance;
PH_CALLBACK_REGISTRATION PluginLoadCallbackRegistration;
PH_CALLBACK_REGISTRATION PluginShowOptionsCallbackRegistration;
@@ -61,4 +93,22 @@ INT_PTR CALLBACK OptionsDlgProc(
__in LPARAM lParam
);
BOOLEAN WordMatch(
__in PPH_STRINGREF Text,
__in PPH_STRINGREF Search,
__in BOOLEAN IgnoreCase
);
BOOLEAN ProcessTreeFilterCallback(
__in PPH_TREENEW_NODE Node,
__in_opt PVOID Context
);
BOOLEAN ServiceTreeFilterCallback(
__in PPH_TREENEW_NODE Node,
__in_opt PVOID Context
);
BOOLEAN NetworkTreeFilterCallback(
__in PPH_TREENEW_NODE Node,
__in_opt PVOID Context
);
#endif