Question the OnTimer function in MFC

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

void CChildView::OnTimer(UINT_PTR nIDEvent)
    // TODO: Add message handler code here and/or call default values.
    if (nIDEvent == 0 && _play == true) {
    //  //  _ballCenter.x += 10;


In this way, when the OnTimer function is declared in MFC, a factor called nIDEvent is generated, and what is the role of the factor?

c++ mfc

2022-09-20 10:53

1 Answers

To use a timer, the SetTimer function is used to set the timer, where the returned value is nIDEvent, which is used as the identifier of the timer.

For example, if you install 3 timers,

UINT_PTR timer1=SetTimer(1, 1000, NULL); // 1 second timer
UINT_PTR timer2=SetTimer(2,2000,NULL); // 2-second timer
UINT_PTR timer3=SetTimer(3,300, NULL); // 0.3 second timer

In the OnTimer function, compare whether nIDEvent is timer1, timer2, or timer3 and process it according to the type of timer.

2022-09-20 10:53

If you have any answers or tips

© 2022 pinfo. All rights reserved.