// TODO: Change any attributes of the DC here int id = pWnd->GetDlgCtrlID(); if(nCtlColor== CTLCOLOR_STATIC ) { switch(id) { case IDC_STATIC: pDC->SetBkMode(TRANSPARENT); hbr=(HBRUSH)GetStockObject(HOLLOW_BRUSH); default: break; } }
// TODO: Return a different brush if the default is not desired return hbr; }
你重载所有子控件的OnPaint,用你对话框的DC
你重载所有子控件的OnPaint,用你对话框的DC,自己计算好区域,拷贝过去就好了litbox/listctrl/treectrl我的都实现透明了
{
CRect rect;
GetClientRect(&rect);
CBitmap m_pBmp;
BITMAP bm;
CDC dcMem;
m_pBmp.LoadBitmap(IDB_SKY);
m_pBmp.GetBitmap(&bm);//得到位图尺寸
dcMem.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMem.SelectObject(&m_pBmp);pDC->SetStretchBltMode(COLORONCOLOR);//这个模式不设置的话会导致图片严重失真
pDC->StretchBlt(0,0,rect.Width() ,rect.Height(),
&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);dcMem.SelectObject(pOldBitmap);
return TRUE;//return CBkDialog::OnEraseBkgnd(pDC);
}HBRUSH CDlgSysSetup::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch( nCtlColor)
{
case CTLCOLOR_EDIT:
return (HBRUSH)GetStockObject(WHITE_BRUSH); //设置背景色
case CTLCOLOR_DLG:
case CTLCOLOR_BTN:
case CTLCOLOR_STATIC:
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH); //设置背景色
default:
return (HBRUSH)GetStockObject(HOLLOW_BRUSH); //设置背景色}}
这个例子我试了,不能通过
HBRUSH CxxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
int id = pWnd->GetDlgCtrlID();
if(nCtlColor== CTLCOLOR_STATIC )
{
switch(id)
{
case IDC_STATIC:
pDC->SetBkMode(TRANSPARENT);
hbr=(HBRUSH)GetStockObject(HOLLOW_BRUSH);
default:
break;
}
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
如果控件类型少 就都重载了 这个肯定没问题 但显然挺麻烦的。