When using GDI + to fill the background, it often does not work.

Source: Internet
Author: User

It does not work when you execute GDI + to fill the background in ondraw. I do not know why

Graphics graphics (PDC-> getsafehdc (); bitmap BMP (m_imgrec.width (), m_imgrec.height ()); // The memory bitmap graphics grbmp (& BMP); solidbrush backbrush (RGB (255,255,255); grbmp. fillrectangle (& backbrush, 0, 0, m_imgrec.width (), m_imgrec.height (); // initializes the memory bitmap background graphics. drawimage (& BMP, m_imgrec.left, m_imgrec.top, m_imgrec.width (), m_imgrec.height (); // The second step draws the memory bitmap of the same screen size to the screen.

The original intention of the program is to initialize the customer area to white, but after the execution, the customer area is transparent, not white, and the filling operation does not have any effect. I wonder if someone can know the reason.

If this is not the case, we can use GDI in combination with GDI +.

Create memdc and cbitmap resources, use memdc to fill directly, and then create the memory DC's GDI + object graphics grbmp (memdc. getsafehdc (); Use this object to draw a picture

CDC memdc; cbitmap bm; memdc. createcompatibledc (PDC); BM. createcompatiblebitmap (PDC, m_imgrec.width (), m_imgrec.height (); memdc. selectObject (& BM); memdc. fillrect (& m_imgrec, & m_backbrush); // fill in the background graphics grbmp (memdc. getsafehdc (); // create the memory DC's GDI + object grbmp. drawimage (m_pbmp, nwidth, nheight); // drawing PDC-> bitblt (, m_imgrec.width (), m_imgrec.height (), & memdc, srccopy); // The memory DC is drawn to the screen.

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.