MFC joins background image and makes control background transparent

Source: Internet
Author: User
Tags set background

/* Add background image */
BOOL ctooldlg::onerasebkgnd (cdc* pDC)
{
 //TODO: Add Message Handler code here and/or call default value
 cdialog::onerasebkgnd (pDC);
 HBITMAP   m_hbitmap;
 HDC           m_hbkdc;
 m_hBitmap   =  :: loadbitmap (:: getmodulehandle (NULL), makeintresource (idb_bitmap2)) ;
 m_hBkDC     =  :: CreateCompatibleDC (pdc-> m_hdc);
 if (m_hbitmap   &&   m_hbkdc)
 {
 :: SelectObject (m_hbkdc,m_ hbitmap);
 :: StretchBlt (pdc-> m_hdc,0,0,700,610,m_hbkdc,0,0,700,610,srccopy);
 ::D Eleteobject (m_hbitmap);
 ::D Eletedc (m_hbkdc);
 }

Return TRUE;
}

/* set control background transparent */
Hbrush ctooldlg::onctlcolor (cdc* pDC, cwnd* pWnd, UINT nctlcolor)
{
Hbrush HBR = Cdialogex::onctlcolor (pDC, pWnd, nctlcolor);

if (nctlcolor = = Ctlcolor_static)
{
Pdc->setbkmode (TRANSPARENT);//set Background Transparency
Pdc->settextcolor (RGB (255,255,0));//set the font to yellow
return (hbrush):: Getstockobject (null_brush);
}

TODO: Assuming that the default is not the desired brush, return a brush
Return hbr;
}

Achieve effects such as what you see:

Transferred from: http://www.2cto.com/kf/201305/210038.html



MFC joins background image and makes control background transparent

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.