Page 1 of 1

Vista Command Link Button (also for Server 2008 / Windows 7)

Posted: Wed Dec 02, 2009 11:25 pm
by Rescator
Vista Command Link or Command Button, should also work on Server 2008 and Windows 7

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

Re: Vista Command Link Button (also for Server 2008 / Windows 7)

Posted: Thu Dec 03, 2009 9:22 am
by Jacobus
Magnificent! Effect and more to add to our Windows to make them more current.
But I have a slight problem with your example, I get a strange language come very far...

Image

Re: Vista Command Link Button (also for Server 2008 / Windows 7)

Posted: Thu Dec 03, 2009 9:34 am
by RASHAD
Hi Jacobus
compile using unicode

Re: Vista Command Link Button (also for Server 2008 / Windows 7)

Posted: Thu Dec 03, 2009 11:14 am
by srod
Very nice Rescator.

Thanks.

Re: Vista Command Link Button (also for Server 2008 / Windows 7)

Posted: Thu Dec 03, 2009 6:40 pm
by Jacobus
RASHAD wrote:Hi Jacobus
compile using unicode
Thanks, it's Ok.

Re: Vista Command Link Button (also for Server 2008 / Window

Posted: Tue Dec 07, 2010 5:18 pm
by Alireza
is there a way to use this useful code in Win-XP :?: