CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2001
    Posts
    60

    Add timer to my class (my class does not derived form MFC)

    Hi GURU!

    How to add timer to my class (my class does not derived form MFC).

    class MyClass{
    }



    Thank You.
    Sorry for bad English.

  2. #2
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    324
    You can use SetTimer and KillTimer, but this functions need your class has a window and a message loop to handle a WM_TIMER message.

  3. #3
    Join Date
    Jul 2002
    Location
    Connecticut, U.S.
    Posts
    275
    Phogang,

    I would look at ::SetTimer(...). Reading the MSDN documentaion, I'm guessing the only requirement is that your application has a message pump. If your class has a single instance, you should be able to kludge something using ::SetTimer.

    Good luck,
    John Flegert

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    There is no need for a message loop to use a timer

    You just havew to use one that is not based on messages!

    A WaitableTimer is directly supported via Windows API calls.

    Check MSDN for a starting point into the documentation.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Dec 2002
    Posts
    104
    Use this function
    CreateTimerQueue();

    CreateTimerQueueTimer(
    PHANDLE phNewTimer,
    HANDLE hTimerQueue,
    WAITORTIMERCALLBACK pfnCallback,
    PVOID pvContext,
    DWORD dwDueTime,
    DWORD dwPeriod,
    ULONG dwFlags);

    with callback WAITORTIMERCALLBACK pfnCallback,

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    A TimerQueue may or may not be prefferable over a WaitableTimer. Only the user knows for sure...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Add timer to my class (my class does not derived form MFC)

    Originally posted by Phogang
    Hi GURU!

    How to add timer to my class (my class does not derived form MFC).
    To be able to answer the question you would need to provide some more information. Does your application has a message loop? Which resolution of the timer do you need? What is the purpose of the timer?

    Based on these information one can provide a fully satisfying answer. Without these it is more-likely just guessing in the dark...

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

Featured