Page 1 of 1
Setting a container gadget color affects ALL containers
Posted: Fri Oct 29, 2004 8:30 pm
by halo
I am using this code to change the background color of a container gadget. Unfortunately, it affects all container gadgets, even the ones in the parent application window. How do I resolve this?
Code: Select all
Procedure SetGadgetColor(object,r,g,b)
hBrush.l=CreateSolidBrush_(RGB(r,g,b))
SetClassLong_(object,#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(object,0,#TRUE)
EndProcedure
Thanks.
Posted: Sat Oct 30, 2004 12:19 am
by Sparkie
SetClassLong_(object,#GCL_HBRBACKGROUND,hBrush) changes the background brush for all gadgets (ContainerGadgets) that are of the class (PureContainer). You could either create your own class for each ContainerGadget and then use the SetClassLong_() or you can try this code.
I'm not sure if this is the preferred method, but it does work here with minimal testing on WinXPhome and PB 3.92.
Code: Select all
blueBrush.l = CreateSolidBrush_(RGB(0, 0, 255))
greenBrush.l = CreateSolidBrush_(RGB(0, 255, 0))
Global blueBrush, greenBrush
Procedure myWindowCallback(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_ERASEBKGND
container.RECT
If IsGadget(0) And hwnd = GadgetID(0)
container\left = 0
container\top = 0
container\right = GadgetWidth(0)
container\bottom = GadgetHeight(0)
FillRect_(wparam, container, blueBrush)
result = 1
EndIf
If IsGadget(2) And hwnd = GadgetID(2)
container\left = 0
container\top = 0
container\right = GadgetWidth(2)
container\bottom = GadgetHeight(2)
FillRect_(wparam, container, greenBrush)
result = 1
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 400, 230, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget,"Colored ContainerGadgets") And CreateGadgetList(WindowID(0))
SetWindowCallback(@myWindowCallback())
ContainerGadget (0, 10, 10, 380, 100)
; --> This sets a #Null brush for all ContainerGadgets
SetClassLong_(GadgetID(0), #GCL_HBRBACKGROUND, 0)
ButtonGadget(1, 90, 40, 180, 20,"Button in Blue Container")
CloseGadgetList()
ContainerGadget (2, 10, 120, 380, 100)
ButtonGadget(3, 90, 40, 180, 20,"Button in Green Container")
CloseGadgetList()
Repeat
event = WaitWindowEvent()
Select event
Case #PB_EventSizeWindow
ResizeGadget(0, -1, -1, WindowWidth()-20, -1)
ResizeGadget(2, -1, -1, WindowWidth()-20, -1)
EndSelect
Until event = #PB_Event_CloseWindow
DeleteObject_(blueBrush)
DeleteObject_(greenBrush)
EndIf
Posted: Sat Oct 30, 2004 12:47 am
by halo
Thank you!
No offense, but you PB programmers write the worst spaghetti code I have ever seen. If I wrote code like that, I would spend more time formatting than thinking:
Code: Select all
Global blueBrush
Global greenBrush
blueBrush=CreateSolidBrush_(RGB(0,0,255))
greenBrush=CreateSolidBrush_(RGB(0,255,0))
Procedure myWindowCallback(hwnd, msg, wparam, lparam)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_ERASEBKGND
container.RECT
Select hwnd
Case GadgetID(0)
container\right=GadgetWidth(0)
container\bottom=GadgetHeight(0)
FillRect_(wparam,container,blueBrush)
result=1
Case GadgetID(2)
container\right=GadgetWidth(2)
container\bottom=GadgetHeight(2)
FillRect_(wparam,container,greenBrush)
result=1
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
win=OpenWindow(0,0,0,400,230,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget,"Colored ContainerGadgets")
CreateGadgetList(win)
ContainerGadget (0,10,10,380,100)
SetClassLong_(GadgetID(0),#GCL_HBRBACKGROUND,0)
ButtonGadget(1,90,40,180,20,"Button in Blue Container")
CloseGadgetList()
ContainerGadget (2,10,120,380,100)
ButtonGadget(3,90,40,180,20,"Button in Green Container")
CloseGadgetList()
SetWindowCallback(@myWindowCallback())
Repeat
Select WaitWindowEvent()
Case #PB_EventSizeWindow
ResizeGadget(0,-1,-1,WindowWidth()-20,-1)
ResizeGadget(2,-1,-1,WindowWidth()-20,-1)
Case #PB_Event_CloseWindow
DeleteObject_(blueBrush)
DeleteObject_(greenBrush)
End
EndSelect
ForEver
Posted: Sat Oct 30, 2004 1:21 am
by Sparkie
halo wrote:Thank you!
No offense, but you PB programmers write the worst spaghetti code I have ever seen. If I wrote code like that, I would spend more time formatting than thinking:
You're welcome and no offense taken
I format my code to suit my eyes. Much of the code I post here is cut and paste from various sources I've accumulated. Sometimes I don't have time to clean it up so I post it as is. I figure posting results is more important than posting pretty code. I leave it up to the user to spend the time cleaning up the code to suit their coding style.

Posted: Sat Oct 30, 2004 1:25 am
by halo
I got it working.
Dude, just trust me, Blitz3D+PureBasic is one WEIRD development environment.
Re: Setting a container gadget color affects ALL containers
Posted: Wed Nov 28, 2018 5:38 pm
by GenRabbit
I'm trying the code above with a few fixes so it would compile, but I can't get it working.
Code: Select all
Global.l blueBrush=CreateSolidBrush_(RGB(0,0,255))
Global.l greenBrush=CreateSolidBrush_(RGB(0,255,0))
Procedure myWindowCallback(hwnd.i, msg.i, wparam.i, lparam.i)
result=#PB_ProcessPureBasicEvents
Select msg
Case #WM_ERASEBKGND
container.RECT
Select hwnd
Case GadgetID(0)
container\right=GadgetWidth(0)
container\bottom=GadgetHeight(0)
FillRect_(wparam,container,blueBrush)
result=1
Case GadgetID(2)
container\right=GadgetWidth(2)
container\bottom=GadgetHeight(2)
FillRect_(wparam,container,greenBrush)
result=1
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
win=OpenWindow(0,0,0,400,230,"Colored ContainerGadgets", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ContainerGadget (0,10,10,380,100)
SetClassLong_(GadgetID(0),#GCL_HBRBACKGROUND,0)
ButtonGadget(1,90,40,180,20,"Button in Blue Container")
CloseGadgetList()
ContainerGadget (2,10,120,380,100)
ButtonGadget(3,90,40,180,20,"Button in Green Container")
CloseGadgetList()
SetWindowCallback(@myWindowCallback())
Repeat
Select WaitWindowEvent()
Case #PB_Event_SizeWindow
ResizeGadget(0,-1,-1,WindowWidth(0)-20,-1)
ResizeGadget(2,-1,-1,WindowWidth(0)-20,-1)
Case #PB_Event_CloseWindow
DeleteObject_(blueBrush)
DeleteObject_(greenBrush)
End
EndSelect
ForEver
Re: Setting a container gadget color affects ALL containers
Posted: Wed Nov 28, 2018 6:07 pm
by Paul
Why not use SetGadgetColor() command ??
Code: Select all
If OpenWindow(0, 0, 0, 322, 150, "ContainerGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0, 8, 8, 306, 133, #PB_Container_Raised)
ButtonGadget(1, 10, 15, 80, 24, "Button 1")
ButtonGadget(2, 95, 15, 80, 24, "Button 2")
CloseGadgetList()
SetGadgetColor(0,#PB_Gadget_BackColor,$ff0000)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: Setting a container gadget color affects ALL containers
Posted: Wed Nov 28, 2018 6:22 pm
by GenRabbit
Because I had forgotten all about these and where sure I needed to use WinAPI. What I was looking for was a way to color/Add a picture as background picture in a window. But your post made me check if there was a setWindowColor, and it was. So that solved my problem so far. (openWindow did not show any link to commands related to it, So I quickly thought There where not any related to what I needed.)
Re: Setting a container gadget color affects ALL containers
Posted: Wed Nov 28, 2018 6:41 pm
by Bisonte
Use a CanvasGadget with #PB_Canvas_Container Flag.
Simple way to put images, drawings etc on it and by the way .... crossplatform

Re: Setting a container gadget color affects ALL containers
Posted: Thu Nov 29, 2018 3:13 pm
by GenRabbit
Thanks for the tip. That makes it easier.
I don't think I get around using API as I also use Editorgadget. And some of my code there is using sendmessage.