
Setting Background Colour of Specific CEdit Controls
Thanks for the help.
I've now written a new OnCtlColor handler - which works !
I create a brush (not static to the handler)
COLORREF backcol = RGB(255,0,0);
RedEdit.CreateSolidBrush(backcol);
HBRUSH CBreezeJobClient::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
switch (nCtlColor)
{
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
switch (pWnd->GetDlgCtrlID())
{
case IDC_JCCLIENT:
case IDC_JCCONTACT:
case IDC_JCCLIENTQUOTE:
case IDC_JCCLIENTREF:
case IDC_JCCLIENTORDER:
pDC->SetBkColor(RGB(255,0,0));
pDC->SetTextColor(RGB(255,255,255));
hbr = (HBRUSH) RedEdit; //GetStockObject(NULL_BRUSH);
break;
default:
hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
break;
}
break;
default:
hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
}
return hbr;
Quote:
}
Works like a charm.
Thanks for the help - it pointed me in the right direction.
Duncan
Quote:
> Ajay,
> Here is the code i've got for OnCtrlColor:
> HBRUSH CBreezeJobClient::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
> {
> //HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
> // TODO: Change any attributes of the DC here
> // TODO: Return a different brush if the default is not desired
> HBRUSH hbr;
> switch (pWnd->GetDlgCtrlID())
> {
> case IDC_JCCLIENT:
> case IDC_JCCONTACT:
> pDC->SetBkColor(RGB(255,0,0));
> pDC->SetTextColor(RGB(255,255,255));
> hbr = (HBRUSH) GetStockObject(NULL_BRUSH);
> break;
> default:
> hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
> break;
> }
> return hbr;
> }
> So what is the modification i need to make to set the background of the
Edit
> control to red and text to white ?
> Many thanks for your help.
> Duncan