Sunday, March 23, 2008

How can I avoid flickering that occurs when using a custom paint routine with a common control?

Common controls sometimes draw to the screen without sending a WM_PAINT message. An example is expanding items in a TreeView control. This can cause flickering if you are using a custom painting routine. To solve this problem you can surround the call with WM_SETREDRAW switches, which disable any drawing to the window.
SendMessage(hwndTV, WM_SETREDRAW, FALSE, 0);
TreeView_Expand(hwndTV, hItem, TVE_EXPAND);
SendMessage(hwndTV, WM_SETREDRAW, TRUE, 0);

No comments: