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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with CView::OnCtlColor

Status
Not open for further replies.

MinnisotaFreezing

Programmer
Jun 21, 2001
120
0
0
KR
I am trying to change the text and color of a static control and group control. I found some info in MSD that should do it, but it doesn't work. I declare the message map, so I get into the overriden function, but it doesn't change any colors. It will change the text color and background color of an edit box. Here is my code.

HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
CBrush m_brush(RGB(255,0,0));
// Call the base class implementation first! Otherwise, it may
// undo what we're trying to accomplish here.
HBRUSH hbr = CView::OnCtlColor(pDC, pWnd, nCtlColor);

// Are we painting the IDC_MYSTATIC control? We can use
// CWnd::GetDlgCtrlID() to perform the most efficient test.
if (pWnd->GetDlgCtrlID() == IDC_GUESSED)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkColor(RGB(0,0,255));

// Set the background mode for text to transparent
// so background will show thru.
// pDC->SetBkMode(TRANSPARENT);

// Return handle to our CBrush object
hbr = m_brush;
}

return hbr;
}

From what I understand, if I return a colord brush, it will creat the control with that color. However, I can't get this to work. I've scoured the internet and MSDN, but Im getting nothing but grey hairs. Does anyone have any ideas?
I've also tried embeding the CView:: call in the if statment so it only fires when its not my ctrl im testing for, but it still doesn't work. Also, this code sample is for a dialog box in MSDN, but I modified it for a view, since OnCtlColor is inhearited from CWnd, it shoudln't matter.

CJB
 
I have found that when trying to print text on a dc with a certain back mode that it is best to get the Client dc. As when i did it with a CDC variable it did nothing

e.g Instead of using the CDC passed do
CClientDC dc(this)
dc.SetTextColor(RGB(255, 0, 0));
dc.SetBkColor(RGB(0,0,255));
dc.SetBkMode(TRANSPARENT);



Don't know if this is barking up the right tree
[ponytails]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top