Use WaitKey or Sleep Problem in MFC [closed]

asked 2018-07-10 04:00:48 -0500

chuliqiang gravatar image

We use MFC to play a video.


1.We can not use waitkey and sleep in main(UI) thread.waitkey and sleep will block main(UI) thread.

2.If we not use waitkey and sleep,how can i control video playing with different FPS?

Possible solution:

1.Can we update UI and video output in other thread(I think it is not a good idea)?

2.Waitkey or sleep in main(UI) (I think it is not a good idea)?

3.Should we PostMessage from other thread to UI thread(is it the best solution)?Can message guarantee the refresh interval?

4.Use timer to refresh UI,problem:We can not check timer is stop when stop video playing. Error example:(begin kill Timer => stop video playing => update video UI thread background=> timer update UI thread background => timer end)=>(I worry but not testing this case in my app,is it possible?)


The function waitKey() waits for a key event infinitely (when delay <= 0) or for delay milliseconds, when it is positive. If the FPS is equal to 20, then you should wait 0,05 seconds between the consecutive frames. So put waitKey(50) after imshow() and it will be displayed at normal speed.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by berak
close date 2018-07-10 04:02:23.712564


we also can't help you with mfc problems here, sorry.

berak gravatar imageberak ( 2018-07-10 04:02:53 -0500 )edit