What's the fastest way to update an owner drawn control?

73 views Asked by At

I have an owner drawn control which displays data. The data changes over time. I need to find a fast way to continuously update the control.

I tried using timers, but the problem is that the timer alone runs at maximum of 65 frames per second. And if control's paint method takes time, the fps becomes quite low.

I tried requesting update (InvalidateRect) from control's paint method, this way it repaints the control hundreds of times per second, however the rest of the UI doesn't work properly (e.g. buttons not updated, tooltips are frozen, etc).

What's the proper way to update an owner drawn control as fast as possible, still keeping the UI responsive?

P. S. I need this to work with GDI, so I can't use OpenGL/Direct3D to display my data.

1

There are 1 answers

0
Jonathan Potter On BEST ANSWER

If you want to update it literally as fast as possible, run a message loop that doesn't wait for input. If you continue to process messages the UI will stay responsive but when there aren't any messages your control will continue to update.

Psuedo-code:

while (!fQuit)
{
    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        DispatchMessage(&msg);
    RepaintControl();
}

Depending on how your control is implemented, the "repaint" function might be as simple as:

RedrawWindow(hwndControl, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);

If you find this bogs your machine down too much (although with multi-core it should be ok) or is updating too quickly, you could use a waitable timer to get a higher-resolution update while still yielding control at times. See Using Waitable Timer Objects for details on waitable timers.