Windows 11 : Panel Gadget / same background color

Windows specific forum
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Windows 11 : Panel Gadget / same background color

Post by tatanas »

Hi,

On Windows 10 I can get the PanelGadget background color with

Code: Select all

GetSysColor_(#COLOR_WINDOW)
. Then I can change the background color of another gadget (TextGadget for example) inside this Panel.
If I do the same on Windows 11, the TextGadget background stay grey. GetSysColor_(#COLOR_WINDOW) doesn't get the right color.

I achieved what I want with this trick (get pixel color from Panel background) but its pretty ugly...

Code: Select all

firstpass = #True

If OpenWindow(0, 200, 200, 200, 200, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
	
	PanelGadget(1, 0, 0, 200, 200)
	AddGadgetItem(1, -1, "Panel 1")
	TextGadget(2, 50, 50, 100, 100, "", #PB_Text_Border)
	CloseGadgetList()
	
	BackGroundPanelColor = GetSysColor_(#COLOR_WINDOW)
	SetGadgetColor(2, #PB_Gadget_BackColor, BackGroundPanelColor)
	
	Repeat
		Event = WaitWindowEvent()
		
		If Event = #PB_Event_CloseWindow
			Quit = 1
		EndIf
		
		If firstpass And OSVersion() >= #PB_OS_Windows_11 And IsWindowVisible_(GetWindow_(WindowID(0), #GW_HWNDPREV))
			firstpass = #False
			StartDrawing(WindowOutput(0))
			BackGroundPanelColor = Point(GadgetX(1, #PB_Gadget_WindowCoordinate) + 20, GadgetY(1, #PB_Gadget_WindowCoordinate) + 20)
			; Circle(GadgetX(1, #PB_Gadget_WindowCoordinate) + 20, GadgetY(1, #PB_Gadget_WindowCoordinate) + 20, 3, #Red)
			StopDrawing()
			SetGadgetColor(2, #PB_Gadget_BackColor, BackGroundPanelColor)
		EndIf
		
	Until Quit = 1
	
EndIf

End
Do you have a better solution ?

Thanks for your time.
Windows 10 Pro x64
PureBasic 6.20 x64
User avatar
jacdelad
Addict
Addict
Posts: 2004
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Windows 11 : Panel Gadget / same background color

Post by jacdelad »

I do it the other way round and recolor the panel back to "normal":

Code: Select all

SetWindowTheme_(GadgetID(#Panel),@"",@"")
...saves a lot of time used for reskinning.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: Windows 11 : Panel Gadget / same background color

Post by tatanas »

Hi jacdelad,

Sorry I don't undestand how I can do it with SetWindowTheme().
Could you edit my example please ?
Windows 10 Pro x64
PureBasic 6.20 x64
User avatar
jacdelad
Addict
Addict
Posts: 2004
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Windows 11 : Panel Gadget / same background color

Post by jacdelad »

Copy the command just after you created the panel (and replace with your variable/command). No need for reskinning then.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: Windows 11 : Panel Gadget / same background color

Post by tatanas »

Ok, I undestand this method but I can't use it.
Actually I'm using a module which create a toolbar and apply a color to its background. The color is retrieved through GetSysColor_().
So I have to change it during creation with the background color of my panel.
Even if I use SetWindowTheme() to remove the theme, the background color of the toolbar will still be modified by the default color implemented in the module.
That's why I'm looking for a solution to get the default background color of a panel to apply this color to my toolbar.
Windows 10 Pro x64
PureBasic 6.20 x64
User avatar
jacdelad
Addict
Addict
Posts: 2004
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Windows 11 : Panel Gadget / same background color

Post by jacdelad »

Oh ok. Then you should take a look at ChrisR's ObjectTheme module: https://www.purebasic.fr/english/viewto ... bjecttheme
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: Windows 11 : Panel Gadget / same background color

Post by RASHAD »

1- There is no way to color the Panel Gadget direct
Workaround :
you can use Container Gadget covering the panel area first then color the container
2- To get the color for any part of the window and it's objects you need some time after creation

Code: Select all

If OpenWindow(0, 10, 10, 640, 480, "Main Window",#PB_Window_SystemMenu) 
    PanelGadget(0, 10, 10, 600, 400)
    AddGadgetItem(0, -1, " TAB 1 ")      
      TextGadget(1, 10, 100, 300, 20, "test")
    CloseGadgetList()
    Repeat 
      Select WaitWindowEvent()       
        Case #PB_Event_CloseWindow
          Quit = 1
          
        Case #PB_Event_Repaint
          hdc = GetWindowDC_(GadgetID(0))
          Color = GetPixel_(hdc,GadgetX(0,#PB_Gadget_ScreenCoordinate)+2,GadgetY(0,#PB_Gadget_ScreenCoordinate)+2)
          ReleaseDC_(WindowID(0),hdc)
          SetGadgetColor(1, #PB_Gadget_BackColor, Color)
          SetGadgetColor(1, #PB_Gadget_FrontColor, $0000FF)
          
        Case #PB_Event_Gadget
            Select EventGadget()
            EndSelect
      EndSelect       
    Until Quit = 1
 EndIf
Egypt my love
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Windows 11 : Panel Gadget / same background color

Post by fryquez »

If the app is themed, than the color comes from a PNG inside aero theme.
Maybe this is what you want.

Code: Select all

Procedure GetPanelColor()
  
  Protected Image, hOutput, hDC, hTab, iColor, rc.rect 
  
  Image = CreateImage(#PB_Any, 32, 32) 
  If Image
    hOutput = ImageOutput(Image)
    If hOutput
      hDC = StartDrawing(hOutput)
      If hDC
        hTab = OpenThemeData_(0, "Tab")
        If hTab
          rc\right = 32
          rc\bottom = 32
          DrawThemeBackground_(hTab, hDC, 10, 0, @rc, 0)
          iColor = Point(16, 16) 
          CloseThemeData_(hTab)          
        EndIf
        StopDrawing() 
      EndIf
    EndIf
    FreeImage(Image)
  EndIf
  
  ProcedureReturn iColor
  
EndProcedure

Debug Hex(GetPanelColor())
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: Windows 11 : Panel Gadget / same background color

Post by tatanas »

Thank you for all your answers.

The one proposed by fryquez is what I need. It get the right color on Windows 11 (and lower).
Windows 10 Pro x64
PureBasic 6.20 x64
Post Reply