Solved

SetTimer

Posted on 1997-12-07
6
390 Views
Last Modified: 2012-06-27
Hi,

When setting a Timer using the API func. SetTimer,
How can you make sure that the handle of the timer you're
providing isn't already in use?
Is there a function that returns the next valid timer handle?
Something like FreeFile???

Thanks in advance
0
Comment
Question by:BabyFace
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
The SetTimer API function creates a timer, the return value is a long integer identifying the new timer.  It is unique.

There is a Timer control with VB - it's easier to use.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
whoops,

If the return value is zero, the function failed.
0
 
LVL 1

Author Comment

by:BabyFace
Comment Utility
Hi,

Perhapse I should make my question a little clearer.
Sorry.

This is the definition of SetTimer:
Declare Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

How do I find the next valid timer identifier?
because what if you did this?
SetTimer me.hwnd,1,1000,addressof Myfunc
[in another function]
SetTimer me.hwnd,1,1000,addressof MyFunc2
[destory event]
KillTimer 1
???? What about the other timer?????
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:mrmick
Comment Utility
As I said, the timer function RETURNS a long integer identifying the new timer. It is unique.  When set the timer like this:

TimerID = SetTimer me.hwnd,1,1000,addressof Myfunc

And release it:

Kill TimerID

The second argument in you're example (1) is the EVENT ID

0
 
LVL 1

Author Comment

by:BabyFace
Comment Utility
Quote:
TimerID = SetTimer me.hwnd,1,1000,addressof Myfunc
And release it:
Kill TimerID

I suppose you ment KillTimer TimerID right?
But the description of the KillTimer say that it receives a windows hwnd  and the timer identifier
not the timer handle.
So how do you find the next valid timer handle.?

0
 
LVL 8

Accepted Solution

by:
mrmick earned 30 total points
Comment Utility
Well, if you look at the SetTimer description - you'll find the following:

Return Values
If the function succeeds, the return value is an integer identifying the new timer. An application can pass this value, or the string identifier, if it exists, to the KillTimer function to destroy the timer. If the function fails to create a timer, the return value is zero.

The syntax for releasing the timer would therefore be:

KillTimer hWnd, TimerID

What makes the TimerID unique is the hWnd.  You must specify a different ID if you're going to create a second timer using the same hWnd.  In your example, 1000 would be the only timer associated with me.hwnd.




0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now