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!

Using OnCtlColor problems

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I've got an EDIT object that I'm trying to change the background color to black and the text to white. Well I've gotten it so that when you type in something...the text is white and the text background is black...but the actual EDIT background is still white and it's causing sort of a border of white around my text. If there is no text in the box...the background looks white. I've tried everything I can think of...this is what I have for my code so far:

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_EDIT_DIAL)
switch (nCtlColor)
{
case CTLCOLOR_MSGBOX:
case CTLCOLOR_EDIT:
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH) (m_brush->GetSafeHandle());
default:
;
}

m_brush is a pointer of CBrush type...
This is of course inside my OnCtrlColor function to override the default. One thought....should my m_brush be a direct member variable of my Dlg class? Any and all help/comments would be appreciated. Thanks in advance.

Niky Williams
NTS Marketing

 
I had a similar problem here I am posting the code as how I resolved it


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_ErrorEdit)
{
if (pWnd->m_hWnd == m_ErrorEdit.m_hWnd )
{
switch(m_ErrorColor)
{
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;
}

Hope this help and let me know
 
What are and where are your m_ErrorEdit and m_ErrorColor member functions defined. They don't sound familiar to me. Thanks for helping me out!

Niky Williams
NTS Marketing
 
Oh! Sorry I forgot to Mention m_ErrorEdit and m_ErrorColor
Actually that time m_ErrorEdit is derived from CEdit class
to show Error/Warnings with appropriate color. m_ErrorColor is integer defined to hold colors.
Anyhow hope this helps in resolving your problem.
 
Hmm....no luck...I'm still getting that stupid white background. Like I said, the text background when I start typing is black and the text is white like it should be. I'm programming in Win2K. Don't know if that makes a difference or not. I wouldn't think so. I'm doing something wrong and I don't know what it is. Thanks for your help. If anything else comes up that you can think of, please post it here.

Niky Williams
NTS Marketing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top