Add a background image to the image in vs2010

Source: Internet
Author: User

Something simple, hey

  1. Void ctestdlg: onpaint ()
  2. {
  3. If (isiconic ())
  4. {
  5. Cpaintdc DC (this); // device context used for plotting
  6. Sendmessage (wm_iconerasebkgnd, reinterpret_cast <wparam> (DC. getsafehdc (), 0 );
  7. // Center the icon in the rectangle of the Workspace
  8. Int cxicon = getsystemmetrics (sm_cxicon );
  9. Int cyicon = getsystemmetrics (sm_cyicon );
  10. Crect rect;
  11. Getclientrect (& rect );
  12. Int x = (rect. Width ()-cxicon + 1)/2;
  13. Int y = (rect. Height ()-cyicon + 1)/2;
  14. // Draw the icon
  15. DC. drawicon (X, Y, m_hicon );
  16. }
  17. Else
  18. {
  19. Cpaintdc DC (this );
  20. Crect rect;
  21. Getclientrect (& rect); // obtain the customer's size
  22. CDC memdc;
  23. Cbitmap;
  24. Cbitmap * poldmembmp = NULL;
  25. Cbitmap. loadbitmap (idb_bitmap1 );
  26. Memdc. createcompatibledc (& DC); // create a device object context
  27. Poldmembmp = memdc. SelectObject (& cbitmap );
  28. Bitmap BMP;
  29. Cbitmap. getbitmap (& BMP );
  30. Setstretchbltmode (DC, stretch_halftone); // It is said that distortion can be reduced
  31. DC. stretchblt (0, 0, rect. Width (), rect. Height (), & memdc, 0, BMP. bmwidth, BMP. bmheight, srccopy );
  32. Memdc. SelectObject (poldmembmp );
  33. Cdialogex: onpaint ();
  34. }
  35. }

Is it easy?

Add a background image to the image in vs2010

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.