I have done some tests with QueryPerformanceCounter and got strange results.
It seems that my simple program refreshes slowly (about 40ms) when it doing nothing, but when I put RedrawWindow with RDW_INVALIDATE message it refreshes and works very fast (about 1ms)
Please look at the examples:
{…}
double PCFreq = 0.0;
__int64 now = 0, start = 0;
LARGE_INTEGER li;
PCFreq = double(li.QuadPart)/1000;
AllocConsole( );
freopen("CONOUT$", "wb", stdout);
double delay;
while (GetMessage (&messages, NULL, 0, 0))
{
QueryPerformanceCounter(&li);
now = li.QuadPart;
if ( double(now - start) / PCFreq >= 40)
{
**// painting !!!**
cout << double(now - start) / PCFreq << "\n";
start = now;
}
// !!!!!!
**RedrawWindow(hwnd, NULL, NULL, RDW_VALIDATE);**
TranslateMessage(&messages);
DispatchMessage(&messages);
}
FreeConsole( );
{…}
When the RedrawWindow(hwnd, NULL, NULL, RDW_VALIDATE); is in main loop I can obtain exacly 40ms or even 5ms, but without RedrawWindow(hwnd, NULL, NULL, RDW_VALIDATE); the condition if ( double(now – start) / PCFreq >= 40) is entering no faster than 45-50 ms….
My question is:
How can I avoid RedrawWindow(hwnd, NULL, NULL, RDW_VALIDATE); function but keep fast refreshing. When Iam using RedrawWindow(hwnd, NULL, NULL, RDW_VALIDATE); my interface (buttons, windows) not displays.
THANKS!
GetMessage does not return unless there is a message in the message queue. By calling RedrawWindow, you are putting a Message in the queue every single iteration of the loop. Use PeekMessage instead of GetMessage: