The benefit of how it's implemented in my code below is that it behaves just like a normal button, so it may look different but shouldn't break your code.
No flags are supported as none of the PB flags works with the command link button, there may be other Win API flags that work but I didn't check.
Have fun folks!
Code: Select all
;This only works with Vista or later.
;XP skin (or Vista skin if you will) support must also be enabled in compiler options.
EnableExplicit
#BCM_FIRST=$1600
;http://www.interact-sw.co.uk/iangblog/2005/12/21/commandlinks
#BCM_SETSHIELD=#BCM_FIRST+$000C
Macro SetElevationRequiredStateOnButton(Gadget,Required)
SendMessage_(GadgetID(Gadget),#BCM_SETSHIELD,#Null,required)
;If all went well, the button should now display a Shield icon in it on Vista.
EndMacro
#BS_COMMANDLINK=$0000000E
#BCM_SETNOTE=#BCM_FIRST+$0009
Procedure.i CommandGadget(Gadget.i,x.l,y.l,Width.l,Height.l,Text$,Note$="",Shield.l=#False)
Protected result.i
result=ButtonGadget(Gadget,x,y,Width,Height,Text$,#BS_COMMANDLINK)
If IsGadget(Gadget)
If Note$
SendMessage_(GadgetID(Gadget),#BCM_SETNOTE,#Null,@Note$)
EndIf
If Shield
SetElevationRequiredStateOnButton(Gadget,#True)
EndIf
EndIf
ProcedureReturn result
EndProcedure
Define Event.i
; Shows possible flags of ButtonGadget in action...
If OpenWindow(1, 0, 0, 420, 220, "CommandGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CommandGadget(1, 10, 10, 400, 50, "Command Button 1")
CommandGadget(2, 10, 60, 400, 50, "&Command Button 2","This should display a subtext and the C should be underlined!")
CommandGadget(3, 10, 110, 400, 50, "Command Button 3","This should have a elevation shield instead of an arrow!",#True)
ButtonGadget(4, 10, 160, 400, 50, "Normal Button with Elevation Shield")
SetElevationRequiredStateOnButton(4,#True)
Repeat
Event=WaitWindowEvent()
If Event=#PB_Event_Gadget
Debug EventGadget()
EndIf
Until Event=#PB_Event_CloseWindow
EndIf