33 static HWND PhMipContainerWindow = NULL;
34 static POINT PhMipSourcePoint;
36 static LONG PhMipMaxPinCounts[] =
47 static HWND PhMipLastTrackedWindow;
48 static HWND PhMipLastNcTrackedWindow;
49 static ULONG PhMipRefreshAutomatically;
50 static BOOLEAN PhMipPinned;
52 static HWND PhMipWindow = NULL;
54 static RECT MinimumSize;
57 static WNDPROC SectionControlOldWndProc;
66 _In_opt_ ULONG PinDelayMs,
68 _In_opt_ PWSTR SectionName,
69 _In_opt_ PPOINT SourcePoint
74 if (PinDelayMs && PinCount < 0)
76 PhMipDelayedPinAdjustments[PinType] = PinCount;
82 PhMipDelayedPinAdjustments[PinType] = 0;
94 PhMipSourcePoint = *SourcePoint;
96 if (!PhMipContainerWindow)
100 memset(&wcex, 0,
sizeof(WNDCLASSEX));
101 wcex.cbSize =
sizeof(WNDCLASSEX);
108 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
109 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
112 RegisterClassEx(&wcex);
114 PhMipContainerWindow = CreateWindow(
117 WS_BORDER | WS_THICKFRAME | WS_POPUP,
128 PhMipWindow = CreateDialog(
131 PhMipContainerWindow,
134 ShowWindow(PhMipWindow, SW_SHOW);
146 MinimumSize.left = 0;
148 MinimumSize.right = 210;
149 MinimumSize.bottom = 140;
150 MapDialogRect(PhMipWindow, &MinimumSize);
157 PhMipContainerWindow,
159 windowRectangle.
Left,
161 windowRectangle.
Width,
169 SetWindowPos(PhMipContainerWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
176 if (PhMipContainerWindow)
177 ShowWindow(PhMipContainerWindow, SW_HIDE);
182 SetActiveWindow(PhMipContainerWindow);
226 case WM_EXITSIZEMOVE:
234 ShowWindow(hWnd, SW_HIDE);
235 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, 0);
251 return DefWindowProc(hWnd, uMsg, wParam, lParam);
265 PhMipWindow = hwndDlg;
285 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, result);
292 case WM_CTLCOLORSTATIC:
297 return (INT_PTR)brush;
317 _In_ BOOLEAN Showing,
334 &ProcessesUpdatedRegistration
344 PhMipPinCounts[i] = 0;
346 Button_SetCheck(GetDlgItem(PhMipWindow,
IDC_PIN), BST_UNCHECKED);
352 &ProcessesUpdatedRegistration
355 if (PhMipMessageLoopFilterEntry)
358 PhMipMessageLoopFilterEntry = NULL;
366 for (i = 0; i < SectionList->
Count; i++)
368 section = SectionList->
Items[i];
376 _In_ BOOLEAN Minimized
379 if (Type == WA_ACTIVE || Type == WA_CLICKACTIVE)
383 else if (Type == WA_INACTIVE)
395 InvalidateRect(PhMipContainerWindow, NULL,
FALSE);
402 _In_ PRECT DragRectangle
458 SectionControlOldWndProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(PhMipWindow,
IDC_SECTION), GWLP_WNDPROC);
465 _In_ BOOLEAN Showing,
518 pinned = Button_GetCheck(GetDlgItem(PhMipWindow,
IDC_PIN)) == BST_CHECKED;
529 _Out_ LRESULT *Result
547 _In_ DRAWITEMSTRUCT *DrawItemStruct
555 _In_ ULONG_PTR WParam,
556 _In_ ULONG_PTR LParam
568 for (i = 0; i < SectionList->
Count; i++)
570 section = SectionList->
Items[i];
584 if (Message->hwnd == PhMipContainerWindow || IsChild(PhMipContainerWindow, Message->hwnd))
586 if (Message->message == WM_MOUSEMOVE || Message->message == WM_NCMOUSEMOVE)
588 TRACKMOUSEEVENT trackMouseEvent;
590 trackMouseEvent.cbSize =
sizeof(TRACKMOUSEEVENT);
591 trackMouseEvent.dwFlags = TME_LEAVE | (Message->message == WM_NCMOUSEMOVE ? TME_NONCLIENT : 0);
592 trackMouseEvent.hwndTrack = Message->hwnd;
593 trackMouseEvent.dwHoverTime = 0;
594 TrackMouseEvent(&trackMouseEvent);
596 if (Message->message == WM_MOUSEMOVE)
597 PhMipLastTrackedWindow = Message->hwnd;
599 PhMipLastNcTrackedWindow = Message->hwnd;
603 else if (Message->message == WM_MOUSELEAVE && Message->hwnd == PhMipLastTrackedWindow)
607 else if (Message->message == WM_NCMOUSELEAVE && Message->hwnd == PhMipLastNcTrackedWindow)
611 else if (Message->message == WM_KEYDOWN)
613 switch (Message->wParam)
630 _In_opt_ PVOID Parameter,
631 _In_opt_ PVOID Context
643 LONG oldTotalPinCount;
648 oldTotalPinCount = 0;
651 oldTotalPinCount += PhMipPinCounts[i];
653 oldPinCount = PhMipPinCounts[PinType];
654 newPinCount = max(oldPinCount + PinCount, 0);
655 newPinCount = min(newPinCount, PhMipMaxPinCounts[PinType]);
656 PhMipPinCounts[PinType] = newPinCount;
658 if (oldTotalPinCount == 0 && newPinCount > oldPinCount)
660 else if (oldTotalPinCount > 0 && oldTotalPinCount - oldPinCount + newPinCount == 0)
667 _In_ PPOINT SourcePoint,
674 MONITORINFO monitorInfo = {
sizeof(monitorInfo) };
677 GetWindowRect(PhMipContainerWindow, &windowRect);
678 SendMessage(PhMipContainerWindow, WM_SIZING, WMSZ_BOTTOMRIGHT, (LPARAM)&windowRect);
681 point.
Left = SourcePoint->x;
682 point.
Top = SourcePoint->y;
688 MonitorFromPoint(*SourcePoint, MONITOR_DEFAULTTOPRIMARY),
694 if (memcmp(&monitorInfo.rcWork, &monitorInfo.rcMonitor,
sizeof(RECT)) == 0)
700 if ((trayWindow = FindWindow(L
"Shell_TrayWnd", NULL)) &&
701 GetMonitorInfo(MonitorFromWindow(trayWindow, MONITOR_DEFAULTTOPRIMARY), &monitorInfo) &&
702 GetWindowRect(trayWindow, &taskbarRect))
704 LONG monitorMidX = (monitorInfo.rcMonitor.left + monitorInfo.rcMonitor.right) / 2;
705 LONG monitorMidY = (monitorInfo.rcMonitor.top + monitorInfo.rcMonitor.bottom) / 2;
707 if (taskbarRect.right < monitorMidX)
710 monitorInfo.rcWork.left += taskbarRect.right - taskbarRect.left;
712 else if (taskbarRect.bottom < monitorMidY)
715 monitorInfo.rcWork.top += taskbarRect.bottom - taskbarRect.top;
717 else if (taskbarRect.left > monitorMidX)
720 monitorInfo.rcWork.right -= taskbarRect.right - taskbarRect.left;
722 else if (taskbarRect.top > monitorMidY)
725 monitorInfo.rcWork.bottom -= taskbarRect.bottom - taskbarRect.top;
735 *WindowRectangle = windowRectangle;
744 TEXTMETRIC textMetrics;
752 if (SystemParametersInfo(SPI_GETICONTITLELOGFONT,
sizeof(LOGFONT), &logFont, 0))
754 CurrentParameters.
Font = CreateFontIndirect(&logFont);
762 hdc = GetDC(PhMipWindow);
764 logFont.lfHeight -= MulDiv(2, GetDeviceCaps(hdc, LOGPIXELSY), 72);
765 CurrentParameters.
MediumFont = CreateFontIndirect(&logFont);
767 originalFont = SelectObject(hdc, CurrentParameters.
Font);
768 GetTextMetrics(hdc, &textMetrics);
769 CurrentParameters.
FontHeight = textMetrics.tmHeight;
772 SelectObject(hdc, CurrentParameters.
MediumFont);
773 GetTextMetrics(hdc, &textMetrics);
779 SelectObject(hdc, originalFont);
780 ReleaseDC(PhMipWindow, hdc);
792 section->
Name = Template->Name;
793 section->
Flags = Template->Flags;
794 section->
Callback = Template->Callback;
795 section->
Context = Template->Context;
822 for (i = 0; i < SectionList->
Count; i++)
824 section = SectionList->
Items[i];
843 section.
Flags = Flags;
863 DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD,
879 if (NewSection == CurrentSection)
882 oldSection = CurrentSection;
883 CurrentSection = NewSection;
893 if (!NewSection->DialogHandle)
895 if (NewSection->DialogHandle)
896 ShowWindow(NewSection->DialogHandle, SW_SHOW);
901 NewSection->Callback(NewSection,
MiniInfoTick, NULL, NULL);
911 if (Section == CurrentSection)
938 GetClientRect(PhMipContainerWindow, &clientRect);
941 clientRect.left, clientRect.top,
942 clientRect.right - clientRect.left, clientRect.bottom - clientRect.top,
948 GetWindowRect(GetDlgItem(PhMipWindow,
IDC_LAYOUT), &rect);
949 MapWindowPoints(NULL, PhMipWindow, (POINT *)&rect, 2);
957 rect.right = clientRect.right;
961 LONG leftDistance = rect.left - clientRect.left;
962 LONG rightDistance = clientRect.right - rect.right;
965 if (leftDistance != rightDistance)
968 minDistance = min(leftDistance, rightDistance);
969 rect.left = clientRect.left + minDistance;
970 rect.right = clientRect.right - minDistance;
977 rect.right - rect.left, rect.bottom - rect.top,
982 GetWindowRect(GetDlgItem(PhMipWindow,
IDC_PIN), &rect);
983 MapWindowPoints(NULL, PhMipWindow, (POINT *)&rect, 2);
998 PostMessage(PhMipWindow, WM_MOUSEMOVE, 0, 0);
1023 PhSetWindowStyle(PhMipContainerWindow, WS_DLGFRAME | WS_SYSMENU, Pinned ? (WS_DLGFRAME | WS_SYSMENU) : 0);
1024 SetWindowPos(PhMipContainerWindow, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
1025 PhMipPinned = Pinned;
1043 for (i = 0; i < SectionList->
Count; i++)
1045 section = SectionList->
Items[i];
1056 GetCursorPos(&point);
1096 GetWindowRect(GetDlgItem(PhMipWindow,
IDC_OPTIONS), &rect);
1102 switch (menuItem->
Id)
1146 SetCursor(LoadCursor(NULL, IDC_HAND));
1151 return CallWindowProc(SectionControlOldWndProc, hwnd, uMsg, wParam, lParam);
1166 listSection->
Context = Template->Context;
1167 listSection->
Callback = Template->Callback;
1173 section.
Context = listSection;
1196 _In_opt_ PVOID Parameter1,
1197 _In_opt_ PVOID Parameter2
1269 listSection->DialogHandle = hwndDlg;
1270 listSection->TreeNewHandle = GetDlgItem(hwndDlg,
IDC_LIST);
1276 layoutItem->
Margin.left = -1;
1277 layoutItem->
Margin.top = -1;
1278 layoutItem->
Margin.right = -1;
1309 _In_opt_ PVOID Context
1315 sortList.
List = List;
1336 if (!ListSection->ProcessGroupList)
1339 for (i = 0; i < ListSection->ProcessGroupList->Count; i++)
1366 if (ListSection->ProcessGroupList)
1369 ListSection->ProcessGroupList = NULL;
1372 for (i = 0; i < ListSection->NodeList->Count; i++)
1383 LONG titleAndSubtitleHeight;
1386 titleAndSubtitleHeight =
1389 return max(iconHeight, titleAndSubtitleHeight);
1423 _In_opt_ PVOID Parameter1,
1424 _In_opt_ PVOID Parameter2,
1425 _In_opt_ PVOID Context
1437 if (!getChildren->
Node)
1458 HDC hdc = customDraw->
Dc;
1460 ULONG baseTextFlags = DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE;
1462 COLORREF originalTextColor;
1466 ULONG usageTextTopWidth = 0;
1467 ULONG usageTextBottomWidth = 0;
1475 if (processItem->LargeIcon)
1476 icon = processItem->LargeIcon;
1481 0, NULL, DI_NORMAL);
1484 SelectObject(hdc, CurrentParameters.
Font);
1487 originalTextColor = GetTextColor(hdc);
1492 topRect.bottom = topRect.top + CurrentParameters.
FontHeight;
1494 bottomRect.top = bottomRect.bottom - CurrentParameters.
FontHeight;
1497 getUsageText.SortData = &node->
SortData;
1498 getUsageText.Line1 = NULL;
1499 getUsageText.Line2 = NULL;
1500 getUsageText.Line1Color = originalTextColor;
1501 getUsageText.Line2Color = originalTextColor;
1511 GetTextExtentPoint32(hdc, text.
Buffer, (ULONG)text.
Length / 2, &textSize);
1512 usageTextTopWidth = textSize.cx;
1514 textRect.left = textRect.right - textSize.cx;
1515 SetTextColor(hdc, getUsageText.Line1Color);
1516 DrawText(hdc, text.
Buffer, (ULONG)text.
Length / 2, &textRect, baseTextFlags | DT_RIGHT);
1521 GetTextExtentPoint32(hdc, text.
Buffer, (ULONG)text.
Length / 2, &textSize);
1522 usageTextBottomWidth = textSize.cx;
1523 textRect = bottomRect;
1524 textRect.left = textRect.right - textSize.cx;
1525 SetTextColor(hdc, getUsageText.Line2Color);
1526 DrawText(hdc, text.
Buffer, (ULONG)text.
Length / 2, &textRect, baseTextFlags | DT_RIGHT);
1533 getTitleText.SortData = &node->
SortData;
1536 PhSetReference(&getTitleText.Title, processItem->VersionInfo.FileDescription);
1542 PhSetReference(&getTitleText.Subtitle, processItem->ProcessName);
1547 L
"%s (%u processes)",
1548 processItem->ProcessName->Buffer,
1553 getTitleText.TitleColor = originalTextColor;
1554 getTitleText.SubtitleColor = GetSysColor(COLOR_GRAYTEXT);
1564 SetTextColor(hdc, getTitleText.TitleColor);
1567 getTitleText.Title->Buffer,
1568 (ULONG)getTitleText.Title->Length / 2,
1570 baseTextFlags | DT_END_ELLIPSIS
1578 textRect = bottomRect;
1580 SetTextColor(hdc, getTitleText.SubtitleColor);
1583 getTitleText.Subtitle->Buffer,
1584 (ULONG)getTitleText.Subtitle->Length / 2,
1586 baseTextFlags | DT_END_ELLIPSIS
1600 tickCount = GetTickCount();
1657 if (GetKeyState(VK_CONTROL) >= 0)
1725 for (i = 0; i < ListSection->NodeList->Count; i++)
1727 node = ListSection->NodeList->Items[i];
1773 pluginMenuInfo.
Menu = menu;
1775 pluginMenuInfo.
u.
MiListSection.SectionName = &ListSection->Section->Name;
1786 ContextMenu->Location.x,
1787 ContextMenu->Location.y
1792 BOOLEAN handled =
FALSE;
1828 for (i = 0; i < ProcessGroup->Processes->Count; i++)
1852 _In_opt_ PVOID Parameter1,
1853 _In_opt_ PVOID Parameter2
1859 ListSection->Section->Parameters->SetSectionText(ListSection->Section,
1877 for (i = 0; i < processes->
Count; i++)
1898 if (cpuUsage >= 0.01)
1900 else if (cpuUsage != 0)
1903 cpuUsageText = NULL;
1914 _In_
const void *elem1,
1915 _In_
const void *elem2
1931 _In_
const void *elem1,
1932 _In_
const void *elem2
1944 _In_opt_ PVOID Parameter1,
1945 _In_opt_ PVOID Parameter2
1960 ListSection->Section->Parameters->SetSectionText(ListSection->Section,
1976 ULONG64 privateBytes = 0;
1979 for (i = 0; i < processes->
Count; i++)
2001 getUsageText->
Line2Color = GetSysColor(COLOR_GRAYTEXT);
2010 _In_
const void *elem1,
2011 _In_
const void *elem2
2021 _In_
const void *elem1,
2022 _In_
const void *elem2
2034 _In_opt_ PVOID Parameter1,
2035 _In_opt_ PVOID Parameter2
2051 ListSection->Section->Parameters->SetSectionText(ListSection->Section,
2067 ULONG64 workingSet = 0;
2070 for (i = 0; i < processes->
Count; i++)
2092 getUsageText->
Line2Color = GetSysColor(COLOR_GRAYTEXT);
2101 _In_
const void *elem1,
2102 _In_
const void *elem2
2112 _In_
const void *elem1,
2113 _In_
const void *elem2
2125 _In_opt_ PVOID Parameter1,
2126 _In_opt_ PVOID Parameter2
2147 ListSection->Section->Parameters->SetSectionText(ListSection->Section,
2163 ULONG64 ioReadOtherDelta = 0;
2164 ULONG64 ioWriteDelta = 0;
2167 for (i = 0; i < processes->
Count; i++)
2205 _In_
const void *elem1,
2206 _In_
const void *elem2
2226 _In_
const void *elem1,
2227 _In_
const void *elem2