How to set color for static text controls

17 03 2009

 description3

 

 

Sometimes we need to change the color of the static text on our window. Actually the default colour of the static text is black.

howcanidoit3

 

 

MFC provides a CWnd::OnCtlColor function for that. Actually this function handles the WM_CTLCOLOR messages of the window. The framework calls this member function when a child control is about to be drawn.

mycodesnippet3

 

 

HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{   
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);      
  
   if(pWnd->GetDlgCtrlID() == IDC_ST_MY_STATIC_CTRL)   
   {      
      //set the static text color to red      
      pDC->SetTextColor(RGB(255, 0, 0));   
   }      
  
   // TODO: Return a different brush if the default is not desired   
   return hbr;
}

mynote4

 

 

If you want to do it in the Win32 application just handle the message WM_CTLCOLORSTATIC .

Advertisements

Actions

Information

One response

13 10 2014
Praveen

Thanks…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: