Add a background image in MFC and make the control background transparent

Source: Internet
Author: User

/* Add a background image */
BOOL CTOOLDlg: OnEraseBkgnd (CDC * pDC)
{
// TODO: add the message processing program code and/or call the default value here
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, 700,610, 700,610, m_hBkDC, SRCCOPY );
: DeleteObject (m_hBitmap );
: DeleteDC (m_hBkDC );
}

Return TRUE;
}

/* Set the control background to transparent */
HBRUSH CTOOLDlg: OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx: OnCtlColor (pDC, pWnd, nCtlColor );
 
If (nCtlColor = CTLCOLOR_STATIC)
{
PDC-> SetBkMode (TRANSPARENT); // sets the background transparency.
PDC-> SetTextColor (RGB (255,255, 0); // set the font to yellow
Return (HBRUSH): GetStockObject (NULL_BRUSH );
}

// TODO: if the default paint brush is not required, another paint brush is returned.
Return hbr;
}

 

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.