Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

background color in a edit ctrl

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I'm trying to change the background color in a edit control. The help files say catch the WM_CTLCOLOREDIT message which gives you the HWND in the lParam and HDC in the wParam. The message call appears to be right. However, neither SetBkColor or SetTextColor work in this context.


case WM_CTLCOLOREDIT:
[tab]SetBkColor((HDC)wParam, RGB(0,0,0)); // doesn't work
[tab]GetClientRect(ghEdit, &cr);
[tab]FillRect((HDC)wParam, &cr, CreateSolidBrush(RGB(255,66,00)));// works but only proves the hdc is valid
[tab]break;


--Will Duty
wduty@radicalfringe.com

 
I had earlier faced similar problems here is the way by which I resolved it.
Depending on Value of m_nErrorColor I change the Background color of My Edit box for showing Warnings and Error
and here m_ErrorEditCtrl is my Edit Ctrl for showing errors. I change the back gournd of Edit Box in OnCtlColor function. GREYBRUSH,REDBRUSH,YELLOW BRUSH are defined RGB values for different colors.

HBRUSH CActiveChildDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = IOrderEntryDlg::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here

if (nCtlColor == CTLCOLOR_STATIC||nCtlColor == CTLCOLOR_EDIT)
{
if(pWnd && m_ErrorEditCtrl)
{
if (pWnd->m_hWnd == m_ErrorEditCtrl).m_hWnd )
{
switch(m_nErrorColor)
{
case 1:
pDC->SetBkColor(REDCOLOR);
break;
case 3:
pDC->SetBkColor(YELLOWCOLOR);
break;
default:

pDC->SelectStockObject(GRAY_BRUSH);
}
}
}
}

// TODO: Return a different brush if the default is not desired
return hbr;
}

 
Thanks a lot Sanjay. I'll try this.

--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top