Results 1 to 7 of 7

Thread: APITimer control 2.0

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    APITimer control 2.0

    every professional programmer said that the VB6 timer control isn't "good"(i don't know the right term) for the programs.
    is why that i build these control
    is very easy to use... like VB6 timer control... or more easy
    i accept comments, please
    Attached Files Attached Files
    Last edited by joaquim; Apr 6th, 2010 at 06:35 AM. Reason: Sorry the bad language... sorry :(
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: APITimer control 1.0

    Here are some comments.

    1. API timers do have advantages over VB timers. API timers can be windowless and the timer interval can be very large. VB timers are not windowless and max interval is a little over a minute.

    2. I would recommend you make your timer windowless too. You are creating timers in the code using hWnd of zero. If you keep your usercontrol windowed, then you should create your timer with the usercontrol's hWnd in my opinion. By assigning the timer a non-zero hWnd, the timer is automatically destroyed when the hWnd is destroyed. However, you are using the usercontrol's hWnd to send it messages, so making it windowless would require rethinking that logic.

    3. Your event is called Cicle. Is that word English? If so, it is misspelled and should be Cycle.

    4. The Interval property should do more than just save a value. If user passes 0 then the timer should stop if it is running. If user passes > 0 then the timer should stop/restart with new interval if already running or it should start if it is currently stopped. That is how the VB timer works.

    5. A major flaw with your logic. If more than one timer control is in use, only one will receive events. This is because your module is sending a message to the control that matches the MouseOverControl value in your bas module. Public variables/values in a bas modules within a usercontrol are shared among all instances of that usercontrol.

    However, in order to make your control work correctly, you would need to modify some code to allow multiple timers to call the correct usercontrol. This fix requires the timer control to stay windowed and not windowless.

    1. In the usercontrol, always use the usercontrol's hWnd with SetTimer and KillTimer.
    Do not use zero as the hWnd
    Code:
    ' Example
    lTimerId = SetTimer(UserControl.hWnd, 100&, ByVal Interval, AddressOf TimerRoutine)
    ' Example
    KillTimer UserControl.hWnd, lTimerID
    2. In the bas module
    Code:
     change from: SendMessage MouseOverControl, WM_KEYDOWN, 1000, 0
    change to: SendMessage lHwnd, WM_KEYDOWN, 1000, 0
    3. You can now remove the MouseOverControl variable from your bas module and usercontrol.
    Last edited by LaVolpe; Nov 12th, 2009 at 02:01 PM. Reason: added code examples
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: APITimer control 1.0

    hi LaVolte
    i belive that i did what you said
    thanks for the help my friend
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: APITimer control 1.0

    Here are some more comments, you may want to test it some more

    1. When interval is set to zero during design time and the TimerState is set to Started, the timer will fire when the project is run. This is because in your TimerState routine, you create the timer with an interval of zero when TimerState=TimerStart. On Win9x machines (i.e., 95/98/ME) that may turn the timer off or fail to create the timer. But on NT-based systems, the timer will automatically be set to USER_TIMER_MINIMUM which I believe is 10ms. Try it. So, I think you want to test the interval is > 0 before actually creating the timer.

    2. I was mistaken earlier when I said then when an active timer's interval changes, the timer is stopped then restarted with the new interval. Testing VB's timer, VB does not do that. VB simply calls SetTimer again and in this case if the timer id does not change:
    Quote Originally Posted by msdn
    When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.
    In other words if the interval was 5 seconds, and the interval is changed, before the 5 seconds happens, to say 30 seconds, what happens? When the prior interval of 5 seconds elapses, no event is fired. When the current interval elapses, 30 seconds, an event is fired.
    MSDN SetTimer source documentation

    Well your code doesn't quite do that and it is really up to you how you want to handle that scenario. Currently your interval does not change because you do not call the TimerState routine again from the Interval routine when lngInterval > 0.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: APITimer control 1.0

    Quote Originally Posted by LaVolpe View Post
    Here are some more comments, you may want to test it some more

    1. When interval is set to zero during design time and the TimerState is set to Started, the timer will fire when the project is run. This is because in your TimerState routine, you create the timer with an interval of zero when TimerState=TimerStart. On Win9x machines (i.e., 95/98/ME) that may turn the timer off or fail to create the timer. But on NT-based systems, the timer will automatically be set to USER_TIMER_MINIMUM which I believe is 10ms. Try it. So, I think you want to test the interval is > 0 before actually creating the timer.

    2. I was mistaken earlier when I said then when an active timer's interval changes, the timer is stopped then restarted with the new interval. Testing VB's timer, VB does not do that. VB simply calls SetTimer again and in this case if the timer id does not change:

    In other words if the interval was 5 seconds, and the interval is changed, before the 5 seconds happens, to say 30 seconds, what happens? When the prior interval of 5 seconds elapses, no event is fired. When the current interval elapses, 30 seconds, an event is fired.
    MSDN SetTimer source documentation

    Well your code doesn't quite do that and it is really up to you how you want to handle that scenario. Currently your interval does not change because you do not call the TimerState routine again from the Interval routine when lngInterval > 0.
    thanks for that information my friend
    i will change that
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: APITimer control 1.0

    This may interest you: SelfTimer.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: APITimer control 2.0

    finally i build a new APITimer version: APITimer 2.
    finally these control is:
    - compatible with Visual basic 6 timer control(you can change the timer without any code change);
    -and now i put 1 precise property for these timer be more precise.
    i acept comments and sugestions
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width