Sunday, May 4, 2008

Change color of CStatic object.

.h file
(add this function to your class)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
// Called to change color of text
.cpp file
(add this to your message map)
ON_WM_CTLCOLOR()
(add this to the file too)
HBRUSH CYourDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call original functions
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Create a blue color
COLORREF textColor = RGB(0, 0, 255);

// Set text color
if (pWnd->GetDlgCtrlID() == yourstatic)
{
pDC->SetTextColor(textColor);

}

// Return result of original function
return hbr;

}

No comments: