String-Button with Icon

Just starting out? Need help? Post your questions and find answers here.
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

String-Button with Icon

Post 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
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Re: String-Button with Icon

Post by firace »

For what OS?

I believe I may have a short API based example (Windows only), but I can't check right now.
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: String-Button with Icon

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

Re: String-Button with Icon

Post 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
Last edited by infratec on Tue Sep 24, 2019 11:23 am, edited 1 time in total.
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: String-Button with Icon

Post by Kiffi »

Hygge
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: String-Button with Icon

Post 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.
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Re: String-Button with Icon

Post 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 
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: String-Button with Icon

Post 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!
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: String-Button with Icon

Post 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
Hygge
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: String-Button with Icon

Post by Zimon »

Got it, thanks!
bafometto
New User
New User
Posts: 2
Joined: Fri Sep 06, 2019 12:47 pm

Re: String-Button with Icon

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