NetTrafficButton
Environment: VC6 SP4, Win2000
This little control, derived from a CButton control, displays the network traffic on a given interface. It uses the Performace API functions to enumerate the current traffic.
Usage:
1. Copy files
To use this control in your project, simply copy the two classes
MFNetTraffic
MFNetTrafficButton
into your project directory (also copy the globals.h file, which includes the necessary definitions and types).
2.Create helper button
Create a CButton control in your e.g. Dialog and overwrite the type with MFNetTrafficButton.
3. Initalization
Initialize the control with the right values. These are:
MFNetTrafficButton.SetInterfaceNumber(SelectedInterface);
This initializes the control to monitor the interface given. You can obtain this value by calling the MFNetTraffic::GetNetworkInterfacesCount() method.
MFNetTrafficButton.SelectTrafficType(MFTrafficButton::Traffic_Total);
Sets the type of the traffic to monitor. Possible values are:
Traffic_Total
Traffic_Incoming
Traffic_Outgoing
MFNetTrafficButton.SetInterfaceNumberNotificationFunction(interfaceHasChanged);
If you are interested in being notificated if a control changes the number of the interface.
MFNetTrafficButton.SetUpdateSpeed(timerresolution, gridresolution);
Specifies how fast the grid should scroll and how often the control should update the network traffic information (both values are in milliseconds).
Downloads
Download demo project - 47 KbDownload source - 12 Kb

Comments
Brilliant!!
Posted by Legacy on 12/11/2002 12:00amOriginally posted by: Heath
Thankyou for sharing this marvellous piece of code with us. You are a very smart person.
ReplyFix for Win2k
Posted by Legacy on 09/08/2002 12:00amOriginally posted by: Michael Fatzi
Sometimes, win2k seems to automatically disable the performance query function. You can see this, if the program is unable to receive any performance information.
Fix the registry with the following procedure:
see:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Performance
Modify sub-key (DWORD):
Disable Performance Counters
to value: 0
This helps on my system.
ReplyFix for MemLeaks
Posted by Legacy on 06/12/2002 12:00amOriginally posted by: Scott
ReplyIMPORTANT CORRECTION!!!
Posted by Legacy on 03/14/2002 12:00amOriginally posted by: Gabriel Praino
Good code, great!!! Here's an important correction.
This code won't work on many PC, because
RegQueryValueEx (HKEY_PERFORMANCE_DATA,
has a bug (documented by Microsoft) on Windows NT Server/Workstation 4.0. This bug can cause the function to return incomplete information, and even cause application to stop responding. I believe this bug is not fixed by any Service Pack.
Microsoft say the UNICODE version of this function (RegQueryValueExW) should be used instead when using
HKEY_PERFORMANCE_DATA.
Here's the fix:
In MFNetTraffic.cpp, replace the two calls to RegQueryValueEx (line 131 and line 269) by:
RegQueryValueExW (HKEY_PERFORMANCE_DATA, L"510",
For more information, take a look at:
Q226371, Q259394, (MSDN October 2001)
ReplyHint / Fix
Posted by Legacy on 12/26/2001 12:00amOriginally posted by: Michael Fatzi
Hi all,
Don Kim gave me the possibility to present a solution for all machines beeing unable to display the right performance counters.
The following registry key gets changed somehow sometime when system have some problem. if you reset it, it will show all the performance counter objects you weren't be able to see before.
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Performance\Disable Performance Counters
I was not able to verify this procedure, because on my machine everything works fine (now) and the key does not exist.
Thanks to Don
Michael
ReplySimple question????
Posted by Legacy on 12/07/2001 12:00amOriginally posted by: John Miller
Hi,
This question may look stupid or simple for you folks here,
but I am still puzzled with this:
is a control (such as a Edit box or Static control) area
still the client area of the main dialog window?
When the mouse move occurs within any control box area,
it looks that the neither the WM_MOUSEMOVE nor the WM_NCMOUSEMOVE message does not get sent!
When you put a control on top of the dialog client area,
how do you capture the mouse move event WITHIN the control
area????
Hope some one would kindly point it out, thanks!
Reply
Does it support Win2K
Posted by Legacy on 11/28/2001 12:00amOriginally posted by: Will
A very interesting article, thank you. The only problem is I compile the project under Win 2K, VC6.0 SP5. When I run the program I have the popup dialog box as shown but nothing happen. Am I overlooking something?
ReplyFloat divided by zero.
Posted by Legacy on 11/14/2001 12:00amOriginally posted by: Petr Vozka
Float divided by zero. This unhandled exception i get in DrawItem method (line 241). Environment; NT4.0CZ + SP6a + VC++ 6.0 SP4.
ReplyWhy do we need the CMemDC?
Posted by Legacy on 11/10/2001 12:00amOriginally posted by: YiHai
Why do we need the CMemDC class in this case? Answer is appreciated. Anyway, this is some interesting code,i learned sth from it . Thanx.
ReplyDoesn't seem to work on 98?
Posted by Legacy on 11/09/2001 12:00amOriginally posted by: Jeff
I realize this was developed on 2000. Is there anything that can be done to make it work on 98?
Jeff
ReplyLoading, Please Wait ...