Home > Software engineering >  How to realize operation with the stop button in MFC
How to realize operation with the stop button in MFC

Time:09-24


I want to be in the run button capture video capture, four window always cycle, then when press the stop button to stop the screenshots, but has no way to stop button, what should I do

CodePudding user response:

In the processing of messages add message loop cycle, refer to the following:
 # pragma comment (lib, "user32") 
# include & lt; stdio.h>
# include & lt; Time. H>
# include & lt; Sys/timeb. H>
# include & lt; Windows. H>
Char datestr [16].
Char timestr [16].
Char MSS [4].
Void the log (char * s) {
* struct tm now;
Struct timeb TB;

Ftime (& amp; TB);
Now=localtime (& amp; TB. Time);
Sprintf (datestr, "% d % % 4 d - 02-02 d", now - & gt; Tm_year + 1900, now - & gt; Tm_mon + 1, now - & gt; Tm_mday);
Sprintf (timestr, "02 02 02 % d: % d: % d", now - & gt; Tm_hour, now - & gt; Tm_min, now - & gt; Tm_sec);
Sprintf (MSS, "% 3 d", TB. Millitm);
Printf (" % s % s. % s % s ", datestr, timestr, MSS, s);
}
VOID CALLBACK myTimerProc1 (
HWND HWND,//handle of the window for the timer messages
UINT uMsg,//WM_TIMER message
UINT idEvent,//timer identifier
DWORD dwTime//the current system time
) {
The log (" In myTimerProc1 \ n ");
}
VOID CALLBACK myTimerProc2 (
HWND HWND,//handle of the window for the timer messages
UINT uMsg,//WM_TIMER message
UINT idEvent,//timer identifier
DWORD dwTime//the current system time
) {
The log (" In myTimerProc2 \ n ");
}
Int main () {
int i;
MSG MSG.

SetTimer (NULL, 0, 0100 myTimerProc1);
SetTimer (NULL, 0, 0200 myTimerProc2);
for (i=0; I<20; I++) {
Sleep (500);
The log (In the main "\ n");
If (GetMessage (& amp; MSG, NULL, 0, 0)) {
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}

}
return 0;
}
//the 2012-07-26 17:29:06. 375 In the main
//the 2012-07-26 17:29:06. 875 In myTimerProc1
//the 2012-07-26 17:29:07. 375 In the main
//the 2012-07-26 17:29:07. 875 In myTimerProc2
//the 2012-07-26 17:29:08. 375 In the main
//the 2012-07-26 17:29:08. 375 In myTimerProc1
//the 2012-07-26 17:29:08. 875 In the main
//the 2012-07-26 17:29:08. 875 In myTimerProc1
//the 2012-07-26 17:29:09. 375 In the main
//the 2012-07-26 17:29:09. 890 In myTimerProc2
//the 2012-07-26 17:29:10. 390 In the main
//the 2012-07-26 17:29:10. 390 In myTimerProc1
//the 2012-07-26 17:29:10. 890 In the main
//the 2012-07-26 17:29:10. 890 In myTimerProc1
//the 2012-07-26 17:29:11. 390 In the main
//the 2012-07-26 17:29:11. 890 In myTimerProc2
//the 2012-07-26 17:29:12. 390 In the main
//the 2012-07-26 17:29:12. 390 In myTimerProc1
//the 2012-07-26 17:29:12. 890 In the main
//the 2012-07-26 17:29:12. 890 In myTimerProc1
//the 2012-07-26 17:29:13. 390 In the main
//the 2012-07-26 17:29:13. 890 In myTimerProc2
//the 2012-07-26 17:29:14. 390 In the main
//the 2012-07-26 17:29:14. 390 In myTimerProc1
//the 2012-07-26 17:29:14. 890 In the main
//the 2012-07-26 17:29:14. 890 In myTimerProc1
//the 2012-07-26 17:29:15. 390 In the main
//the 2012-07-26 17:29:15. 890 In myTimerProc2
//the 2012-07-26 17:29:16. 390 In the main
//the 2012-07-26 17:29:16. 390 In myTimerProc1
//the 2012-07-26 17:29:16. 890 In the main
//the 2012-07-26 17:29:16. 890 In myTimerProc1
//the 2012-07-26 17:29:17. 390 In the main
//the 2012-07-26 17:29:17. 890 In myTimerProc2
//the 2012-07-26 17:29:18. 390 In the main
//the 2012-07-26 17:29:18. 390 In myTimerProc1
//the 2012-07-26 17:29:18. 890 In the main
//the 2012-07-26 17:29:18. 890 In myTimerProc1
//the 2012-07-26 17:29:19. 390 In the main
//the 2012-07-26 17:29:19. 890 In myTimerProc2

CodePudding user response:

The main thread is blocked!

CodePudding user response:

Stresses the time-consuming operations in a background thread operation such as figure, with a variable tags start/stop, don't block the message loop

CodePudding user response:

Multiple Threads in the User Interface of http://msdn.microsoft.com/zh-cn/library/ms810439.aspx

CodePudding user response:

Video capture four window screenshot work need to put into a separate thread; By setting a semaphore, click "run" button to make the thread started, click the "stop" button to stop the thread,

CodePudding user response:

Run infinite loop blocking the stop button, please join in the loop body DoEvents function (https://blog.csdn.net/worldy/article/details/15028745)
  • Related