// TODO: Change any attributes of the DC here pDC->SetTextColor (RGB (255, 255 ,0)); //前景色 pDC->SetBkColor (RGB (0,0,0)); //背景色 // TODO: Return a different brush if the default is not desired return hbr; }
可是我想给每一个Check Box设置不一样颜色的名称,有没有简单一点的语句可以直接用的?
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here if(pWnd->GetDlgCtrlID()==IDC_CHECK1) { pDC->SetTextColor (RGB (255, 255 ,0)); //前景色1 pDC->SetBkColor (RGB (0,0,0)); //背景色1 } if(pWnd->GetDlgCtrlID()==IDC_CHECK2) { pDC->SetTextColor (RGB (0, 255 ,0)); //前景色2 pDC->SetBkColor (RGB (0,0,255)); //背景色2 } ...... // TODO: Return a different brush if the default is not desired return hbr; }
switch (pWnd->GetDlgCtrlID()) { case IDC_CHECK1: pDC->SetTextColor (RGB (255, 255 ,0)); break; //前景色1 case IDC_CHECK2: pDC->SetTextColor (RGB (0, 255 ,255)); break; //前景色2 // ......} // TODO: Return a different brush if the default is not desired return hbr; }
m_check.SetDlgItemText(strname);
UpdateData(false);
谢谢:)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pDC->SetTextColor (RGB (255, 255 ,0)); //前景色
pDC->SetBkColor (RGB (0,0,0)); //背景色
// TODO: Return a different brush if the default is not desired
return hbr;
}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here
if(pWnd->GetDlgCtrlID()==IDC_CHECK1)
{
pDC->SetTextColor (RGB (255, 255 ,0)); //前景色1
pDC->SetBkColor (RGB (0,0,0)); //背景色1
}
if(pWnd->GetDlgCtrlID()==IDC_CHECK2)
{
pDC->SetTextColor (RGB (0, 255 ,0)); //前景色2
pDC->SetBkColor (RGB (0,0,255)); //背景色2
}
......
// TODO: Return a different brush if the default is not desired
return hbr;
}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch (pWnd->GetDlgCtrlID())
{
case IDC_CHECK1: pDC->SetTextColor (RGB (255, 255 ,0)); break; //前景色1
case IDC_CHECK2: pDC->SetTextColor (RGB (0, 255 ,255)); break; //前景色2
// ......}
// TODO: Return a different brush if the default is not desired
return hbr;
}
在对话框类里面自己定义一个函数吗?
在NewWindowsMessages中选择WM_CTLCOLOR 然后点AddandEdit按钮,就OK了