TabControl and Form Backgrounds

Started by Larry Heber, September 15, 2006, 03:32:33 PM

Previous topic - Next topic

Larry Heber

After doing quite a bit of searching I can't seem to find my answer.

I am using a the tab control, the issue is when the forms that are linked to the tabs are displayed they are using the form background color property rather then tab background color (the theme color).   Is there a way to get the forms to use the theme color without manually adjusting the background color on form.  The reason would be if a user is looking at the tabs on non-theme display then color would be incorrect on that display, as it is now on a theme display.

One thought was to make the forms background transparent, but I wasn't sure if that was possibility or how I would go about doing that.

Thanks in advance for any help!

TechSupport

I am working on a solution for this right now.... I will post again ASAP with (hopefully) a workable solution.

I only recently switched my development to WinXP (from Win2K) and I am finding that this Theme issue is a royal pain in the butt for many of my applications.  :)

TechSupport

OK, are you ready for this? :)  This may be somewhat of a dirty hack but it does appear to work okay on my computer. Let me know how you fare.

Add the following function to your project:

Function IsThemeActive() As Long
  Local hLib As Dword
  Local pProc As Dword
  Local lRes As Long
 
  hLib = LoadLibrary("UxTheme.dll")
  If hLib Then
     pProc = GetProcAddress(hLib, "IsThemeActive")
     If pProc Then
        Call Dword pProc Using IsThemeActive To lRes
        Function = lRes
     End If
     FreeLibrary hLib
  End If
End Function


In the WM_CREATE of the main form that your tab control is on, add the following code (this is based on the TabControl sample program that ships with FireFly):

Function FRMMAINFORM_WM_CREATE ( _
                              hWndForm As Dword, _  ' handle of Form
                              ByVal UserData As Long _  'optional user defined Long value
                              ) As Long

  Local nBackColor As Long
 
  If IsThemeActive Then
     nBackColor = &HFCFCFE  ' this appears to be the color of a selected tab
 
  Else
     ' Use the "traditional" background color
     nBackColor = GetSysColor( %COLOR_BTNFACE )
  End If
 
  FF_Control_SetColor HWND_FRMGENERAL, -1, nBackColor
  FF_Control_SetColor HWND_FRMOPTIONS, -1, nBackColor
  FF_Control_SetColor HWND_FRMENVIRONMENT, -1, nBackColor
 
End Function


I'm sure that there may be better ways to do this using the built in Windows theming functions but FireFly handles a lot of the background painting itself so manually setting the colors is a pretty good solution, I think.

Larry Heber

Quote from: TechSupport
I'm sure that there may be better ways to do this using the built in Windows theming functions but FireFly handles a lot of the background painting itself so manually setting the colors is a pretty good solution, I think.

This solution worked perfectly.  I started messing arround with the colors, but couldn't seem to find the "property" page color.

Thank you for all your help!

Roger Garstang

Works until you switch themes.  I believe there is a function using the same approach to get the tab color...then you have the actual tabs where the labels are too...which are even more fun when you add images to them.

May end up having to go back to inline stuff FF used before for themes instead of manifest files/resource manifest...only complete and with the ability to disable them on a per app basis where even title bars are drawn without them, etc.  Then figuring out the code on the VB site to make things work better.  PS...is the new FF going to have the finished code for the colored dropdowns and code gen fixes I sent ya too?  I guess with the new redraw thing in another thread it may need to be subclassed code for those...and maybe for XP too since those and Radio buttons, etc don't draw colors.  We can't forget the autobutton style being made available too so we can have toggle buttons.  Lots of fun stuff with controls!

I got a new job and ditched Linux for the time being too, so whenever you need help, or beta testers...let me know!

Larry Heber

Dang didn't think of that, do you by chance have or now were I can get a peek at the function that gets the current tab color?

FF_Control_GetColor gets this odd looking gray color when I run it.

Roger Garstang

I sent Paul the link sometime back.  It's on one of my backup CDs.  One of the VB code sites that has code for an app that manually draws all XP theme styles...even without the actual controls.  It would be pretty cool once converted to PB.  At the time I had too many things going on and just disable themes to finish my apps, but it would be nice to get it working.  I'll have to find it and see if I can do anything with it on the weekends.