Commandlinks (Windows Vista and above)

Share your advanced PureBasic knowledge/code with the community.
User avatar
jacdelad
Addict
Addict
Posts: 1418
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Commandlinks (Windows Vista and above)

Post by jacdelad »

Make a button a command link:

Code: Select all

#BS_COMMANDLINK = $E
#BCM_SETNOTE = $1609
OpenWindow(0, 100, 100, 150, 60, "Commandlink-Demo")
ButtonGadget(0, 10, 10, 125, 40, "Commandlink",#BS_COMMANDLINK)
SendMessage_(GadgetID(0),#BCM_SETNOTE,0,"Subline(s)")
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Behaves like a normal button.

Additionally the image can be changed with:

Code: Select all

SendMessage_(GadgetID(0),#BM_SETIMAGE,#IMAGE_ICON,ImageID(LoadImage(#PB_Any,my_icon_with_path)))
Use #IMAGE_CURSOR or #IMAGE_BITMAP for cursors/bitmaps.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
BarryG
Addict
Addict
Posts: 3268
Joined: Thu Apr 18, 2019 8:17 am

Re: Commandlinks (Windows Vista and above)

Post by BarryG »

Thanks for this. I'm trying to use a PNG icon (encoded to BMP) but it doesn't work. Any ideas?

Code: Select all

UsePNGImageDecoder()
i=LoadImage(#PB_Any,"Path\To\Icon.png")
i2=EncodeImage(i)
#BS_COMMANDLINK = $E
#BCM_SETNOTE = $1609
OpenWindow(0, 100, 100, 250, 100, "Commandlink-Demo")
ButtonGadget(0, 10, 10, 225, 60, "Commandlink",#BS_COMMANDLINK)
SendMessage_(GadgetID(0),#BCM_SETNOTE,0,"Subline(s)")
SendMessage_(GadgetID(0),#BM_SETIMAGE,#IMAGE_ICON,i2)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Axolotl
Enthusiast
Enthusiast
Posts: 432
Joined: Wed Dec 31, 2008 3:36 pm

Re: Commandlinks (Windows Vista and above)

Post by Axolotl »

Hi BarryG,

you have to change the #IMAGE_ICON to #IMAGE_BITMAP

Code: Select all

;SendMessage_(GadgetID(0), #BM_SETIMAGE, #IMAGE_ICON, ImageID(0)) 
SendMessage_(GadgetID(0), #BM_SETIMAGE, #IMAGE_BITMAP, ImageID(0)) 


and this is an running example (with a self made image!) ... I changed the window size to see the entire stuff!

Code: Select all


#BS_COMMANDLINK = $E
#BCM_SETNOTE = $1609

Procedure MakeTestImage(ImgID) 
  Protected k 

  If CreateImage(ImgID, 32, 32)
    If StartDrawing(ImageOutput(ImgID))
      DrawingMode(#PB_2DDrawing_Transparent)
      Box(2,2,28,28, #Green) 
      Circle(4, 4,10, #Blue) 
      StopDrawing()
    EndIf
  EndIf 
  ProcedureReturn ImageID(ImgID) 
EndProcedure 

MakeTestImage(0) 

OpenWindow(0, 100, 100, 250, 160, "Commandlink-Demo")
ButtonGadget(0, 10, 10, 225, 140, "Commandlink", #BS_COMMANDLINK) 
SendMessage_(GadgetID(0), #BCM_SETNOTE, 0, "Subline(s)") 

;SendMessage_(GadgetID(0), #BM_SETIMAGE, #IMAGE_ICON, ImageID(0)) 
SendMessage_(GadgetID(0), #BM_SETIMAGE, #IMAGE_BITMAP, ImageID(0)) 

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget                          :Debug "EventGadget: " + EventGadget()  
  EndSelect
ForEver 
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Commandlinks (Windows Vista and above)

Post by Kwai chang caine »

Not works without "visual themes XP" else works good with it actived
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
jacdelad
Addict
Addict
Posts: 1418
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Commandlinks (Windows Vista and above)

Post by jacdelad »

Yes, yes, you need the themes. I forgot to mention it.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply