[WM] use double buffering to draw on cstatic

Source: Internet
Author: User

I thought about it for a long time. I didn't think of a good name. I 'd like to name it for the moment.

 

Native programming, it seems that there is no good choice except painting. in fact, I chose static controls instead of painting. I don't think there is any essential difference between painting on other controls and static controls. (I just think static controls are simple enough and can achieve my goal)
OK. Let's talk about the painting first. The only thing that needs to be paid attention to is the problem of the flash screen. The dual buffer is used to prevent the flash screen. How can this problem be solved?
1. Prevent background painting. I need to draw the background by myself.
2. Create a memdc. All images are completed on memdc.
3. Copy the painted items to DC (using bitblt)
At this point, the most essential content has been introduced, and the following is just a sample. There is nothing in this sample (SWEAT )...

 

 

// Register the erasebkgnd and paint begin_message_map (mystatic, cstatic) values () on_wm_paint () end_message_map () // header file class mystatic: Public cstatic {declare_dynamic (mystatic) public: mystatic (); Virtual ~ Mystatic (); protected: afx_msg bool onerasebkgnd (CDC * PDC) {return true;} afx_msg void onpaint (); declare_message_map () PRIVATE: void paintonmemdc (crect client, CDC * pmemdc) ;}; // implement implement_dynamic (mystatic, cstatic) mystatic: mystatic () {} mystatic ::~ Mystatic () {} void mystatic: onpaint () {cpaintdc DC (this); cpaintdc * PDC = & DC; crect client; getclientrect (& client); CDC m_memdc; if (! M_memdc.m_hdc) {cbitmap m_memmap; m_memdc.createcompatibledc (PDC); m_memmap.createcompatiblebitmap (PDC, client. width (), client. height (); m_memdc.selectobject (& m_memmap); m_memmap.deleteobject (); m_memdc.setbkmode (transparent);} paintonmemdc (client, & m_memdc); PDC-> setbkmode (transparent ); PDC-> bitblt (client. left, client. top, client. width (), client. height (), & m_memdc, 0, 0, srccopy); m_memdc.deletedc ();}

 

Draw here:

 

 
Void mystatic: paintonmemdc (crect client, CDC * pmemdc) {// draw it here}

You just need to draw it in paintonmemdc, and you don't need to care about anything else. Of course you can also take this stuff out ..

 

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.