Introduction
In Windows XP, I was used to turning on "Show icon in notification area when connected" and Windows would display a blinking icon to indicate network traffic on the System Tray.
In Windows 7, all I can get is a static icon to show I am on a network, no animation to show me the traffic.
I figured out that the animation feature had been removed from Windows 7, so I decided to create a simple application to satisfy those people (including myself) who want to see when data is coming and going on the network.
A long time ago, I developed a small utility called Network Lights which blinks keyboard LEDs (Light Emitting Diode) indicating outgoing and incoming network packets on the network interface. This utility with source code can be found here: www.itsamples.com/network-lights.html. I remade it to control the System Tray icon instead of keyboard LEDs and adapted it to Windows 7 environment.
Using the Code
The core of this program is a separate thread that obtains current TCP, UDP and ICMP statistics and decides which icon should be displayed on the System Tray:
void TCPThread(LPVOID pInfo)
{
MIB_TCPSTATS mibTcpStats;
MIB_UDPSTATS mibUdpStats;
MIB_ICMP mibIcmpStats;
UINT nCounter = 0;
DWORD dwSegTcpRcvd = 0;
DWORD dwSegTcpSent = 0;
DWORD dwSegUdpRcvd = 0;
DWORD dwSegUdpSent = 0;
DWORD dwSegIcmpRcvd = 0;
DWORD dwSegIcmpSent = 0;
DWORD dwLocalOutSegs = 0;
DWORD dwLocalInSegs = 0;
while(m_bWorkContinue)
{
if(m_bSetIconContinue)
{
m_dwPacketsSent = 0;
m_dwPacketsReceived = 0;
m_bSetIconContinue = FALSE;
if(m_bDisplayTCP)
{
if(GetTcpStatistics(&mibTcpStats) == NO_ERROR)
{
dwLocalInSegs = mibTcpStats.dwInSegs;
dwLocalOutSegs = mibTcpStats.dwOutSegs;
m_dwPacketsSent += dwLocalOutSegs;
m_dwPacketsReceived += dwLocalInSegs;
if(dwLocalOutSegs > dwSegTcpSent &&
dwLocalInSegs > dwSegTcpRcvd)
{
dwSegTcpSent = dwLocalOutSegs;
dwSegTcpRcvd = dwLocalInSegs;
SetTrayIcon(NIM_MODIFY,
m_hActiveIcon);
goto done;
}
else if(dwLocalOutSegs > dwSegTcpSent &&
dwLocalInSegs <= dwSegTcpRcvd)
{
dwSegTcpSent = dwLocalOutSegs;
SetTrayIcon
(NIM_MODIFY, m_hSendIcon);
goto done;
}
else if(dwLocalInSegs > dwSegTcpRcvd &&
dwLocalOutSegs <= dwSegTcpSent)
{
dwSegTcpRcvd = dwLocalInSegs;
SetTrayIcon(NIM_MODIFY,
m_hReceiveIcon);
goto done;
}
else
nCounter++;
if(nCounter == 10)
{
nCounter = 0;
SetTrayIcon(NIM_MODIFY,
m_hInactiveIcon);
goto done;
}
}
}
if(m_bDisplayUDP)
{
if(GetUdpStatistics(&mibUdpStats) == NO_ERROR)
{
dwLocalInSegs = mibUdpStats.dwInDatagrams;
dwLocalOutSegs = mibUdpStats.dwOutDatagrams;
m_dwPacketsSent += dwLocalOutSegs;
m_dwPacketsReceived += dwLocalInSegs;
if(dwLocalOutSegs > dwSegUdpSent &&
dwLocalInSegs > dwSegUdpRcvd)
{
dwSegUdpSent = dwLocalOutSegs;
dwSegUdpRcvd = dwLocalInSegs;
SetTrayIcon(NIM_MODIFY,
m_hActiveIcon);
goto done;
}
else if(dwLocalOutSegs > dwSegUdpSent &&
dwLocalInSegs <= dwSegUdpRcvd)
{
dwSegUdpSent = dwLocalOutSegs;
SetTrayIcon(NIM_MODIFY,
m_hSendIcon);
goto done;
}
else if(dwLocalInSegs > dwSegUdpRcvd &&
dwLocalOutSegs <= dwSegUdpSent)
{
dwSegUdpRcvd = dwLocalInSegs;
SetTrayIcon(NIM_MODIFY,
m_hReceiveIcon);
goto done;
}
else
nCounter++;
if(nCounter == 10)
{
nCounter = 0;
SetTrayIcon(NIM_MODIFY,
m_hInactiveIcon);
goto done;
}
}
}
if(m_bDisplayICMP)
{
if(GetIcmpStatistics(&mibIcmpStats) == NO_ERROR)
{
dwLocalInSegs =
mibIcmpStats.stats.icmpInStats.dwMsgs;
dwLocalOutSegs =
mibIcmpStats.stats.icmpOutStats.dwMsgs;
m_dwPacketsSent += dwLocalOutSegs;
m_dwPacketsReceived += dwLocalInSegs;
if(dwLocalOutSegs > dwSegIcmpSent &&
dwLocalInSegs > dwSegIcmpRcvd)
{
dwSegIcmpSent = dwLocalOutSegs;
dwSegIcmpRcvd = dwLocalInSegs;
SetTrayIcon(NIM_MODIFY,
m_hActiveIcon);
goto done;
}
else if(dwLocalOutSegs > dwSegIcmpSent &&
dwLocalInSegs <= dwSegIcmpRcvd)
{
dwSegIcmpSent = dwLocalOutSegs;
SetTrayIcon(NIM_MODIFY,
m_hSendIcon);
goto done;
}
else if(dwLocalInSegs > dwSegIcmpRcvd &&
dwLocalOutSegs <= dwSegIcmpSent)
{
dwSegIcmpRcvd = dwLocalInSegs;
SetTrayIcon(NIM_MODIFY,
m_hReceiveIcon);
goto done;
}
else
nCounter++;
if(nCounter == 10)
{
nCounter = 0;
SetTrayIcon(NIM_MODIFY,
m_hInactiveIcon);
goto done;
}
}
}
done:
m_bSetIconContinue = TRUE;
}
Sleep(m_nDuration);
}
m_hTcpThread = NULL;
}
Unlike the original Windows XP utility (that has individual indicators for each interface), this program indicates outgoing and incoming network packets on all available interfaces.
History
- Initial post: November 20, 2009
- Updated: January 14, 2010
Version 1.2 allows you to display ICMP and UDP packets, show selected Network Interface traffic in bytes, use Vista-styled icons, and access the "Network Connections", "Windows Firewall" and "Network and Sharing Center" applets directly.