Commandlinks (Windows Vista and above)

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

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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
BarryG
Addict
Addict
Posts: 4175
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
Addict
Addict
Posts: 838
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 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
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: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Commandlinks (Windows Vista and above)

Post by jacdelad »

Yes, yes, you need the themes. I forgot to mention it.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply