timer while dragging a window

BlitzPlus Forums/BlitzPlus Programming/timer while dragging a window

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I only have crappy 56k line here, however, to lower the regular 2-monthly 200$+ phonebill, a company offers a better deal: you buy a fixed amount of phonehours and that's all. In my case, I have 100 hours for 50$ per month. Day or night doesn't make a difference..

Anyway, ofcourse, you can't take unused hours to the next month, and if you exceed the 100hour barrier, you gotta pay extra. Ofcourse, these companies want you to exceed since they can get more $ then.., so, logically they won't tell you how many hours you already used..

After I tried a one-month solution by writing down all used time in notepad, here's my hacky B+ solution.. when you go online, press 'start' and when you disconnect, press 'stop'.

However.. the timer doesn't update when you drag the app-window around.. how do I fix this?


sw=ClientWidth(Desktop())
sh=ClientHeight(Desktop())

app=CreateWindow("Counter",(sw/2)-70,(sh/2)-40,126,80,0,1)
quit=False
panel=CreatePanel(0,0,130,80,app):SetPanelColor panel,128,160,192:SetGadgetLayout panel,1,0,1,0
start=CreateButton("start",4,4,40,24,panel)
disconnect=CreateButton("stop",48,4,40,24,panel)
minimize=CreateButton("_",96,6,20,20,panel)

timerfile$="c:\My Documents\CS_TBL_counter.dat"

f=ReadFile(timerfile$)

If Not f
	f=WriteFile (timerfile$)
	WriteLine f,0
	CloseFile f	
	f=ReadFile(timerfile$)
Else
	seconds=ReadLine$(f)
	CloseFile f
EndIf


DisableGadget disconnect

startlabel=CreateLabel(seconds+"  ( "+secs2time(seconds)+" )",4,32,112,20,panel,3)

Repeat WaitEvent()

	If EventID()=$803
		If EventSource()=app
			f=WriteFile(timerfile$)
			WriteLine f,seconds
			CloseFile f
			quit=True
		EndIf
	EndIf
	
	If EventID()=$401
		If EventSource()=start
			timer=CreateTimer(1)
			DisableGadget start
			EnableGadget disconnect
		EndIf

		If EventSource()=disconnect
			If timer FreeTimer timer
			f=WriteFile(timerfile$)
			WriteLine f,seconds
			CloseFile f
			
			DisableGadget disconnect
			EnableGadget start
			
		EndIf

		If EventSource()=minimize
			MinimizeWindow app
		EndIf

	EndIf
	
	If EventID()=$4001

		If EventSource()=timer
			seconds=seconds+1
			SetGadgetText startlabel,seconds+"  ( "+secs2time(seconds)+" )"
		EndIf

	EndIf

Until quit End


Function secs2time$(s)
	hours= s / 3600
	mins = (s / 60) Mod 60
	secs = s Mod 60
	Return addzero(hours,3)+":"+addzero(mins,2)+":"+addzero(secs,2)
End Function

Function addzero$(s$,l)
	s$=RSet$(s$,l)
	s$=Replace$(s$," ","0")
	Return s$
End Function