SetTimer Function
The SetTimer function creates a timer with the specified time-out value.
This is a small example that will explain you how to use timer function in vc++
Step 1: Create a sample MFC project.
Step 2: create a member variable in the dialog class .h file
Example, UINT m_nTimerID;
Step 3: In the constructor initialize the timer variable
m_nTimerID = 0;
Step 4: In the OnInitDialog function call settimer function
SetTimer(m_nTimerID, 5000, NULL);
Step 5: Write a handler for WM_TIMER message and write your code..
Example , AfxMessageBox(L"Hai");
Step 6: Create a button that will kill the timer
KillTimer(m_nTimerID);
Now when the application is launched , once in 5 seconds the message window "Hai" will appear .
If you want to stop the timer then call killTimer to kill the timer.
Wednesday, November 12, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment