March 29, 2024, 07:56:07 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Binary Clock Update

Started by GWS, July 29, 2014, 07:45:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

July 29, 2014, 07:45:47 PM Last Edit: July 31, 2014, 08:01:08 PM by GWS
Hi folks,

I've done a small update of the binary clock program, that allows ESC or Q to quit the program, and redraws the screen if another program like Notepad, opens above it.

Egil points out that if Windows is focussed on another program, the clock does not update.

This is because the program uses DX window update messages to update the time. So if you are working in another program, the time is locked - it updates again as soon as you close the other program and focus returns to the clock.

Best wishes, :)

Graham
Tomorrow may be too late ..

LarryMc

Quote from: GWS on July 29, 2014, 07:45:47 PM
Egil points out that if Windows is focussed on another program, the clock does not update.

You can fix that.
Right after your initial call to update when the program is started add this line
starttimer w,1000
then down in the handler for window w add this
  case @idtimer
update

right after where you currently call update.

Now the clock updates whether it has focus are not.
The clock is updating as I am typing this post.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Hi Larry,

Thanks for the suggestion ..  :)

I've made the changes and uploaded the amended version.

Strange though - I had tried the Timer method as being the most usual way of controlling updating.

I got an unusual error when I ran it that I'd never seen before - from Norton AntiVirus of all things.
It said that one or more of my CPU's was exhibiting unusual usage (100%) - and closed the program down.

I thought maybe it was some weird interaction between Direct X messages and the normal window timer messages.

So I went with just the DX update messages which worked, as long as the window had the focus. All very odd.

Anyway, I've changed back to the simple Timer method and it seems to be working now - no messages from Norton so far.

Isn't programming fun .. ::)

All the best, :)

Graham
Tomorrow may be too late ..

LarryMc

Just noticed on my computer:

with the timer code I suggested:
if the clock has focus it uses 51-52% of CPU time
if clock doesn't have focus the CPU drops to 2-3%

appears my suggested fix wasn't a good fix after all.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

oops.
I just ran the program without my timer fix
I get the same exact result as in my previous post.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

That's very strange - I'm now getting <1% CPU usage using the Timer method ..  :)

How can it be so unstable .. I'll just keep checking it - but it seems OK here at the moment.

Graham  :)
Tomorrow may be too late ..

GWS

I've gone back to using the DirectX update signal to update the clock. :)

Normally, a DX window would be full-screen, and so giving another window the focus would not arise.
It works fine, so I'll leave it at that I think.

Best wishes, :)

Graham
Tomorrow may be too late ..

GWS

Hi,

I think I've found the problem - or non-problem. :)

It's DirectX.   ::)

If you try either the Lines, or DirectX 1 example programs, running in a window - you will see the CPU usage jump up.

Full screen is harder to check, because it's hard to get the Windows Task Manager to show over a full window, but it also is using a lot of CPU time.

So it looks as if any Direct X program will be making heavy use of the CPU  ::)

What it's doing I've no idea, and I don't suppose Microsoft will have said anything about it. I will check though.  Bring back good old DOS. ;D

Best wishes, :)

Graham

Tomorrow may be too late ..

GWS

Well there's lots of discussion on the Net about DirectX using lots of CPU time.

Comments like:

'Without an explicit frame capping technique in place, a directx app will use 100% of the processor, rendering as many frames per second as possible.'  â€"  GSerg  Nov 27 '13 at 16:07

'the high system cpu usage comes from the Thread which zeros the free memory (ntkrnlmp.exe!KeZeroPages) so that it can be used again.'

'Put some 'Sleep' into the loop'.

But otherwise no useful answers ..  ::)

I'll try the 'sleep' idea .. :)

Graham
Tomorrow may be too late ..

GWS

OK, that did it  :)

I put


declare "kernel32",Sleep(msec:int),int


.. in the declarations, and Sleep 500 (half a second) at the end of the Update routine.

No sign of any CPU activity now.

Of course this program has very little activity, changing only as each minute passes.

For a game though, with constant user interaction, Sleep might not be the best option unless quite low time values like 10 msec are used.  Something to check out next time I try to make a game. :)

Best wishes,

Graham

Tomorrow may be too late ..

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Just been bringing all this together ..  :)

I've kept Larry's use of the Timer to guard against loss of focus, since the clock stopped if only DXUpdate timing was used.

I found it was necessary to keep the DXUpdate message as well, because of CPU usage problems if that was left out.

The Sleep function is also needed to reduce the CPU usage. I've reduced the sleep time to only 1 msec because otherwise, if another window is opened, the screen refresh is too slow.

Also, I've changed the window to a dragable, nocaption window. The normal window was a bit clumsy, and the system window close 'X' didn't work properly.

Seems to be working OK now. The clock window can be dragged around, but not re-sized. It also needs to have the focus for ESC or q to exit the program.

Best wishes, :)

Graham

Tomorrow may be too late ..

aurelCB

well
people something is very wrong here...
i still cannot detect what it is but i will.. ;)