我在《vc技术内幕》中看到说
只要在OnCtlColor()中添加如下代码
if(nCtlColor == CTLCOLOR_BTN)
{
pDC->SetBkColor(SetBkColor(255,0,0));
return m_hRedBrush; //已在OnInitDialog()中初始化
}可就是不行啊,CTLCOLOR_DLG就可以修改dialog底色,这是为什么?
请高手指点!
只要在OnCtlColor()中添加如下代码
if(nCtlColor == CTLCOLOR_BTN)
{
pDC->SetBkColor(SetBkColor(255,0,0));
return m_hRedBrush; //已在OnInitDialog()中初始化
}可就是不行啊,CTLCOLOR_DLG就可以修改dialog底色,这是为什么?
请高手指点!
HBRUSH CMyDataView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CRecordView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_PDNUM)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_JSNAME)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_YNAME)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_BNUM)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_GRADE)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_BJ)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_KCNAME_KCNAME)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
if(pWnd->GetDlgCtrlID()==IDC_MYDATA_KCNUM)
{
pDC->SetBkMode(TRANSPARENT);//这样还可把文字背景设为透明!
hbr = CreateSolidBrush(RGB(255,255,255));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
按钮的颜色没变化的
http://www.bestpim.net/ebook/bbs/showthread.php?s=b8c660b21ff38c5fbaffa76d8871f825&threadid=46
<
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH;<br /> // This code only works with buttons.
<br /> ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
<br />
<br /> // If drawing selected, add the pushed style to DrawFrameControl.
<br /> if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;
// Draw the button frame.
<br /> ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle); // Get the button's text.
CString strText; GetWindowText(strText); // Draw the button text using the text color red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
<br /> ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}