C ++ snacks: use dual Buffering in wtl to avoid blinking

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.