+ Reply to Thread
Results 1 to 2 of 2

Thread: How to change foreground color of static box in MFC Dialog box?

  1. #1

    How to change foreground color of static box in MFC Dialog box?

    How to change foreground color of static box in MFC

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    This can be done using ON_WM_CTLCOLOR message.

    Example:

    Code:
    class CMyDialog : public CDialog
    {
    public:
           afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    }
    
    BEGIN_MESSAGE_MAP(CMyDialog , CDialog)
    	//{{AFX_MSG_MAP(CMyDialog )
    	ON_WM_CTLCOLOR()
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    HBRUSH CMyDialog ::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	
            //You must have an IDC_STATIC static control in your dialog.
    	if (pWnd->GetDlgCtrlID() == IDC_STATIC)
    	{
    		pDC->SetTextColor(RGB(0, 255, 255));
    	}
    
    	return hbr;
    }
    Hope this helps.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts