Page 1 of 1

Windows 11 : Panel Gadget / same background color

Posted: Fri Jan 26, 2024 10:29 am
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.

Re: Windows 11 : Panel Gadget / same background color

Posted: Fri Jan 26, 2024 4:16 pm
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.

Re: Windows 11 : Panel Gadget / same background color

Posted: Mon Jan 29, 2024 8:24 am
by tatanas
Hi jacdelad,

Sorry I don't undestand how I can do it with SetWindowTheme().
Could you edit my example please ?

Re: Windows 11 : Panel Gadget / same background color

Posted: Mon Jan 29, 2024 10:05 am
by jacdelad
Copy the command just after you created the panel (and replace with your variable/command). No need for reskinning then.

Re: Windows 11 : Panel Gadget / same background color

Posted: Mon Jan 29, 2024 2:20 pm
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.

Re: Windows 11 : Panel Gadget / same background color

Posted: Mon Jan 29, 2024 5:01 pm
by jacdelad
Oh ok. Then you should take a look at ChrisR's ObjectTheme module: https://www.purebasic.fr/english/viewto ... bjecttheme

Re: Windows 11 : Panel Gadget / same background color

Posted: Mon Jan 29, 2024 5:08 pm
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

Re: Windows 11 : Panel Gadget / same background color

Posted: Mon Jan 29, 2024 5:17 pm
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())

Re: Windows 11 : Panel Gadget / same background color

Posted: Wed Jan 31, 2024 8:27 am
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).