Please Fred!!!

I have used this to GET to button and text colors... just need to SET itWindows provides default color values for buttons. The system sends a WM_CTLCOLORBTN message to a button's parent window before the button is drawn. This message contains a handle of the button's device context and a handle of the child window. The parent window can use these handles to change the button's text and background colors. The following table shows the default button-color values.
Value Element colored
COLOR_BTNFACE Button faces.
COLOR_BTNHIGHLIGHT Highlight area (the top and left edges) of a button.
COLOR_BTNSHADOW Shadow area (the bottom and right edges) of a button.
COLOR_BTNTEXT Regular (nongrayed) text in buttons.
COLOR_GRAYTEXT Disabled (gray) text in buttons. This color is set to 0 if the current display driver does not support a solid gray color.
COLOR_WINDOW Window backgrounds.
COLOR_WINDOWFRAME Window frames.
COLOR_WINDOWTEXT Text in windows.
An application can retrieve the default values for these colors by calling the GetSysColor function, or set the values by calling the SetSysColors function. For more information about system colors, see System Information. For more information about how colors are used with controls, see Controls.
Portability Issue The WM_CTLCOLOR message has been replaced by the set of control-color messages. When porting your Windows 3.x - based application to the Win32 API, you must modify any code that processes the WM_CTLCOLOR message.
Code: Select all
BOOL WINAPI SetSysColors(
int cElements, // number of elements to change
CONST INT *lpaElements, // address of array of elements
CONST COLORREF *lpaRgbValues // address of array of RGB values
);
Code: Select all
Enumeration
#Window_0
EndEnumeration
Enumeration
#Button_8
#Button_7
#Button_6
#Button_5
#Button_4
#Button_3
#Button_2
#Button_1
#Button_0
#Text_MSG
EndEnumeration
Structure VisualDesignerGadgets
Gadget.l
EventFunction.l
EndStructure
Global NewList EventProcedures.VisualDesignerGadgets()
;-
Procedure Whichbutton(button)
cbutface = GetSysColor_ ( #COLOR_BTNFACE )
cbuttext = GetSysColor_ ( #COLOR_BTNTEXT)
For XX = #Button_8 To #Button_0
;PureCOLOR_ClearButtonColor(XX)
; PureCOLOR_SetButtonColor(XX, cbuttext, cbutface)
Next
; PureCOLOR_ClearAllButtonColors()
;PureCOLOR_SetButtonColor(button, RGB(255, 255, 255), RGB(0, 0, 0))
goo = SetSysColors_ (#COLOR_BTNFACE, button, RGB(0,0,0))
googoo = SetSysColors_ (#COLOR_BTNTEXT, button, RGB(255,255,255))
Debug "FACE: "+Str(goo) ; 0 = FAIL!
Debug "TEXT: "+Str(googoo)
EndProcedure
;-
Procedure Button_8_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_8)
EndProcedure
Procedure Button_7_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_7)
EndProcedure
Procedure Button_6_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_6)
EndProcedure
Procedure Button_5_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_5)
EndProcedure
Procedure Button_4_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_4)
EndProcedure
Procedure Button_3_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_3)
EndProcedure
Procedure Button_2_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_2)
EndProcedure
Procedure Button_1_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_1)
EndProcedure
Procedure Button_0_Event(Window, Event, Gadget, Type)
Whichbutton(#Button_0)
EndProcedure
;-
Procedure RegisterGadgetEvent(Gadget, *Function)
If IsGadget(Gadget)
AddElement(EventProcedures())
EventProcedures()\Gadget = Gadget
EventProcedures()\EventFunction = *Function
EndIf
EndProcedure
Procedure CallEventFunction(Window, Event, Gadget, Type)
ForEach EventProcedures()
If EventProcedures()\Gadget = Gadget
CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
LastElement(EventProcedures())
EndIf
Next
EndProcedure
;-
Procedure Open_Window_0()
If OpenWindow(#Window_0, 5, 5, 248, 441, "BUTON TESTER", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
ButtonGadget(#Button_0, 5, 5, 235, 40, "BUTTON 0")
RegisterGadgetEvent(#Button_0, @Button_0_Event())
ButtonGadget(#Button_1, 5, 50, 235, 40, "BUTTON 1")
RegisterGadgetEvent(#Button_1, @Button_1_Event())
ButtonGadget(#Button_2, 5, 95, 235, 40, "BUTTON 2")
RegisterGadgetEvent(#Button_2, @Button_2_Event())
ButtonGadget(#Button_3, 5, 140, 235, 40, "BUTTON 3")
RegisterGadgetEvent(#Button_3, @Button_3_Event())
ButtonGadget(#Button_4, 5, 185, 235, 40, "BUTTON 4")
RegisterGadgetEvent(#Button_4, @Button_4_Event())
ButtonGadget(#Button_5, 5, 230, 235, 40, "BUTTON 5")
RegisterGadgetEvent(#Button_5, @Button_5_Event())
ButtonGadget(#Button_6, 5, 275, 235, 40, "BUTTON 6")
RegisterGadgetEvent(#Button_6, @Button_6_Event())
ButtonGadget(#Button_7, 5, 320, 235, 40, "BUTTON 7")
RegisterGadgetEvent(#Button_7, @Button_7_Event())
ButtonGadget(#Button_8, 5, 365, 235, 40, "BUTTON 8")
RegisterGadgetEvent(#Button_8, @Button_8_Event())
TextGadget(#Text_MSG, 5, 410, 235, 25, "", #PB_Text_Center | #PB_Text_Border)
EndIf
EndProcedure
;-
Open_Window_0()
PureCOLOR_SetButtonColor(#Button_0, RGB(255, 255, 255), RGB(0, 0, 0))
Repeat
Event = WaitWindowEvent()
Gadget = EventGadget()
Type = EventType()
Window = EventWindow()
Select Event
Case #PB_Event_Gadget
CallEventFunction(Window, Event, Gadget, Type)
EndSelect
Until Event = #PB_Event_CloseWindow
End
VB6 just owner-draws it. It doesn't use any special or secret API call to do it. In fact, a lot of things that VB6 does with a single command is just a lot of custom code behind it. That's what made VB6 so popular with beginner programmers. In contrast, PureBasic doesn't do all this hand-holding and is a real programming language like C.Rook Zimbabwe wrote:if you can do it in VB6 (and last time i looked though admittedly a few years ago...) you can!
Well that explains the VB BLOAT!!!a lot of things that VB6 does with a single command is just a lot of custom code behind it.
Just because I like you, here's some code to save your time:Rook Zimbabwe wrote:I shall work out mine own system
Code: Select all
Procedure ButtonColorGadget(num,x,y,w,h,text$,fcolor,bcolor,flags=0,fontid=#PB_Font_Default)
img=CreateImage(#PB_Any,w,h)
If StartDrawing(ImageOutput(img))
DrawingFont(fontid) : Box(0,0,w,h,bcolor)
DrawText(w/2-TextWidth(text$)/2,h/2-TextHeight(text$)/2,text$,fcolor,bcolor)
StopDrawing() : ok=ButtonImageGadget(num,x,y,w,h,ImageID(img),flags)
EndIf
ProcedureReturn ok
EndProcedure
OpenWindow(0,100,100,340,100,"Colored Buttons",#PB_Window_SystemMenu)
ButtonColorGadget(1,10,10,150,30,"toggle",#Black,#Red,#PB_Button_Toggle)
ButtonColorGadget(2,10,50,150,30,"courier",#Blue,#Yellow,0,LoadFont(0,"courier",12))
btnBlack=ButtonColorGadget(#PB_Any,170,10,150,30,"black/white",#Black,#White)
btnWhite=ButtonColorGadget(#PB_Any,170,50,150,30,"white/black",#White,#Black)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
; English forum: http://purebasic.myforums.net/viewtopic.php?t=2369
; Author: MikeB
; Date: 05. September 2003
Procedure.l MyImage(ImageNumber.l, Width.l, Height.l, Color.l,a$,x,y)
ImageID.l = createimage (ImageNumber, Width, Height)
startdrawing ( imageoutput (ImageNumber))
drawingmode (1)
box (0, 0, Width, Height, Color)
frontcolor ( rgb (0,0,0))
drawtext (x,y,a$)
stopdrawing ()
ProcedureReturn imageid
EndProcedure
mywin= openwindow (0,0,0,218,68, "Coloured buttons" , #PB_Window_SystemMenu|#PB_Window_ScreenCentered )
If mywin
wbrush= CreateSolidBrush_ ( rgb (0,0,255))
SetClassLong_ (mywin, #GCL_HBRBACKGROUND , wbrush)
If creategadgetlist (mywin)
hGadget= containergadget (0,10,10,198,48, #PB_Container_Raised )
hBrush = CreateSolidBrush_ ( rgb (255,255,0))
SetClassLong_ (hGadget, #GCL_HBRBACKGROUND , hBrush)
;
buttonimagegadget (1, 10, 8, 80, 24,MyImage(1,80,24, rgb (255,155,0), "Button 1" ,13,4))
;
buttonimagegadget (2, 100, 8, 80, 24,MyImage(2,80,24, rgb (255,155,0), "Button 2" ,13,4))
closegadgetlist ()
EndIf
Repeat : Until waitwindowevent ()= #PB_Event_CloseWindow
EndIf
; ExecutableFormat=
; FirstLine=1
; EOF
True, but it's not my code.akj wrote:There is a problem with your code in that the appearance of the buttons degrades significantly when they are disabled.
Code: Select all
mywin= OpenWindow (0,0,0,218,68, "Coloured buttons" , #PB_Window_SystemMenu|#PB_Window_ScreenCentered )
If mywin
wbrush= CreateSolidBrush_ ( RGB (0,0,255))
SetClassLong_ (mywin, #GCL_HBRBACKGROUND , wbrush)
hGadget= ContainerGadget (0,10,10,198,48, #PB_Container_Raised )
hBrush = CreateSolidBrush_ ( RGB (255,255,0))
SetClassLong_ (hGadget, #GCL_HBRBACKGROUND , hBrush)
CloseGadgetList ()
; if comment change backcolor gadget = 0
ContainerGadget (50,0,0,0,0 ) : CloseGadgetList ()
Repeat : Until WaitWindowEvent ()= #PB_Event_CloseWindow
EndIf