1. 程式人生 > >CFromView視圖中的Static text控件透明

CFromView視圖中的Static text控件透明

mfc cview視圖

在文框視圖框架中,視圖上的static控件的透明和CDialog類有所不同。代碼如下:

HBRUSH CMainView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

	if(CTLCOLOR_STATIC == nCtlColor)//這一行不同
	{
		pDC->SetBkMode(TRANSPARENT);
		return   (HBRUSH)::GetStockObject(NULL_BRUSH);  
	}

	//CString str;
	//str.Format(_T("%d\n"),pWnd->GetDlgCtrlID());
	//TRACE(str);
	return hbr;
}

在判斷static控件的ID時,不是用某個具體控件的ID,而是CTLCOLOR_STATIC,表示一類控件。


CFromView視圖中的Static text控件透明