News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Alternative timer demo

Started by hutch--, August 30, 2005, 04:33:25 AM

Previous topic - Next topic

hutch--

Setting a timer in Windows is an easy enough task but it not much more work to write your own timer with more flexibility and control it using standard window messages.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

hutch--

Here is the extended version, change settings on the fly with WM_COMAND messages sent with PostThreadMessage() including the timer thread priority.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Hutch,
Am I missing something?  Pressing 'Stop Timer' displays a 0 in the Title bar but none of the other buttons, except Cancel, do anything.  Neither example appears to work on XP SP2.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

hutch--

Paul,

Try out "Start Timer" and see if it starts to display 1 second intervals on the title bar. If it does click on "Fast Timer" to see if the interval rate gets a lot faster. If that works then try Stop Timer to see if it stops runing the titlebar intervals. This has just been built on win2k SP4 and I would be surprised if the mesaging system has been changed.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Hutch,
The buttons do nothing.  The Title bar message only changes if I click the Stop Timer Button.  Neither version works.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

PBrennick

Hutch,
QuoteThis has just been built on win2k SP4 and I would be surprised if the mesaging system has been changed.

I doubt if it has changed, also.  If that is the case then the switch/case macros MUST be the culprit.  I am not certain of this, though, because I just tested the switch example in your package and it works fine.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

hutch--

Paul,

Thanks, I can reproduce the problem on my win98se box so I will track it down. So far if I add a PeekMessage before the loop its partially working but thee are oter APIs that are not returning correct values or failing.

LATER : The problem on my win98se test box is that the arguments passed to the new thread in the array are being messed up by the thread. I converted the values to a global scope structure so the thread DWORD arg was not used and it works correctly.

If you have the time, would you do a test for me on xp sp2, in the proc alt_timer_thread after te arguments from the stack parameter for the thread are converted to the locals, would you test the value of any of the locals to see if they are garbage ?
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Hutch,
Setting a breakpoint after
    mov esi, args
    mov eax, [esi]
    mov interval, eax


in alt_timer_thread
shows esi or interval having a value of 0012FADC, this value is the same as in the alt_timer procedure, but this seems to be an odd value for an interval.  Is this what you want or have I mistaken your need?

Also, I moved the breakpoint to:
          case 100
            mov eax, tmsg.lParam
            mov interval, eax           ; change the interval timing on the fly
            int 3


and it never executes no matter what I do...

Paul
The GeneSys Project is available from:
The Repository or My crappy website

hutch--

Paul,

This is te version I got to work on win98se. There appeared to be no way to get the argument for the new thread to be transfered properly so I set a global structure as a transient method of transfer and it works OK. An ugly technique but will probably work OK as it is only used between the proc that starts the thread and te new thread itself.

I vaguely remember some years ago tere being a problem with threaded code but its been too long since I heard of the problem.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Hutch,
It works but it is not stable.  If I start the timer twice or if I click Fast Timer and then Slow Timer it appears to count odd seconds quickly and even seconds slowly if that makes sense to you.

Later:  The Stop Timer Button is actually a Restart Timer.

Finally:  Tests on my ME test box are pretty much the same except that clicking the Start Timer twice (which creates 2 threads) displays only even seconds (probably because it is a slower box).

Paul
The GeneSys Project is available from:
The Repository or My crappy website

PBrennick

Hutch,
Perhaps you should set a trap condition to prevent the thread from starting more than once.  This will protect against silly people such as myself who have a tendancy to double-click everything!

Paul
The GeneSys Project is available from:
The Repository or My crappy website

PBrennick

Hutch,
This version (attached) contains the trap and is stable.  All the buttons work correctly.

Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

hutch--

Thanks for testing this for me Paul, after I posted the bare working version, I disabled the start button after the thread was started and re-enabled it after the thread was stopped so that the demo would only run one thread at a time. What surprised me was the stack corruption with the pointer passed to the new thread as this was the cause of the problem but I vaguely remember this being a problem some years ago with a few Windows versions.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Farabi

Hai. I dont understand with the sleep function. If I put Sleep,20 is it mean 1000/20 or 50 time each second?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

PBrennick

Onan,
That is correct.  The proc will beacon 50 times a second.
Paul
The GeneSys Project is available from:
The Repository or My crappy website