Commit 8620bd5a authored by Alexander Alekhin's avatar Alexander Alekhin

highgui(win32): improve waitKey() timeout condition

- use cv::getTickCount() instead of Win32 GetTickCount()
- process message queue before timeout exit
parent 7175f257
...@@ -1965,7 +1965,8 @@ static void showSaveDialog(CvWindow* window) ...@@ -1965,7 +1965,8 @@ static void showSaveDialog(CvWindow* window)
CV_IMPL int CV_IMPL int
cvWaitKey( int delay ) cvWaitKey( int delay )
{ {
int time0 = GetTickCount(); int64 time0 = cv::getTickCount();
int64 timeEnd = time0 + (int64)(delay * 0.001f * cv::getTickFrequency());
for(;;) for(;;)
{ {
...@@ -1973,13 +1974,13 @@ cvWaitKey( int delay ) ...@@ -1973,13 +1974,13 @@ cvWaitKey( int delay )
MSG message; MSG message;
int is_processed = 0; int is_processed = 0;
if( (delay > 0 && abs((int)(GetTickCount() - time0)) >= delay) || hg_windows == 0 )
return -1;
if( delay <= 0 ) if( delay <= 0 )
GetMessage(&message, 0, 0, 0); GetMessage(&message, 0, 0, 0);
else if( PeekMessage(&message, 0, 0, 0, PM_REMOVE) == FALSE ) else if( PeekMessage(&message, 0, 0, 0, PM_REMOVE) == FALSE )
{ {
int64 t = cv::getTickCount();
if (t - timeEnd >= 0)
return -1; // no messages and no more time
Sleep(1); Sleep(1);
continue; continue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment