Resolve the implementation using double buffering under WTL

  • 2020-04-01 23:39:45
  • OfStack

The use of WTL CDoubleBufferImpl class can be convenient to achieve double buffering, without their own implementation of cumbersome code, not only can draw the general window, but also can draw the background of the dialog box.
The first # include < Atlframe. H >
Second, classes that require a double-buffered drawing need to be derived from CDoubleBufferImpl < > :
Class CMainDlg: public CDialogImpl < CMainDlg > The public CDoubleBufferImpl < CMainDlg > {}
It is then added to the message chain
BEGIN_MSG_MAP_EX (CMainDlg)
/ /...
    CHAIN_MSG_MAP (CDoubleBufferImpl < CMainDlg > )
END_MSG_MAP ()
And then the DoPaint function, just draw it
Void DoPaint CDCHandle (dc)
{     // draw a rectangle
        Dc. A Rectangle (0, 0, 10, 10);
}
A.
Note that since the CDoubleBufferImpl class responds to the WM_PAINT message and the WM_ERASEBKGND message, there is no need to respond in its own class.

Related articles: