MinnisotaFreezing
Programmer
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
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