/*加入背景图片*/
BOOL CTOOLDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此加入消息处理程序代码和/或调用默认值
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);
::DeleteObject(m_hBitmap);
::DeleteDC(m_hBkDC);
}
return TRUE;
}
/*设置控件背景透明*/
HBRUSH CTOOLDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_STATIC )
{
pDC->SetBkMode(TRANSPARENT);//设置背景透明
pDC->SetTextColor(RGB(255,255,0));//设置字体为黄色
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
// TODO: 假设默认的不是所需画笔,则返回还有一个画笔
return hbr;
}
实现效果例如以下图所看到的:
转自:http://www.2cto.com/kf/201305/210038.html