Please Fred!!!
Button Face Color
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Button Face Color
I am still hoping for the ability to set button face and text colors native to PB! You can set them on all OS now and though I am not an expert on Linux Gnome or Mac OS i suspect the calls may be similar enough!!!
Please Fred!!!
Please Fred!!!
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Button Face Color
how you set then on windows? 
last time I looked into that issue, it was literally impossible. Buttons do not show a facecolor property, no matter if you set it.

last time I looked into that issue, it was literally impossible. Buttons do not show a facecolor property, no matter if you set it.
oh... and have a nice day.
- Fluid Byte
- Addict

- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Button Face Color
The button face color is not a solid color anymore unless you disable themes. The classic look is dying anyway, standard is skinned look for the majority. Also it's not colors anymore that are directly ploted to the device context, it's images. You would have to colorize them using e.g. the HSL color model. Since Vista this is directly possible by using DirectX/Direct2D but only for the native styles of Windows, not sure about custom skins. What finally kills this request is the cross platform aspect so I would say forget about it.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Button Face Color
if you can do it in VB6 (and last time i looked though admittedly a few years ago...) you can!
from the API32
so I would use:
like:
SetSysColors(COLOR_BTNFACE, #BUTTON, RGB(0,0,0))
SetSysColors(COLOR_BTNTEXT, #BUTTON, RGB(255,255,255))
wouldn't i???
{{{{{{{EDIT}}}}}}}
yep... y'all are right...
]
no workee
from the API32
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.
so I would use:
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
);
SetSysColors(COLOR_BTNFACE, #BUTTON, RGB(0,0,0))
SetSysColors(COLOR_BTNTEXT, #BUTTON, RGB(255,255,255))
wouldn't i???
{{{{{{{EDIT}}}}}}}
yep... y'all are right...
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
no workee
-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Re: Button Face Color
You can draw anything but what people wanted to tell is that there is no standard functionality for this so don't expect a compiler to make this possible.
Also the mention about themes is important, you can still draw yourself but does a user want to you to molest the appearance of a button?
To draw a button having the colors of desire use it in ownerdraw mode.
Also the mention about themes is important, you can still draw yourself but does a user want to you to molest the appearance of a button?
To draw a button having the colors of desire use it in ownerdraw mode.
-
UserOfPure
- Enthusiast

- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Button Face Color
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!
(Edited to fix a typo).
Last edited by UserOfPure on Sat Apr 03, 2010 11:16 pm, edited 1 time in total.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Button Face Color
True this! 
OK I shall work out mine own system... just wish I knew where Gnozal has gone!
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.
OK I shall work out mine own system... just wish I knew where Gnozal has gone!
-
UserOfPure
- Enthusiast

- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Button Face Color
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
Re: Button Face Color
@UserOfPure
There is a problem with your code in that the appearance of the buttons degrades significantly when they are disabled.
There is a problem with your code in that the appearance of the buttons degrades significantly when they are disabled.
Anthony Jordan
Re: Button Face Color
works very well for me !! 
otherwise
this code works well too:)
but just for Windows
otherwise
this code works well too:)
but just for Windows
; 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
-
UserOfPure
- Enthusiast

- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Button Face Color
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.
Re: Button Face Color
if you comment out the gadget 50 painted gadget 0.
why?
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

