25 #define MSG_UPDATE (WM_APP + 1)
26 #define MSG_UPDATE_PANEL (WM_APP + 2)
28 static VOID NTAPI ProcessesUpdatedHandler(
29 _In_opt_ PVOID Parameter,
30 _In_opt_ PVOID Context
41 static VOID NetAdapterUpdateGraphs(
45 Context->GraphState.Valid =
FALSE;
46 Context->GraphState.TooltipIndex = -1;
50 InvalidateRect(Context->GraphHandle, NULL,
FALSE);
53 static VOID NetAdapterUpdatePanel(
58 ULONG64 outOctets = 0;
59 ULONG64 linkSpeed = 0;
60 NDIS_MEDIA_CONNECT_STATE mediaState = MediaConnectStateUnknown;
62 if (Context->DeviceHandle)
64 NDIS_STATISTICS_INFO interfaceStats;
65 NDIS_LINK_STATE interfaceState;
69 if (!(interfaceStats.SupportedStatistics & NDIS_STATISTICS_FLAGS_VALID_BYTES_RCV))
72 inOctets = interfaceStats.ifHCInOctets;
74 if (!(interfaceStats.SupportedStatistics & NDIS_STATISTICS_FLAGS_VALID_BYTES_XMIT))
77 outOctets = interfaceStats.ifHCOutOctets;
93 mediaState = interfaceState.MediaConnectState;
94 linkSpeed = interfaceState.XmitLinkSpeed;
103 MIB_IF_ROW2 interfaceRow;
107 inOctets = interfaceRow.InOctets;
108 outOctets = interfaceRow.OutOctets;
109 mediaState = interfaceRow.MediaConnectState;
110 linkSpeed = interfaceRow.TransmitLinkSpeed;
114 MIB_IFROW interfaceRow;
118 inOctets = interfaceRow.dwInOctets;
119 outOctets = interfaceRow.dwOutOctets;
120 linkSpeed = interfaceRow.dwSpeed;
122 if (interfaceRow.dwOperStatus == IF_OPER_STATUS_OPERATIONAL)
123 mediaState = MediaConnectStateConnected;
125 mediaState = MediaConnectStateDisconnected;
128 if (mediaState == MediaConnectStateConnected)
129 SetDlgItemText(Context->PanelWindowHandle,
IDC_LINK_STATE, L
"Connected");
131 SetDlgItemText(Context->PanelWindowHandle,
IDC_LINK_STATE, L
"Disconnected");
139 static INT_PTR CALLBACK NetAdapterPanelDialogProc(
149 static INT_PTR CALLBACK NetAdapterDialogProc(
158 if (uMsg == WM_INITDIALOG)
162 SetProp(hwndDlg, L
"Context", (HANDLE)context);
168 if (uMsg == WM_NCDESTROY)
182 RemoveProp(hwndDlg, L
"Context");
216 WS_VISIBLE | WS_CHILD | WS_BORDER,
231 &PhProcessesUpdatedEvent,
232 ProcessesUpdatedHandler,
237 NetAdapterUpdateGraphs(context);
238 NetAdapterUpdatePanel(context);
246 NMHDR* header = (NMHDR*)lParam;
250 switch (header->code)
279 if (max < data1 + data2)
313 ULONG64 adapterInboundValue = PhGetItemCircularBuffer_ULONG64(
315 getTooltipText->
Index
318 ULONG64 adapterOutboundValue = PhGetItemCircularBuffer_ULONG64(
320 getTooltipText->
Index
341 NetAdapterUpdateGraphs(context);
342 NetAdapterUpdatePanel(context);
350 static BOOLEAN NetAdapterSectionCallback(
353 _In_opt_ PVOID Parameter1,
354 _In_opt_ PVOID Parameter2
370 FILE_ATTRIBUTE_NORMAL,
371 FILE_SHARE_READ | FILE_SHARE_WRITE,
408 ULONG64 networkInOctets = 0;
409 ULONG64 networkOutOctets = 0;
410 ULONG64 networkRcvSpeed = 0;
411 ULONG64 networkXmitSpeed = 0;
416 NDIS_STATISTICS_INFO interfaceStats;
421 if (!(interfaceStats.SupportedStatistics & NDIS_STATISTICS_FLAGS_VALID_BYTES_RCV))
424 networkInOctets = interfaceStats.ifHCInOctets;
426 if (!(interfaceStats.SupportedStatistics & NDIS_STATISTICS_FLAGS_VALID_BYTES_XMIT))
429 networkOutOctets = interfaceStats.ifHCOutOctets;
463 MIB_IF_ROW2 interfaceRow;
467 networkInOctets = interfaceRow.InOctets;
468 networkOutOctets = interfaceRow.OutOctets;
484 MIB_IFROW interfaceRow;
488 networkInOctets = interfaceRow.dwInOctets;
489 networkOutOctets = interfaceRow.dwOutOctets;
507 networkXmitSpeed = 0;
511 PhAddItemCircularBuffer_ULONG64(&context->
InboundBuffer, networkRcvSpeed);
512 PhAddItemCircularBuffer_ULONG64(&context->
OutboundBuffer, networkXmitSpeed);
527 createDialog->
DialogProc = NetAdapterDialogProc;
539 if (!Section->GraphState.Valid)
548 Section->GraphState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->
InboundBuffer, i);
549 Section->GraphState.Data2[i] = data2 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->
OutboundBuffer, i);
551 if (max < data1 + data2)
561 Section->GraphState.Data1,
568 Section->GraphState.Data2,
572 Section->GraphState.Valid =
TRUE;
580 ULONG64 adapterInboundValue = PhGetItemCircularBuffer_ULONG64(
582 getTooltipText->
Index
585 ULONG64 adapterOutboundValue = PhGetItemCircularBuffer_ULONG64(
587 getTooltipText->
Index
597 getTooltipText->
Text = Section->GraphState.TooltipText->sr;
632 section.
Callback = NetAdapterSectionCallback;