ButtonColor

Just starting out? Need help? Post your questions and find answers here.
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

ButtonColor

Post 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)
Image
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 683
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: ButtonColor

Post 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
PB 6.12 x64, OS: Win 11 24H2 x64, Desktopscaling: 150%, CPU: I7 12700 H, RAM: 32 GB, GPU: Intel(R) Iris(R) Xe Graphics | NVIDIA GeForce RTX 3070, User age in 2025: 57y
"Happiness is a pet." | "Never run a changing system!"
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: ButtonColor

Post 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.
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ButtonColor

Post by infratec »

User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: ButtonColor

Post 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)
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: ButtonColor

Post 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


~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: ButtonColor

Post 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 
Image

Code width call dll:

Image
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 683
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: ButtonColor

Post 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).
PB 6.12 x64, OS: Win 11 24H2 x64, Desktopscaling: 150%, CPU: I7 12700 H, RAM: 32 GB, GPU: Intel(R) Iris(R) Xe Graphics | NVIDIA GeForce RTX 3070, User age in 2025: 57y
"Happiness is a pet." | "Never run a changing system!"
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: ButtonColor

Post 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.
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: ButtonColor

Post 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
Image

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
Image

Why?
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: ButtonColor

Post by Bisonte »

Use #PB_Any to create your buttons. PB is used another List than the DLL.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 683
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: ButtonColor

Post by Kurzer »

incaroad wrote:I'm making the dll:
Oh! I didn't realized this. :shock: sorry.
But unfortunately, I have no idea what's causing the problem.
PB 6.12 x64, OS: Win 11 24H2 x64, Desktopscaling: 150%, CPU: I7 12700 H, RAM: 32 GB, GPU: Intel(R) Iris(R) Xe Graphics | NVIDIA GeForce RTX 3070, User age in 2025: 57y
"Happiness is a pet." | "Never run a changing system!"
User avatar
Tombmyst
User
User
Posts: 11
Joined: Thu Jul 04, 2013 2:34 am
Location: Québec

Re: ButtonColor

Post 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?
Tombmyst
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: ButtonColor

Post 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
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: ButtonColor

Post 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)
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply