Virtual Developer Workshop: Containerized Development with Docker

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.


1. Copy files

To use this control in your project, simply copy the two classes
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:

This initializes the control to monitor the interface given. You can obtain this value by calling the MFNetTraffic::GetNetworkInterfacesCount() method.

Sets the type of the traffic to monitor. Possible values are:

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).


Download demo project - 47 Kb
Download source - 12 Kb


  • Brilliant!!

    Posted by Legacy on 12/11/2002 08:00am

    Originally posted by: Heath

    Thankyou for sharing this marvellous piece of code with us. You are a very smart person.

  • Fix for Win2k

    Posted by Legacy on 09/08/2002 07:00am

    Originally 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:

    Modify sub-key (DWORD):
    Disable Performance Counters
    to value: 0

    This helps on my system.

  • Fix for MemLeaks

    Posted by Legacy on 06/12/2002 07:00am

    Originally posted by: Scott

    at around line 198 in trafficbutton.cpp, CMemDC *memDC = new CMemDC(pDC); is called but it's not cleaned up so at the end of the if statment put a delete [] memDC; and in the destructor put: 

    if (TrafficStats)
    delete [] TrafficStats;

    to clean up the memory allocated for the stat's

    All the best,


    Posted by Legacy on 03/14/2002 08:00am

    Originally posted by: Gabriel Praino

    Good code, great!!! Here's an important correction.

    This code won't work on many PC, because


    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

    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)

  • Hint / Fix

    Posted by Legacy on 12/26/2001 08:00am

    Originally 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


  • Simple question????

    Posted by Legacy on 12/07/2001 08:00am

    Originally posted by: John Miller

    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

    Hope some one would kindly point it out, thanks!

  • Does it support Win2K

    Posted by Legacy on 11/28/2001 08:00am

    Originally 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?

  • Float divided by zero.

    Posted by Legacy on 11/14/2001 08:00am

    Originally 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.

  • Why do we need the CMemDC?

    Posted by Legacy on 11/10/2001 08:00am

    Originally 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.

  • Doesn't seem to work on 98?

    Posted by Legacy on 11/09/2001 08:00am

    Originally posted by: Jeff

    I realize this was developed on 2000. Is there anything that can be done to make it work on 98?


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date