ArticleDirectory
-
- Cdoublebufferimpl in wtl
- References
In a self-painted window, sometimes flashes. Why is there a flickering phenomenon? BecauseProgramYou need to clear the display area with the background color when painting the window, and then draw it again. Because of the large contrast between the two, they will be captured by the human eyes, and the feeling will flash.
The dual buffer is to first make a picture in the memory and then copy it directly to the screen. This contrast is relatively small, so you don't feel the flash.
Cdoublebufferimpl in wtl
There are ready-made dual-buffer implementation in wtl, which can be easily used to achieve the effect.
Cdoublebufferimpl is in atlframe. h.
1. First inherited from cdoublebufferimpl
ClassTctrl:PublicCsf-wimpl<Tctrl>,PublicWtl::Cdoublebufferimpl<Tctrl> // Inherit the double buffer class
2. Because wm_erasebkgnd and wm_paint messages have been processed in the double buffer classCode. Then, you can add dual-buffer message processing.
Begin_msg_map(Tctrl)// Message_handler (wm_paint, onpaint)Chain_msg_map(Wtl::Cdoublebufferimpl<Tctrl>)End_msg_map()
3. Add a dopaint function. The function declaration is as follows:
VoidDopaint(Cdchandle DC);
4. Move the code in the original onpaint function to dopaint. Note that the original cpaintdc needs to use the cdchandler parameter instead.
VoidTctrl::Dopaint(Cdchandle DC){// Cpaintdc DC (m_hwnd );
DC. moveTo (XX... )
}
OK. compile it.
References
Method of Drawing with VC without blinking (dual buffering technology)
Http://hi.baidu.com/lovefqing/blog/item/3f86cdb6cc5c75f830add174.html
Approaching WTL--GDI
Http://blog.iceyer.net/walk_up_to_wtl_gdi_part
Basic principle of dual-buffering in Visual C ++
Http://www.builder.com.cn/2007/1016/558583.shtml