{
//TODO: Add your the control notification handler code here
The UpdateData (true);//refresh parameter
Dmc_set_pulse_outmode (m_Card, m_nXaixs, 0);//set the pulse output mode
Dmc_set_profile (m_Card m_nXaixs, m_nSpeedmin m_nSpeedmax, m_nAcc, m_nDec, 500);//set the speed curve
Dmc_set_homemode (m_Card m_nXaixs, m_nPositive m_nLowspeed, m_nHome, 1);//set back to zero way
Dmc_home_move (m_Card m_nXaixs);//back to zero action
While (dmc_check_done (m_Card, m_nXaixs)==0)//determine the current state of shaft takes a long time
{
AfxGetApp () - & gt; PumpMessage ();
GetDlgItem (IDC_BUTTON1) - & gt; The EnableWindow (false);
}
GetDlgItem (IDC_BUTTON1) - & gt; The EnableWindow (true);
The UpdateData (false);
}
I am this AfxGetApp () - & gt; PumpMessage (); After understanding is that when entering the while, in order to prevent blocking the current thread, unable to respond to other operations, plus AfxGetApp () - & gt; PumpMessage () to handle the message; I don't know whether that is to understand, the Internet search the information about the message pump, there is nothing wrong with feeling I understand, ask me company, said it was of no use function, said this function is used to intercept the message, I don't feel right, asked the people, he told me that this function function and thread hang sleep, feeling in elaborate me, I wish to consult everybody a great god,
CodePudding user response:
http://blog.163.com/dingmz_frcmyblog/blog/static/217304023201342751342435/This is an article that I find, I also checked,
PumpMessage have the effect of the message pump, its principle is to use the GetMessage or PeekMessage function reads the message one by one from the message queue, and then make the necessary processing before sending out,
From the perspective of your code
While (dmc_check_done (m_Card, m_nXaixs)==0)//determine the current state of shaft takes a long time
{
AfxGetApp () - & gt; PumpMessage ();
GetDlgItem (IDC_BUTTON1) - & gt; The EnableWindow (false);
}
Your very time-consuming operation in dmc_check_done function, then you use AfxGetApp here () - & gt; PumpMessage (); Is does not work, if not use multithreading, your GUI interface will be stuck,
I don't know whether dmc_check_done function you write, I am here the simple understanding for the SLEEP ();
I personally understand PumpMessage should be given just a little role in the following situations:
While (10000000000000)//perform many times, causing long timescales
{
AfxGetApp () - & gt; PumpMessage ();
Dosomething ();//the function itself is not time consuming
}
Dosomething function, time is not long, but to be executed many times, the interface will be stuck, this time, you are in a loop, using PumpMessage to prevent interface is jammed
This is my PumpMessage functions, applications of understanding
CodePudding user response:
You say dmc_check_done function time consuming, in fact you can treat it as a SLEEP, if dmc_check_done is written by yourself, and have a "circular wait" process, so you can put PumpMessage in the "circular wait" process, can achieve the purpose of youCodePudding user response:
i=0;While (i> 10000000000000)//perform many times, causing long timescales
{
AfxGetApp () - & gt; PumpMessage ();
Dosomething ();//the function itself is not time consuming
i++;
}
Write too casual,,,
CodePudding user response:
Dmc_check_done is not I write, is to buy ray chandrasekhar, the LIB, they provide dmc_check_done is query of motor origin signal state and high real-time requirements, if thread hangs in SLEEP words, back to the origin is not allowed to, fear of the signal to the thread but they hung up, I am very grateful to your reply