Home > Software engineering >  Still cannot enter the OnTimer after the SetTimer function in MFC
Still cannot enter the OnTimer after the SetTimer function in MFC

Time:11-03

RT,
Background is trying to write a simulation robot motion platform, in order to realize the robot motion plan through the timer at intervals of about 200 ms robot movement distance,
 
//start
Void CRobotsDlg: : OnBnClickedStart ()
{
//TODO: add the control notification handler code
The SetTimer (1200, NULL);
//MessageBox (TEXT (" 111 "));
}

 
Void CRobotsDlg: : OnTimer (UINT_PTR nIDEvent)
{
//TODO: add the message handler code and/or invoke the default
The switch (nIDEvent)
{
Case 1:
MoveRobots ();
break;
}

CDialogEx: : OnTimer (nIDEvent);
}

Then the message response also added, debug, breakpoint is set on the SetTimer and MessageBox there is no problem, but may not be able to set in the switch here to,

CodePudding user response:

Is not met, the program there is no problem, other effects

CodePudding user response:

Add some code to see before the switch, can enter ontimer this function, if not into may add ontimer function is not correct

CodePudding user response:

The switch ( * nIDEvent)

CodePudding user response:

The landlord to determine add ON_WM_TIMER ()?

CodePudding user response:

refer to the second floor lang14 response:
add some code to see before the switch, can enter ontimer this function, if can't go to may not add ontimer function right


In front of the switch code also have no reaction, should be entered the OnTimer function

CodePudding user response:

reference 4 floor whx19881209 response:
considered adding ON_WM_TIMER ()?


Add ah==

CodePudding user response:

The
reference 3 floor zhao4zhong1 response:
switch ( *
nIDEvent)


Clams? What do you mean?

CodePudding user response:

UINT_PTR nIDEvent
Since nIDEvent type is a pointer to the UINT, then * nIDEvent is referred to in taking nIDEvent UINT values,

Remind: add the message map?

BEGIN_MESSAGE_MAP (CRobotsDlg CDialog)
//{{AFX_MSG_MAP (CRobotsDlg)
.
ON_WM_TIMER ()
...
//}} AFX_MSG_MAP
END_MESSAGE_MAP ()

CodePudding user response:

Void CRobotsDlg: : OnTimer ( UINT_PTR
nIDEvent)Should be changed to
Void CRobotsDlg: : OnTimer ( UINT
nIDEvent)The switch (nIDEvent)

CodePudding user response:

references 9 f zhao4zhong1 response:
void CRobotsDlg: : OnTimer ( UINT_PTR
nIDEvent)Should be changed to
Void CRobotsDlg: : OnTimer ( UINT
nIDEvent)The switch (nIDEvent)


Specially added again and again ON_WM_TIMER () to determine the added (even though the man even though
UINT_PTR changed is no use, the key still can't enter the OnTimer

CodePudding user response:

": the key is not enter OnTimer:"
WM_TIME message priority is low, have a lot of news to processing program?

CodePudding user response:

BEGIN_MESSAGE_MAP (CRobotsDlg, CDialog the Ex
//{{AFX_MSG_MAP (CRobotsDlg)
.
ON_WM_TIMER ()
.
//}} AFX_MSG_MAP
END_MESSAGE_MAP ()

CodePudding user response:

Code don't have any problem,
UINT_PTR and UINT, also is not the point, add the function of automatically, need not deliberately to change, unless Mr Into code, and then upgrade version, otherwise don't have to manage this,

Doubt your system Settings has a problem, such as some rogue software to hijack or blocked timer, another is your message is too much, and timer message level is not enough, but not usually,

CodePudding user response:

Check the SetTimer return value to see if set success, if you don't succeed, call GetLastError.

CodePudding user response:

Modify the SetTimer (1200, NULL); The inside of the id

CodePudding user response:

The
reference 11 floor schlafenhamster reply:
": the key still can't into the OnTimer:"
WM_TIME message priority is low, have a lot of news to processing program?


Seem to have a lot of message=,=is to be kept in the picture on the control circle wipe again,,, to have treatment method,

CodePudding user response:

reference 15 floor yzwyq response:
modify the SetTimer (1200, NULL); Inside the id of the


Change id no w

CodePudding user response:

"Is to be kept in a picture on the control circle and then wipe"
How to do it?

CodePudding user response:

refer to the 18th floor schlafenhamster response:
"is to be kept in the picture on the control circle and then wipe"
How to do it?


Is to draw a circle, and then obtain the background color, cover, with such big circle,

CodePudding user response:

"To keep" how to do it?

CodePudding user response:

reference schlafenhamster 20 floor response:
"to keep" how to do it?


Put in the loop, directly,

CodePudding user response:

Add in loop

Void DoEvents ()
{
MSG MSG.
//Process existing messages in the application's message queue.
//When the queue is empty, do the clean up and return.
While (: : PeekMessage (& amp; MSG, NULL, 0, 0, PM_NOREMOVE))
{//from the MSG
if (! AfxGetThread () - & gt; PumpMessage break ());
}
}
Otherwise the message was blockednullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related