CTabCtrl and WinXP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: CTabCtrl and WinXP

  1. #1
    Join Date
    Mar 2001
    Location
    Albuquerque, NM
    Posts
    12

    CTabCtrl and WinXP

    All of my CStatic controls that sit on a CTabCtrl have a different background color than the CTabCtrl.

    What is going on and how do I fix it?

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060
    That's a bug in the Windows XP theming engine.

    A workaround is to handle WM_CTLCOLOR and return a holow brush IIRC.

  3. #3
    Join Date
    Mar 2001
    Location
    Albuquerque, NM
    Posts
    12
    Originally posted by Marc G
    That's a bug in the Windows XP theming engine.

    A workaround is to handle WM_CTLCOLOR and return a holow brush IIRC.
    What is the IIRC after hollow brush?

    I tried the following (based on your suggestion):
    Code:
    HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	
    	if(nCtlColor == CTLCOLOR_STATIC)
    	{
    		hbr = m_HollowBrush;
    	}
    	
    	return hbr;
    }
    m_HollowBrush is created like this in the dialog's constructor:
    Code:
    LOGBRUSH	lb;
    lb.lbColor = lb.lbHatch = NULL;
    lb.lbStyle = BS_HOLLOW;
    m_HollowBrush.CreateBrushIndirect(&lb);
    This code does not work. The text in the static control still has the wrong background.
    If I add
    Code:
    pDC->SetBkColor(RGB(255,255,255));
    to OnCtlColor(), it is almost okay, but the CTabCtrl background is not pure white.

    Any suggestions?

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    I've never had any problems with the CStatic background colours in XP.

    I do take it you're using a manifest to define the version of ComCtrl32 you're using ?

    Are you using VC6 or VC7 ?

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  5. #5
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Oh sorry. I've only used CStatics on a property page. They work fine.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060
    IIRC = if i remember correctly

    In your CMyDlg::OnCtlColor you also have to add:
    Code:
    pDC->SetBkMode(TRANSPARENT);

  7. #7
    Join Date
    Mar 2001
    Location
    Albuquerque, NM
    Posts
    12

    CTabCtrl and WinXP

    Whew!!
    Got it working fine now. The solution turned out to be so simple that I am embarassed I didn't get it on my own. Soon I'll be giving up my crayons for colored pencils though!

    A hollow brush and transparent background mode did the trick.
    Code:
    HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	
    	if(nCtlColor == CTLCOLOR_STATIC)
    	{
    		hbr = m_HollowBrush;
    		pDC->SetBkMode(TRANSPARENT);
    	}
    	
    	return hbr;
    }
    I am using a manifest, and VC6.
    Thanks for all the help,
    Geno

  8. #8
    Join Date
    Apr 2004
    Posts
    7

    Question What about other controls?

    Oh yes, it shows statics really right with hollow brush, but what about other controls? I am using check & option boxes, spin and group box, all of them shown wrong and using hollow brush doesn't fixed it. I've got black nonrendered rectangles instead of controls or nothing at all...
    I'd be happy to get some help on this subject. Thanks

    P.S. I've tried it on VC7 and VC6+manifest with the same result...

  9. #9
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    I use XP and I have not noticed a problem. However I use the classic style, not XP styles. However since this is the first time I have read anyone having that problem, I sure have doubts whether it is a bug. A static control is supposed to be a different color than other controls. I think an edit control gets the same color as a static control when the edit control has the read-only style.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  10. #10
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Marc G
    That's a bug in the Windows XP theming engine.
    If it is a bug then it is documented by Microsoft. What KB article documents it?
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  11. #11
    Join Date
    Apr 2004
    Posts
    7
    Originally posted by Sam Hobbs
    I use XP and I have not noticed a problem. However I use the classic style, not XP styles.
    Yeah, if I set it to classic style - the tabs bg color is the same as bg color of dialog, statics, spin and all other controls, so then I have no problem, but when I use theme - tabs are painted using some light color which differs from color of all other controls. The method, described above, helped me to fix only static text appearance. I've attached screenshot, so you can see exactly what I mean.
    Thanks
    Attached Images Attached Images  
    Last edited by Lexis; April 9th, 2004 at 03:57 PM.

  12. #12
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    So which one of the two samples is an example of the problem?
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  13. #13
    Join Date
    Apr 2004
    Posts
    7
    Originally posted by Sam Hobbs
    So which one of the two samples is an example of the problem?
    First one - is a default result of placing controls on CTabCtrl, and second - after use of hollow brush. You can see different background colors on a first image, that's the problem and it resolved for static text control using hollow brush, but other controls got black area where background is not rendered at all. I could simply set bg brush color to bg color of the CTabCtrl, but GetBkColor() is not valid for CTabCtrl, so can't find way to retreive this value.

  14. #14
    Join Date
    Mar 2001
    Location
    Albuquerque, NM
    Posts
    12

    Wierd backgrounds

    Wow, Lexis' dialog is ugly!

    I resolved my CStatic contol background as noted previouslym but I never had a problem with any of the other controls. Group boxes and check boxes work perfectly well in all my apps.

    I have seen some very wierd behavior like this when using the TRANSPARENT style set. I just ried to duplicate it in one of my apps but was unable to do so. I recommend you look at that and turn OFF the transparent style.

    The only other thing I can think of is that the manifest file is screwed up.

    Geno

  15. #15
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060
    Originally posted by Sam Hobbs
    If it is a bug then it is documented by Microsoft. What KB article documents it?
    I don't think there is a KB about it, but it certainly is a bug in the theming engine. The following article describes the problem in detail and gives a solution:
    http://www.codeproject.com/wtl/ThemedDialog.asp

Page 1 of 2 12 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center