Page 1 of 1

String-Button with Icon

Posted: Tue Sep 24, 2019 10:31 am
by Zimon
Hi,

I would like to create a standard button with the string "Process File" which contains a small icon (like a little gear of cogwheel) in front of it. So far I've experimented with the ButtonGadget() and the ButtonImageGadget(), but those two can do either or, as far as I've found out.

Is that possible without an additional module? If not, can you recommend a module that can do this?

Thanks!
Simon

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 10:46 am
by firace
For what OS?

I believe I may have a short API based example (Windows only), but I can't check right now.

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 10:53 am
by Zimon
Yes, it would be for Windows. If you find the time to check your repo some time later, I'd be grateful!

Simon

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 11:22 am
by infratec

Code: Select all

If OpenWindow(0, 0, 0, 150, 100, "ButtonImage", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CreateImage(0, 130, 30)
  If StartDrawing(ImageOutput(0))
    Box(0, 0, 130, 30, $C0C0C0)
    
    LoadImage(1, #PB_Compiler_Home + "Examples\Sources\Data\CDPlayer.ico")
    DrawImage(ImageID(1), 5, 0)
    FreeImage(1)
    
    DrawText(40, 8, "Process File", #Black, $C0C0C0)
    StopDrawing()
    ButtonImageGadget(0, 10, 10, 130, 40, ImageID(0))
  EndIf
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 11:23 am
by Kiffi

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 11:35 am
by Zimon
Kiffi wrote:ButtonEx - Module (all OS / 64Bit / DPI)

Greetings ... Peter
This throws me an error on PureBasic 5.62 in the ModuleEx.pbi:
Line 225: DesktopScaledX() is not a function, array, list, map or macro.

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 11:38 am
by firace
Zimon wrote:Yes, it would be for Windows. If you find the time to check your repo some time later, I'd be grateful!

Simon

Found it:

Code: Select all

OpenWindow(0, 100, 100, 640, 480, "")

ButtonGadget(5, 250, 350, 150, 42, " Play...")   

hIcon2 = ExtractIcon_(#Null, "shell32.dll", 137)         ; 

SendMessage_(GadgetID(5),#BM_SETIMAGE,#IMAGE_ICON,hIcon2 )

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 11:46 am
by Zimon
firace wrote:
Zimon wrote:Yes, it would be for Windows. If you find the time to check your repo some time later, I'd be grateful!

Simon

Found it:

Code: Select all

OpenWindow(0, 100, 100, 640, 480, "")

ButtonGadget(5, 250, 350, 150, 42, " Play...")   

hIcon2 = ExtractIcon_(#Null, "shell32.dll", 137)         ; 

SendMessage_(GadgetID(5),#BM_SETIMAGE,#IMAGE_ICON,hIcon2 )

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 

Excellent! Thanks!

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 12:49 pm
by Kiffi
Zimon wrote:
Line 225: DesktopScaledX() is not a function, array, list, map or macro.
it's nice that you found a solution with the code of firace. For the sake of completeness I would like to mention that DesktopScaledX() is available since version 5.70 LTS (2nd January 2019).

Greetings ... Peter

Re: String-Button with Icon

Posted: Tue Sep 24, 2019 1:47 pm
by Zimon
Got it, thanks!

Re: String-Button with Icon

Posted: Wed Nov 27, 2019 2:26 pm
by bafometto
A simple way to create Buttons with a personal Icon:

Note: the height of the button must be appropriate to the size of the icon (in this example 32x32 icons are used)

OpenWindow(0, 100, 100, 640, 480, "")
LoadFont(2, "Arial", 11, #PB_Font_HighQuality)
SetGadgetFont(#PB_Default, FontID(2))

Icon_0=CatchImage(0,?MyIcon_0)
Icon_1=CatchImage(1,?MyIcon_1)
Icon_2=CatchImage(2,?MyIcon_2)
Icon_3=CatchImage(3,?MyIcon_3)

ButtonGadget(0, 250, 50, 150, 42, " Button 1 ")
SendMessage_(GadgetID(0),#BM_SETIMAGE,#IMAGE_ICON,Icon_0)

ButtonGadget(1, 250, 150, 150, 42, " Button 2 ")
SendMessage_(GadgetID(1),#BM_SETIMAGE,#IMAGE_ICON,Icon_1)

ButtonGadget(2, 250, 250, 150, 42, " Button 3 ")
SendMessage_(GadgetID(2),#BM_SETIMAGE,#IMAGE_ICON,Icon_2)

ButtonGadget(3, 250, 350, 150, 42, " Button 4 ")
SendMessage_(GadgetID(3),#BM_SETIMAGE,#IMAGE_ICON,Icon_3)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

DataSection
MyIcon_0:
IncludeBinary "C:\Users\Utente\Immagini\Icone\Icone 32x32\Cubi colorati.ico"
MyIcon_1:
IncludeBinary "C:\Users\Utente\Immagini\Icone\Icone 32x32\Testa donna.ico"
MyIcon_2:
IncludeBinary "C:\Users\Utente\Immagini\Icone\Icone 32x32\Attrezzi 1.ico"
MyIcon_3:
IncludeBinary "C:\Users\Utente\Immagini\Icone\Icone 32x32\Bandiera italiana.ico"
EndDataSection