A Tiny Meter + Animated Tray Icon Class

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

A Tiny Meter + Animated Tray Icon Class

Post by calstover »

So many netmeters, none I like. I want to see what's going on with super fast refresh, but little or no CPU load. I don't care what happened 5 minutes ago, just gimme a current average speed and a byte counter. I want meaningful indications for low and high traffic. I want a sizeable window.

So its a logarithmic scale bar graph... all buffered GDI in a sizable dialog. I've only completed the top graph (downloads)... the bottom will be the same for uploads. I also plan to add tickeys for peak speed and for disk freespace. The scale can be over any range, but it's currently set by constants in the .bi file.

http://calstover.com/snews/freebasic/atinymeter/

(updated link 16-Oct-07)

compile (I'm using 0.18 beta dated June 30):
fbc -s gui netmeter3.bas netmeter3.rc

Then fire it up and go download something. Click the bmp to change adapters (if you have more than 1 enabled) and to rezero the counter. Does it work with dialup adapters? How hilarious/ignorant is my code? What would you change? Finally, can someone explain how can I insert at the beginning of an array without moving every item down one at a time? I've GOTTA be doing that wrong. (see line 495)
Last edited by calstover on Dec 25, 2007 3:33, edited 2 times in total.
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Post by DrV »

There really is no good way to insert at the beginning of an array; however, if you just think about things a bit differently, you could interpret any element as the "beginning" of the array, wrapping around when you get to the end - a circular buffer.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

You could try this to insert at the beginning of the array...

Code: Select all

Sub NetMeterStats.AddData (uiBC As UInteger, dbTS As Double)
Dim Temp(1 To NDP_MAX) As NTMTR_DATA_PT

	If (uiBC = 0) Then Exit Sub

	MoveMemory @Temp(2), @DataPts(1), SizeOf(NTMTR_DATA_PT) * (NDP_MAX-1)
	Temp(1).uiBytCnt = uiBC
	Temp(1).dbTimStp = dbTS
	MoveMemory @DataPts(1), @Temp(1),  SizeOf(NTMTR_DATA_PT) * (NDP_MAX)

	If StartTm = -1 Then ReZeroCtr()

End Sub
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

Post by calstover »

vdecampo wrote:You could try this to insert at the beginning of the array...
Thanks for that; it was just what I had in mind and had no idea how to implement... later I will build up a proper circular array object.

Another plea for help:

I'm using a dialog and GDI simply because I can't find a way to implement a standard freebasic window while properly handling the resizing and size limiting like I've done here. If I can, I'll switch before going too much further. Anybody have examples or pointers?
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

new version

Post by calstover »

I've fleshed it out some, renamed it A Tiny Meter, and posted it at my site.

http://calstover.com/snews/freebasic/atinymeter/
Voltage
Posts: 110
Joined: Nov 19, 2005 7:36
Location: Sydney, Australia
Contact:

Post by Voltage »

Cool proggy. :)

I downloaded the program from your website, but I had to rename it to an .exe ?

Anyway, after that it worked.... but I had no idea what it was doing... until I reviewed the web page.

My advice would be to label the program itself, so that the user has immediate visual feedback as to what is what. Just label it as you have the web site diagram.
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Post by Kot »

I don't know what's wrong, but it doesn't work on my computer, it eats all the processor time and doesn't even show. It's visible only in Windows Task Manager when I must kill the process because there is no other way to turn it off. WindowsXP, Avira Antivir Personal Edition, PCTools Firewall Plus.
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario

Post by axipher »

Windows XP Pro SP1 Zonealarm, AVG, Spybot

Works beautiful, nice and clean too, Zonealarm didn't even ask me to allow it or anything which is nice, possibility of minimize to tray?
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

Post by calstover »

Kot wrote:I don't know what's wrong, but it doesn't work on my computer, it eats all the processor time and doesn't even show. It's visible only in Windows Task Manager when I must kill the process because there is no other way to turn it off. WindowsXP, Avira Antivir Personal Edition, PCTools Firewall Plus.
Are you using dialup? I know the adapter checking is not very robust!
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

Post by calstover »

axipher wrote:Windows XP Pro SP1 Zonealarm, AVG, Spybot

Works beautiful, nice and clean too, Zonealarm didn't even ask me to allow it or anything which is nice, possibility of minimize to tray?
I want to, but it's not within my skill level. Yet. How is CPU usage for you? Ima add a speed setting anyway, but I'm curious.
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

Post by calstover »

Voltage wrote:Cool proggy. :)

I downloaded the program from your website, but I had to rename it to an .exe ?

Anyway, after that it worked.... but I had no idea what it was doing... until I reviewed the web page.

My advice would be to label the program itself, so that the user has immediate visual feedback as to what is what. Just label it as you have the web site diagram.
Yeah posting an exe is probably a bad idea... I should at least zip it.

I'm fighting the labeling vs cleaniliness issue. I'll add them and another switch to turn 'em off. They're not needed once you know what you're looking at.

How is the text? Should the overall size be smaller?
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

Post by calstover »

axipher wrote:Zonealarm didn't even ask me to allow it or anything


It simply checks the byte counts. Doesn't mess with the TCP/IP stack, and I wouldn't know how to do that anyway.
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario

Post by axipher »

BTW: With everything running I could (AutoCAD, Adobe Photoshop CS2, FireFox, Zonealarm, etc), it still ran smoothly at ~0-3% CPU
calstover
Posts: 68
Joined: Aug 21, 2006 16:51

Now with animated tray icon goodness

Post by calstover »

I've created a simple trayicon class, fbTrayIcon, which provides a DC you can draw on with GDI. The gizmo converts your drawing into an Icon and sends it to the system tray. (see fbtrayicon.bi)

It also sends a message to the parent window (you supply it's handle to the constructor) when mouse activity occurs on the tray icon. To see how this works, check lines 59-69 in a_tiny_meter.bas

I've wrapped that into another class, specialized for A Tiny Meter, atm_fbTrayIcon. This type simply takes two integers 0-32 and draws little progress bars on the tray icon. To make your own animated icon, you should modify this file. (see atm_fbtrayicon.bi)

You'll find these files in source code link on the project's web site:

http://calstover.com/snews/freebasic/atinymeter/

I also fixed some resource leaks. They were due to resources created before testing to see if the routine should exit. Seems fantastic now but took forever to figure out ;-)
Post Reply