CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Timers

  1. #1
    Join Date
    May 1999
    Posts
    1

    Timers

    Can anybody point me in the direction of an online example of how to set up a timer in VC++. I'm using a dialog-based interface which doesn't seem to have a m_hWnd member that is required for use with the SetTimer and KillTimer calls. I expect the answer is probably simple - It's just that I have very little experience in VC++ (V.5).

    Thanks


  2. #2

    Re: Timers

    Hi,

    All CWnd derivatives have m_hWnd, including CDialog, therefore, any CDialog derivatives, including your own application dialog classes.

    To access it, you would do (within your CDialog class where you want to create the timer):

    HWND hwnd = GetSafeHwnd();



    If you only need a simple timer object within your CDialog class, then do the following to create it:
    At top of implementation (.cpp) file:

    #define ID_MYTIMER WM_USER+100



    Then where you want to create the timer (maybe your OnInitDialog():

    SetTimer(ID_MYTIMER, <YOUR_INTERVAL>, NULL);



    Now override OnCommand and add the following:

    if(wParam == ID_MYTIMER)
    {
    // do your stuff
    }



    Hope this helps you,

    Simon

    PS: dont forget to kill your timer when your app quits


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