在文框视图框架中,视图上的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,表示一类控件。

CStatic控件两次设置文字,会重影,解决方法如下:

CRect rt;
m_staTitle.GetWindowRect(&rt);
ScreenToClient(&rt);
InvalidateRect(rt);