Click here to Skip to main content
12,348,728 members (67,286 online)
Click here to Skip to main content
Add your own
alternative version

Stats

176.6K views
7.4K downloads
80 bookmarked
Posted

Network Activity Indicator for Windows 7

, 27 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Displays the old "two monitors" icon in Windows 7 that flashed blue to show network activity on the System Tray.
Network Activity Indicator

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Igor Tolmachev
Software Developer (Senior)
Ukraine Ukraine
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionInternet connectivity Pin
gauravkale18-Nov-11 1:52
membergauravkale18-Nov-11 1:52 
GeneralGreat solution! Pin
tuckertje19-Oct-11 22:12
membertuckertje19-Oct-11 22:12 
QuestionExcellent idea but... Pin
brakto17-Aug-11 7:52
memberbrakto17-Aug-11 7:52 
QuestionWonderful! Any chance of the globe icon? Pin
Member 815486811-Aug-11 13:04
memberMember 815486811-Aug-11 13:04 
QuestionThanks for this...great stuff Pin
baseman119-Jul-11 11:39
memberbaseman119-Jul-11 11:39 
GeneralThank you, spacibo! Pin
Member 80550463-Jul-11 10:11
memberMember 80550463-Jul-11 10:11 
GeneralMy vote of 5 Pin
Sahir Shah2-Jul-11 8:33
groupSahir Shah2-Jul-11 8:33 
GeneralWonderful Pin
Member 794397721-May-11 22:24
memberMember 794397721-May-11 22:24 
GeneralMy vote of 5 Pin
usbchris21-May-11 3:34
memberusbchris21-May-11 3:34 
GeneralExcellent! Pin
whawn26-Apr-11 9:12
memberwhawn26-Apr-11 9:12 
GeneralMy vote of 5 Pin
Scott Wichall27-Feb-11 22:45
memberScott Wichall27-Feb-11 22:45 
GeneralMy vote of 5 Pin
Waleed Eissa20-Feb-11 2:02
memberWaleed Eissa20-Feb-11 2:02 
GeneralMy vote of 5 Pin
gndnet16-Dec-10 14:21
membergndnet16-Dec-10 14:21 
GeneralAnother 5 vote from me! Pin
code_junkie2-Dec-10 3:46
membercode_junkie2-Dec-10 3:46 
GeneralGreat app, 5 points. Pin
dickdickson22-Oct-10 11:29
memberdickdickson22-Oct-10 11:29 
GeneralMy vote of 5 Pin
EFEaglehouse12-Oct-10 8:45
memberEFEaglehouse12-Oct-10 8:45 
GeneralMy vote of 5 Pin
lescol@gmail.com25-Sep-10 5:33
memberlescol@gmail.com25-Sep-10 5:33 
GeneralMy vote of 5 Pin
William Escue2-Aug-10 5:26
memberWilliam Escue2-Aug-10 5:26 
GeneralMy vote of 4 Pin
DrCezW3rd14-Jul-10 6:39
memberDrCezW3rd14-Jul-10 6:39 
GeneralGood software Pin
DavidSmithgf6-Jul-10 19:59
memberDavidSmithgf6-Jul-10 19:59 
GeneralSuggestion Pin
DavidSmithgf6-Jul-10 20:15
memberDavidSmithgf6-Jul-10 20:15 
GeneralMy vote of 5 Pin
castletonroad3-Jul-10 9:54
membercastletonroad3-Jul-10 9:54 
GeneralMy vote of 5 Pin
fubuhead@hotmail.com26-Jun-10 8:18
memberfubuhead@hotmail.com26-Jun-10 8:18 
GeneralThanks For The Network Indicator! Pin
tallowtreemfg18-Jun-10 15:53
membertallowtreemfg18-Jun-10 15:53 
GeneralBug in Autostart code Pin
EzE31-May-10 21:32
memberEzE31-May-10 21:32 
GeneralRe: Bug in Autostart code Pin
alx_max14-Dec-10 5:59
memberalx_max14-Dec-10 5:59 
GeneralRe: Bug in Autostart code Pin
alx_max14-Dec-10 23:35
memberalx_max14-Dec-10 23:35 
GeneralThanks! Pin
Heathheath22-May-10 20:00
memberHeathheath22-May-10 20:00 
QuestionExcellent idea and implementation! Pin
DrABELL11-Apr-10 8:09
memberDrABELL11-Apr-10 8:09 
Generalmerci Pin
kannyy9-Apr-10 9:23
memberkannyy9-Apr-10 9:23 
GeneralMysterious "inactive"-status Pin
tray-icon10-Mar-10 23:09
membertray-icon10-Mar-10 23:09 
GeneralRe: Mysterious "inactive"-status Pin
Igor Tolmachev14-Mar-10 6:58
memberIgor Tolmachev14-Mar-10 6:58 
GeneralRe: Mysterious "inactive"-status Pin
tray-icon23-Mar-10 23:32
membertray-icon23-Mar-10 23:32 
GeneralNEW: "inactive"-status NOW reproducible! Pin
tray-icon25-Mar-10 10:14
membertray-icon25-Mar-10 10:14 
Generalspasibo za tulzu! Pin
login_9531-Mar-10 23:08
memberlogin_9531-Mar-10 23:08 
GeneralGreat util & request Pin
sthubbar26-Feb-10 3:42
membersthubbar26-Feb-10 3:42 
GeneralDefinite 5 from me too Pin
colins214-Feb-10 4:15
membercolins214-Feb-10 4:15 
GeneralThanks and suggestions [modified] Pin
tray-icon12-Feb-10 10:19
membertray-icon12-Feb-10 10:19 
Generalthis is great thanks :D Pin
Sptator9-Feb-10 6:09
memberSptator9-Feb-10 6:09 
GeneralRe: this is great thanks :D Pin
Igor Tolmachev11-Feb-10 1:16
memberIgor Tolmachev11-Feb-10 1:16 
GeneralImproves even the original Xp version, and Great to restore lost XP Icons Pin
chipmaster863-Feb-10 6:21
memberchipmaster863-Feb-10 6:21 
GeneralWorks great in Vista too! Pin
dhuddleston28-Jan-10 5:21
memberdhuddleston28-Jan-10 5:21 
JokeSupport for other protocols Pin
Mehdi Tirgar16-Dec-09 11:37
memberMehdi Tirgar16-Dec-09 11:37 
GeneralRe: Support for other protocols Pin
Igor Tolmachev18-Dec-09 1:07
memberIgor Tolmachev18-Dec-09 1:07 
GeneralRe: Support for other protocols Pin
Igor Tolmachev18-Dec-09 1:16
memberIgor Tolmachev18-Dec-09 1:16 
GeneralRe: Support for other protocols Pin
gaby_la_star4-Jan-10 23:25
membergaby_la_star4-Jan-10 23:25 
GeneralRe: Support for other protocols Pin
Igor Tolmachev11-Feb-10 1:21
memberIgor Tolmachev11-Feb-10 1:21 
GeneralRe: Support for other protocols Pin
gaby_la_star13-Feb-10 7:17
membergaby_la_star13-Feb-10 7:17 
GeneralRe: Support for other protocols Pin
gaby_la_star20-Mar-10 8:43
membergaby_la_star20-Mar-10 8:43 
GeneralRe: Support for other protocols Pin
Mehdi Tirgar17-Feb-10 11:34
memberMehdi Tirgar17-Feb-10 11:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 27 Jan 2010
Article Copyright 2009 by Igor Tolmachev
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid