Click to See Complete Forum and Search --> : Timers


Simon Bone
May 22nd, 1999, 07:39 AM
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

Simon Rose
May 22nd, 1999, 11:50 AM
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