Page 1 of 2
ButtonColor
Posted: Sun Apr 28, 2019 3:18 pm
by incaroad
Hello!
I wrote a little code but it doesn't work. Why?
(PureBasic 5.00)
PureColor is installed.
Thanks for the help!
buttoncolor.dll :
Code: Select all
ProcedureDLL SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
PureCOLOR_SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
EndProcedure
Example:
Code: Select all
Prototype SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
Define dll = OpenLibrary(#PB_Any, "buttoncolor.dll")
If dll
Define SetButtonColor.SetButtonColor = GetFunction(dll, "SetButtonColor")
EndIf
OpenWindow(0, 100, 300, 310, 40, "PureCOLOR button test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(3, 10, 10, 80, 20, "Normal")
ButtonGadget(4, 210, 10, 80, 20, "Extra + Toggle", #PB_Button_Toggle)
ButtonGadget(6, 110, 10, 80, 20, "Extra Colors")
; Adding colors
SetButtonColor(3, RGB(255,0,255), RGB(0,255,255),0,0)
SetButtonColor(4, RGB(255,0,0), RGB(0,255,0), RGB(255,127,0), RGB(255,255,0))
;SetButtonColor(6, RGB(255,0,0), RGB(0,255,0), RGB(255,127,0), RGB(255,255,0))
SetButtonColor(6, RGB(255,0,0), #PureCOLOR_SystemColor, RGB(255,0,0), #PureCOLOR_SystemColor)
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
CloseLibrary(dll)

Re: ButtonColor
Posted: Sun Apr 28, 2019 3:56 pm
by Kurzer
Hello incaroad,
the PureColour extension comes from the user Gnozal, who unfortunately has been "lost" for many years. He hasn't been in the forum for a long time and his former website has disappeared.
It will be hard to find someone here who can help you. We don't know how Gnozals DLL is programmed.
But I'm surprised that you have to open a DLL. I think I remember that one could include Gnozals extensions as a userlib in PureBasic without having to handle a DLL. But that was all so long time ago that I can't give any tips here.
By the way, your avatar is a bit distracting.
Kurzer
Re: ButtonColor
Posted: Sun Apr 28, 2019 4:17 pm
by incaroad
Hello kurzer!
Thank you for your comments!
I made a dll if I could use it in the PureBasic's new version.
But unfortunately not even with 5.00.
Re: ButtonColor
Posted: Sun Apr 28, 2019 4:34 pm
by infratec
Re: ButtonColor
Posted: Sun Apr 28, 2019 8:02 pm
by Bisonte
PureColor is x86 only !
If you want to use it with newer PB Versions, you can only use the x86 Compiler !
The best way is you use a canvas like infratec is mentioned.
(A button is the simpliest gadget you can build with)
Re: ButtonColor
Posted: Sun Apr 28, 2019 11:33 pm
by ar-s
Now with the Canvas you can simulate great buttons.
Here is a small example.
You can also add a "clic" State pictures.
Code: Select all
;///////////// INIT //////////////////////////
UsePNGImageDecoder()
Enumeration
#WIN
#CANVAS
#I1
#I2
EndEnumeration
InitNetwork()
Global Li, Hi
; //////////// PROCEDURES /////////////////////
Procedure DrawCanvasBT(image)
Shared FirstLaunch
StartDrawing(CanvasOutput(#Canvas))
If FirstLaunch = 0
Box(0,0,Li,Hi,$171717)
FirstLaunch+1
EndIf
DrawImage(ImageID(image),0,0)
StopDrawing()
EndProcedure
Procedure CatchImage_Net(Adr$)
Protected EXT.s, image
; By Ar-S
EXT.s = LCase(GetExtensionPart(Adr$))
Select EXT
Case "jpg","jpeg"
UseJPEGImageDecoder()
Case "png"
UsePNGImageDecoder()
EndSelect
*Buffer = ReceiveHTTPMemory(Adr$)
If *Buffer
Image = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer) )
Hi = ImageHeight(image)
Li = ImageWidth(image)
FreeMemory(*Buffer)
ProcedureReturn Image
Else
ProcedureReturn 0
EndIf
EndProcedure
; ////////// PROGRAM ///////////////
;LOADIN PICTURES OF THE BUTTONS
URI1$ = "https://zupimages.net/up/19/18/ecd4.png"
URI2$ = "https://zupimages.net/up/19/18/q6lu.png"
IM1 = CatchImage_Net(URI1$)
IM2 = CatchImage_Net(URI2$)
If OpenWindow(#WIN, 0, 0, 400, 200, "Exemple...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#win,$171717)
CanvasGadget (#CANVAS, 1, 1, Li, Hi)
DrawCanvasBT(IM1)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #CANVAS
Select EventType()
Case #PB_EventType_MouseEnter
DrawCanvasBT(IM2)
Case #PB_EventType_MouseLeave
DrawCanvasBT(IM1)
Case #PB_EventType_LeftClick
Debug "Clic"
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Re: ButtonColor
Posted: Mon Apr 29, 2019 10:16 am
by incaroad
Hello!
The problem is that the code is working, only dll does not work (but there is no error message). Why is this? I do not understand. I would have a solution for that.
Code:
Code: Select all
OpenWindow(0, 100, 300, 310, 40, "PureCOLOR button test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(3, 10, 10, 80, 20, "Normal")
ButtonGadget(4, 210, 10, 80, 20, "Extra + Toggle", #PB_Button_Toggle)
ButtonGadget(6, 110, 10, 80, 20, "Extra Colors")
; Adding colors
PureCOLOR_SetButtonColor(3, RGB(255,0,255), RGB(0,255,255))
PureCOLOR_SetButtonColor(4, RGB(255,0,0), RGB(0,255,0), RGB(255,127,0), RGB(255,255,0))
;PureCOLOR_SetButtonColor(6, RGB(255,0,0), RGB(0,255,0), RGB(255,127,0), RGB(255,255,0))
PureCOLOR_SetButtonColor(6, RGB(255,0,0), #PureCOLOR_SystemColor, RGB(255,0,0), #PureCOLOR_SystemColor)
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Code width call dll:

Re: ButtonColor
Posted: Mon Apr 29, 2019 1:29 pm
by Kurzer
You will have to ask the programmer of the DLL, but unfortunately he has disappeared from the internet many years ago.
It will make more sense to look for an alternative solution, because if you have a problem with a foreign DLL, nobody but the author of the DLL will be able to help you (apart from some reverse engeneering experts).
Re: ButtonColor
Posted: Mon Apr 29, 2019 1:34 pm
by incaroad
I'm making the dll:
ProcedureDLL SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
PureCOLOR_SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
EndProcedure
That's why I don't understand why it doesn't work.
I think PureCOLOR_SetButtonColor instruction operates on WinAPI, and it's not built into the ddI. Maybe.
Re: ButtonColor
Posted: Mon Apr 29, 2019 2:55 pm
by incaroad
One more example.
It works:
Code: Select all
Procedure ButtonGadgetColor(gad,x,y,w,h,text$="",flags=0,fgcolor=#PB_Default,bgcolor=#PB_Default,font=#PB_Default)
If bgcolor=#PB_Default : bgcolor=GetSysColor_(#COLOR_BTNFACE) : EndIf
If fgcolor=#PB_Default : fgcolor=GetSysColor_(#COLOR_BTNFACE) : EndIf
If font=#PB_Default : font=GetStockObject_(#DEFAULT_GUI_FONT) : EndIf
text=CreateImage(#PB_Any,w,h)
If StartDrawing(ImageOutput(text))
DrawingFont(font) : Box(0,0,w,h,bgcolor)
DrawText(w/2-TextWidth(text$)/2,h/2-TextHeight(text$)/2,text$,fgcolor,bgcolor)
StopDrawing() : ok=ButtonImageGadget(gad,x,y,w,h,ImageID(text),flags)
EndIf
ProcedureReturn ok
EndProcedure
OpenWindow(0,100,100,340,100,"Colored Buttons",#PB_Window_SystemMenu)
ButtonGadgetColor(1,10,10,150,30,"toggle",#PB_Button_Toggle,#White,#Red)
ButtonGadgetColor(2,10,50,150,30,"courier",0,#Blue,#Yellow,LoadFont(0,"courier",12))
ButtonGadget(#PB_Any,170,10,150,30,"normal")
ButtonGadgetColor(#PB_Any,170,50,150,30,"normal + red",0,#Red)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
The dll called does not work:
Code: Select all
ProcedureDLL ButtonGadgetColor(gad,x,y,w,h,text$="",flags=0,fgcolor=#PB_Default,bgcolor=#PB_Default,font=#PB_Default)
If bgcolor=#PB_Default : bgcolor=GetSysColor_(#COLOR_BTNFACE) : EndIf
If fgcolor=#PB_Default : fgcolor=GetSysColor_(#COLOR_BTNFACE) : EndIf
If font=#PB_Default : font=GetStockObject_(#DEFAULT_GUI_FONT) : EndIf
text=CreateImage(#PB_Any,w,h)
If StartDrawing(ImageOutput(text))
DrawingFont(font) : Box(0,0,w,h,bgcolor)
DrawText(w/2-TextWidth(text$)/2,h/2-TextHeight(text$)/2,text$,fgcolor,bgcolor)
StopDrawing() : ok=ButtonImageGadget(gad,x,y,w,h,ImageID(text),flags)
EndIf
ProcedureReturn ok
EndProcedure
Why?
Re: ButtonColor
Posted: Mon Apr 29, 2019 3:25 pm
by Bisonte
Use #PB_Any to create your buttons. PB is used another List than the DLL.
Re: ButtonColor
Posted: Mon Apr 29, 2019 4:11 pm
by Kurzer
incaroad wrote:I'm making the dll:
Oh! I didn't realized this.

sorry.
But unfortunately, I have no idea what's causing the problem.
Re: ButtonColor
Posted: Mon Apr 29, 2019 5:16 pm
by Tombmyst
I believe that you can't create any gadgets on a window from a dll that way, how the dll would know on which gadget list to create it?
Secondly, as Bisonte said, use #PB_Any.
May I see the way you call the dll functions from your main code?
Re: ButtonColor
Posted: Mon Apr 29, 2019 6:15 pm
by incaroad
Hello Tombmyst!
Code: Select all
Prototype ButtonGadgetColor(gad,x,y,w,h,text$="",flags=0,fgcolor=#PB_Default,bgcolor=#PB_Default,font=#PB_Default,kep=#PB_Any)
Define dll = OpenLibrary(#PB_Any, "ButtonGadgetColor.dll")
If dll
Define ButtonGadgetColor.ButtonGadgetColor = GetFunction(dll, "ButtonGadgetColor")
EndIf
OpenWindow(0,100,100,340,100,"Colored Buttons",#PB_Window_SystemMenu)
Debug ButtonGadgetColor(1,10,10,150,30,"toggle",#PB_Button_Toggle,#White,#Red)
ButtonGadgetColor(2,10,50,150,30,"courier",0,#Blue,#Yellow,LoadFont(0,"courier",12))
ButtonGadget(#PB_Any,170,10,150,30,"normal")
ButtonGadgetColor(#PB_Any,170,50,150,30,"normal + red",0,#Red)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Re: ButtonColor
Posted: Mon Apr 29, 2019 7:25 pm
by Bisonte
I mean like this :
Code: Select all
DLL:
ProcedureDLL.i ButtonGadgetColor(Gadget.i, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
ProcedureReturn PureCOLOR_SetButtonColor(Gadget.i, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
EndProcedure
Program:
Prototype SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l)
Define dll = OpenLibrary(#PB_Any, "buttoncolor.dll")
If dll
Define SetButtonColor.SetButtonColor = GetFunction(dll, "SetButtonColor")
EndIf
OpenWindow(0, 100, 300, 310, 40, "PureCOLOR button test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
Btn3 = ButtonGadget(#PB_Any, 10, 10, 80, 20, "Normal")
Btn4 = ButtonGadget(#PB_Any, 210, 10, 80, 20, "Extra + Toggle", #PB_Button_Toggle)
Btn6 = ButtonGadget(#PB_Any, 110, 10, 80, 20, "Extra Colors")
; Adding colors
SetButtonColor(Btn3, RGB(255,0,255), RGB(0,255,255),0,0)
SetButtonColor(Btn4, RGB(255,0,0), RGB(0,255,0), RGB(255,127,0), RGB(255,255,0))
;SetButtonColor(6, RGB(255,0,0), RGB(0,255,0), RGB(255,127,0), RGB(255,255,0))
SetButtonColor(Btn6, RGB(255,0,0), #PureCOLOR_SystemColor, RGB(255,0,0), #PureCOLOR_SystemColor)
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
CloseLibrary(dll)