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

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

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

Post 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
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

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

Post 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
PureBasicien tu es, PureBasicien tu resteras.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

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

Post by RASHAD »

Hi Jacobus
compile using unicode
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

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

Post by srod »

Very nice Rescator.

Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

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

Post by Jacobus »

RASHAD wrote:Hi Jacobus
compile using unicode
Thanks, it's Ok.
PureBasicien tu es, PureBasicien tu resteras.
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

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

Post by Alireza »

is there a way to use this useful code in Win-XP :?:
PB v 5.6 :D
Post Reply