CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    119

    Changing text color of radio buttons and group boxes

    OK this is stupid and probably has been answered a hundred times, but I've searched and I can't seem to find the answer.

    I have a dialog based app with a dark background. I want to set all the text in the dialog to a light color so it can be seen against the dark background. So far I've done this for most controls using this code...

    Code:
    HBRUSH CMyAppDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    	switch (nCtlColor)
    	{
    	case CTLCOLOR_BTN:
    	case CTLCOLOR_DLG:
    		return CreateSolidBrush(BACKGROUND_COLOR);
    	case CTLCOLOR_STATIC:
    		pDC->SetBkMode(TRANSPARENT);
    		pDC->SetTextColor(TEXT_COLOR);
    		return CreateSolidBrush(BACKGROUND_COLOR);
    	default:
    		return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	}
    }
    However the radio buttons and group box labels change their background color but not their text color. Am I missing something obvious here?

    Attached is a small screen shot of what I'm getting. As you can see the standard labels (i.e. Fade-in and Fade-out) change color correctly, but the group box labels and radio button text do not.

    Thanks,
    Dan
    Attached Images Attached Images  

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Changing text color of radio buttons and group boxes

    Quote Originally Posted by Dan203 View Post
    ... I have a dialog based app with a dark background. I want to set all the text in the dialog to a light color ...
    Code:
    HBRUSH CMyAppDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    	switch (nCtlColor)
    	{
    	case CTLCOLOR_BTN:
    	case CTLCOLOR_DLG:
    		return CreateSolidBrush(BACKGROUND_COLOR);
    	case CTLCOLOR_STATIC:
    		pDC->SetBkMode(TRANSPARENT);
    		pDC->SetTextColor(TEXT_COLOR);
    		return CreateSolidBrush(BACKGROUND_COLOR);
    	default:
    		return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	}
    }
    However the radio buttons and group box labels change their background color but not their text color. Am I missing something obvious here?
    Yes, you did.
    You are setting text color only for static controls (and for read-only edit boxes), not for any other types!
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2004
    Posts
    119

    Re: Changing text color of radio buttons and group boxes

    I tried setting the code to simply...

    Code:
    HBRUSH CMyAppDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    	pDC->SetBkMode(TRANSPARENT);
    	pDC->SetTextColor(TEXT_COLOR);
    	return CreateSolidBrush(BACKGROUND_COLOR);
    }
    The text color of the radio buttons and group boxes still did not change. I did some more Googling and found a few references that suggest that this might not work when using a manifest to get the newer style controls. Does anyone know if this is the case?

    Dan

  4. #4
    Join Date
    Mar 2004
    Posts
    119

    Re: Changing text color of radio buttons and group boxes

    I answered my own question. Turns out that the manifest/theme does prevent you from changing the text color of check boxes, radio button and group boxes. I'm in a bit of a hurry and didn't want to have to subclass all the controls to fix this so I simply turned off the themes on these controls using this code in OnInitDialog...

    Code:
    SetWindowTheme(GetDlgItem(IDC_RDO_BOX_TEXT)->GetSafeHwnd(), L"", L"");
    Dan

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured