Skip to content

Commit 7fd8ece

Browse files
committed
Sync code
1 parent 4115228 commit 7fd8ece

File tree

6 files changed

+54
-90
lines changed

6 files changed

+54
-90
lines changed

plugins/NetworkTools/NetworkTools.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS
132132
CAPTION "Dialog"
133133
FONT 8, "MS Shell Dlg", 400, 0, 0x1
134134
BEGIN
135-
CONTROL "",IDC_NETOUTPUTEDIT,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,23,375,182
135+
CONTROL "",IDC_LIST_TRACERT,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,23,375,182
136136
LTEXT "Tracing route to xyz...",IDC_STATUS,7,5,375,12
137137
END
138138

plugins/NetworkTools/nettools.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ typedef struct _NETWORK_OUTPUT_CONTEXT
106106
HANDLE PipeReadHandle;
107107
HANDLE ProcessHandle;
108108
HFONT FontHandle;
109-
HICON IconHandle;
110109

111110
ULONG CurrentPingMs;
112111
ULONG MaxPingTimeout;

plugins/NetworkTools/ping.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ INT_PTR CALLBACK NetworkPingWndProc(
293293
PH_RECTANGLE windowRectangle;
294294
PPH_LAYOUT_ITEM panelItem;
295295

296+
CommonSetWindowIcon(hwndDlg);
297+
296298
// We have already set the group boxes to have WS_EX_TRANSPARENT to fix
297299
// the drawing issue that arises when using WS_CLIPCHILDREN. However
298300
// in removing the flicker from the graphs the group boxes will now flicker.
@@ -325,20 +327,7 @@ INT_PTR CALLBACK NetworkPingWndProc(
325327
);
326328
Graph_SetTooltip(context->PingGraphHandle, TRUE);
327329

328-
// Load the Process Hacker icon.
329-
context->IconHandle = (HICON)LoadImage(
330-
NtCurrentPeb()->ImageBaseAddress,
331-
MAKEINTRESOURCE(PHAPP_IDI_PROCESSHACKER),
332-
IMAGE_ICON,
333-
GetSystemMetrics(SM_CXICON),
334-
GetSystemMetrics(SM_CYICON),
335-
LR_SHARED
336-
);
337-
// Set window icon.
338-
if (context->IconHandle)
339-
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)context->IconHandle);
340-
341-
// Initialize the WorkQueue with a maximum of 20 threads (fix pinging slow-links with a high interval update).
330+
// Initialize the WorkQueue with a maximum of 20 threads (fixes pinging slow-links when the refresh interval is 'very slow').
342331
PhInitializeWorkQueue(&context->PingWorkQueue, 0, 20, 5000);
343332
PhInitializeGraphState(&context->PingGraphState);
344333
PhInitializeLayoutManager(&context->LayoutManager, hwndDlg);
@@ -415,9 +404,6 @@ INT_PTR CALLBACK NetworkPingWndProc(
415404
if (context->PingGraphHandle)
416405
DestroyWindow(context->PingGraphHandle);
417406

418-
if (context->IconHandle)
419-
DestroyIcon(context->IconHandle);
420-
421407
if (context->FontHandle)
422408
DeleteObject(context->FontHandle);
423409

plugins/NetworkTools/resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define IDC_PING_LAYOUT 1021
2222
#define IDC_BAD_HASH 1022
2323
#define IDC_STATUS 1023
24+
#define IDC_LIST_TRACERT 1024
2425
#define ID_NETWORK_PING 22465
2526
#define ID_NETWORK_TRACEROUTE 22466
2627
#define ID_NETWORK_WHOIS 22467
@@ -33,7 +34,7 @@
3334
#ifndef APSTUDIO_READONLY_SYMBOLS
3435
#define _APS_NEXT_RESOURCE_VALUE 107
3536
#define _APS_NEXT_COMMAND_VALUE 40006
36-
#define _APS_NEXT_CONTROL_VALUE 1024
37+
#define _APS_NEXT_CONTROL_VALUE 1025
3738
#define _APS_NEXT_SYMED_VALUE 104
3839
#endif
3940
#endif

plugins/NetworkTools/tracert.c

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -583,25 +583,16 @@ INT_PTR CALLBACK TracertDlgProc(
583583

584584
if (uMsg == WM_DESTROY)
585585
{
586-
context->OutputHandle = NULL;
587-
588586
PhSaveListViewColumnsToSetting(SETTING_NAME_TRACERT_COLUMNS, context->OutputHandle);
589587
PhSaveWindowPlacementToSetting(SETTING_NAME_TRACERT_WINDOW_POSITION, SETTING_NAME_TRACERT_WINDOW_SIZE, hwndDlg);
590588

591-
PhSaveWindowPlacementToSetting(
592-
SETTING_NAME_PING_WINDOW_POSITION,
593-
SETTING_NAME_PING_WINDOW_SIZE,
594-
hwndDlg
595-
);
596-
597-
if (context->IconHandle)
598-
DestroyIcon(context->IconHandle);
599-
600589
if (context->FontHandle)
601590
DeleteObject(context->FontHandle);
602591

603592
PhDeleteLayoutManager(&context->LayoutManager);
604593

594+
context->OutputHandle = NULL;
595+
605596
RemoveProp(hwndDlg, L"Context");
606597
PhFree(context);
607598

@@ -616,78 +607,49 @@ INT_PTR CALLBACK TracertDlgProc(
616607
{
617608
case WM_INITDIALOG:
618609
{
619-
PH_RECTANGLE windowRectangle;
620610
HANDLE dialogThread;
611+
612+
PhCenterWindow(hwndDlg, GetParent(hwndDlg));
613+
CommonSetWindowIcon(hwndDlg);
614+
615+
Static_SetText(hwndDlg,
616+
PhaFormatString(L"Tracing %s...", context->IpAddressString)->Buffer
617+
);
618+
Static_SetText(GetDlgItem(hwndDlg, IDC_STATUS),
619+
PhaFormatString(L"Tracing route to %s with %lu bytes of data...", context->IpAddressString, PhGetIntegerSetting(SETTING_NAME_PING_SIZE))->Buffer
620+
);
621621

622622
context->WindowHandle = hwndDlg;
623-
context->OutputHandle = GetDlgItem(hwndDlg, IDC_NETOUTPUTEDIT);
623+
context->OutputHandle = GetDlgItem(hwndDlg, IDC_LIST_TRACERT);
624624
context->MaxPingTimeout = PhGetIntegerSetting(SETTING_NAME_PING_MINIMUM_SCALING);
625-
626-
windowRectangle.Position = PhGetIntegerPairSetting(SETTING_NAME_TRACERT_WINDOW_POSITION);
627-
windowRectangle.Size = PhGetScalableIntegerPairSetting(SETTING_NAME_TRACERT_WINDOW_SIZE, TRUE).Pair;
628-
629-
// Create the font handle.
630625
context->FontHandle = CommonCreateFont(-15, GetDlgItem(hwndDlg, IDC_STATUS));
631626

632-
// Load the Process Hacker icon.
633-
context->IconHandle = (HICON)LoadImage(
634-
NtCurrentPeb()->ImageBaseAddress,
635-
MAKEINTRESOURCE(PHAPP_IDI_PROCESSHACKER),
636-
IMAGE_ICON,
637-
GetSystemMetrics(SM_CXICON),
638-
GetSystemMetrics(SM_CYICON),
639-
LR_SHARED
640-
);
641-
642-
// Set window icon.
643-
if (context->IconHandle)
644-
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)context->IconHandle);
645-
646627
PhSetListViewStyle(context->OutputHandle, FALSE, TRUE);
647628
PhSetControlTheme(context->OutputHandle, L"explorer");
648629
PhAddListViewColumn(context->OutputHandle, 0, 0, 0, LVCFMT_RIGHT, 30, L"TTL");
630+
649631
for (UINT i = 0; i < MAX_PINGS; i++)
650632
PhAddListViewColumn(context->OutputHandle, i + 1, i + 1, i + 1, LVCFMT_RIGHT, 50, L"Time");
633+
651634
PhAddListViewColumn(context->OutputHandle, IP_ADDRESS_COLUMN, IP_ADDRESS_COLUMN, IP_ADDRESS_COLUMN, LVCFMT_LEFT, 120, L"IP Address");
652635
PhAddListViewColumn(context->OutputHandle, HOSTNAME_COLUMN, HOSTNAME_COLUMN, HOSTNAME_COLUMN, LVCFMT_LEFT, 240, L"Hostname");
653-
PhSetExtendedListView(context->OutputHandle);
654-
655636
PhLoadListViewColumnsFromSetting(SETTING_NAME_TRACERT_COLUMNS, context->OutputHandle);
637+
PhSetExtendedListView(context->OutputHandle);
656638

657639
PhInitializeLayoutManager(&context->LayoutManager, hwndDlg);
658640
PhAddLayoutItem(&context->LayoutManager, context->OutputHandle, NULL, PH_ANCHOR_ALL);
659641
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_STATUS), NULL, PH_ANCHOR_TOP | PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT);
660-
661-
// Load window settings.
662-
if (windowRectangle.Position.X == 0 || windowRectangle.Position.Y == 0)
663-
{
664-
PhCenterWindow(hwndDlg, GetParent(hwndDlg));
665-
}
666-
else
667-
{
668-
PhLoadWindowPlacementFromSetting(SETTING_NAME_PING_WINDOW_POSITION, SETTING_NAME_PING_WINDOW_SIZE, hwndDlg);
669-
}
670-
671-
672-
Static_SetText(context->WindowHandle,
673-
PhaFormatString(L"Tracing %s...", context->IpAddressString)->Buffer
674-
);
675-
Static_SetText(GetDlgItem(hwndDlg, IDC_STATUS),
676-
PhaFormatString(L"Tracing route to %s with %lu bytes of data...", context->IpAddressString, PhGetIntegerSetting(SETTING_NAME_PING_SIZE))->Buffer
677-
);
642+
PhLoadWindowPlacementFromSetting(SETTING_NAME_TRACERT_WINDOW_POSITION, SETTING_NAME_TRACERT_WINDOW_SIZE, hwndDlg);
678643

679644
if (dialogThread = PhCreateThread(0, NetworkTracertThreadStart, (PVOID)context))
680-
{
681645
NtClose(dialogThread);
682-
}
683646
}
684647
break;
685648
case WM_COMMAND:
686649
{
687650
switch (GET_WM_COMMAND_ID(wParam, lParam))
688651
{
689652
case IDCANCEL:
690-
case IDOK:
691653
DestroyWindow(hwndDlg);
692654
break;
693655
}
@@ -709,12 +671,12 @@ INT_PTR CALLBACK TracertDlgProc(
709671
L"*"
710672
);
711673

712-
TracertAppendText(
713-
context,
714-
error->LvItemIndex,
715-
IP_ADDRESS_COLUMN,
716-
TracertGetErrorMessage(error->LastErrorCode)->Buffer
717-
);
674+
//TracertAppendText(
675+
// context,
676+
// error->LvItemIndex,
677+
// IP_ADDRESS_COLUMN,
678+
// TracertGetErrorMessage(error->LastErrorCode)->Buffer
679+
// );
718680
}
719681
else
720682
{
@@ -749,26 +711,22 @@ INT_PTR CALLBACK TracertDlgProc(
749711
break;
750712
case NTM_RECEIVEDFINISH:
751713
{
752-
PPH_STRING windowText = PhGetWindowText(context->WindowHandle);
714+
PPH_STRING windowText;
753715

754-
if (windowText)
716+
if (windowText = PH_AUTO(PhGetWindowText(context->WindowHandle)))
755717
{
756718
Static_SetText(
757719
context->WindowHandle,
758720
PhaFormatString(L"%s complete.", windowText->Buffer)->Buffer
759721
);
760-
PhDereferenceObject(windowText);
761722
}
762723

763-
windowText = PhGetWindowText(GetDlgItem(hwndDlg, IDC_STATUS));
764-
765-
if (windowText)
724+
if (windowText = PH_AUTO(PhGetWindowText(GetDlgItem(hwndDlg, IDC_STATUS))))
766725
{
767726
Static_SetText(
768727
GetDlgItem(hwndDlg, IDC_STATUS),
769728
PhaFormatString(L"%s complete.", windowText->Buffer)->Buffer
770729
);
771-
PhDereferenceObject(windowText);
772730
}
773731
}
774732
break;

plugins/include/commonutil.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ FormatAnsiString(
5252
return FormatAnsiString_V(Format, argptr);
5353
}
5454

55-
56-
5755
FORCEINLINE
5856
HFONT
5957
CommonCreateFont(
@@ -105,4 +103,26 @@ CommonDuplicateFont(
105103
return NULL;
106104
}
107105

106+
FORCEINLINE
107+
VOID
108+
CommonSetWindowIcon(
109+
_In_ HWND WindowHandle
110+
)
111+
{
112+
HICON iconHandle;
113+
114+
// Load the Process Hacker window icon
115+
if (iconHandle = (HICON)LoadImage(
116+
NtCurrentPeb()->ImageBaseAddress,
117+
MAKEINTRESOURCE(PHAPP_IDI_PROCESSHACKER),
118+
IMAGE_ICON,
119+
GetSystemMetrics(SM_CXICON),
120+
GetSystemMetrics(SM_CYICON),
121+
LR_SHARED
122+
))
123+
{
124+
SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)iconHandle);
125+
}
126+
}
127+
108128
#endif

0 commit comments

Comments
 (0)