HyperLinkGadget + icon (?)

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2223
Joined: Sun May 14, 2017 1:48 am

HyperLinkGadget + icon (?)

Post by AZJIO »

How to make a hyperlink with an icon?
I've seen some launchers where the button has no borders, just text that changes color when hovered over. At the same time, the button has an icon.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: HyperLinkGadget + icon (?)

Post by Marc56us »

AZJIO wrote: Sun Feb 20, 2022 10:33 am How to make a hyperlink with an icon?
I've seen some launchers where the button has no borders, just text that changes color when hovered over. At the same time, the button has an icon.
Hi,

Some launchers simply use CanvasGadgets with images that change on mouseover (using Eventype #PB_EventType_Focus / LostFocus)
The link is then activated with a simple RunProgram ("http://...", "", "") that will open the default browser.

:wink:
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: HyperLinkGadget + icon (?)

Post by mk-soft »

There is no such control in the OS.
These are external or self-created controls. OwnerDraw controls.

You can create these yourself with the CanvasGadget or search for them in the forum. For example the one from Thorsten.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
AZJIO
Addict
Addict
Posts: 2223
Joined: Sun May 14, 2017 1:48 am

Re: HyperLinkGadget + icon (?)

Post by AZJIO »

I tried to use the example with #BS_OWNERDRAW, but there is no hover event in it. There is a pressed button event - #ODS_SELECTED.
I tried the #BCN_HOTITEMCHANGE event, but it doesn't work together with #BS_OWNERDRAW. I've tried disabling all button border styles, but that doesn't work. Using GetDC_() grabs the area of ​​the button, but it doesn't include the button's borders, so I can't paint them and get rid of them.
When using Canvas, the size of the program increases by 40 kb, and the size of my program is 70 kb. I would not want to attach an airplane engine to a bicycle.

Code: Select all

EnableExplicit

Global hIcon

; START for button icon
#Library = 0
InitCommonControls_() ; инициализация классов элементов управления
If OpenLibrary(#Library,"comctl32.dll")
	Prototype ImageList_AddIcon(List, Icon)
	Global ImageList_AddIcon.ImageList_AddIcon
	ImageList_AddIcon=GetFunction(#Library,"ImageList_AddIcon")
	CloseLibrary(#Library)
EndIf

#BCM_FIRST = $1600
#BCM_SETIMAGELIST = #BCM_FIRST + 2
#BUTTON_IMAGELIST_ALIGN_LEFT = 0

Procedure AddIconToButton(ButtonID,IconID,s = 16)
	Protected buttonImgList.BUTTON_IMAGELIST
	Protected himlIcons
	
	himlIcons = ImageList_Create_(s,s, #ILC_MASK | #ILC_COLOR32, 1, 0)
	
	ImageList_AddIcon(himlIcons, IconID)
	
	With buttonImgList
		\uAlign = #BUTTON_IMAGELIST_ALIGN_LEFT
		\margin\top = 3
		\margin\bottom = 3
		\margin\left = 3
		\margin\right = 3
		\himl = himlIcons
	EndWith
	
	SendMessage_(ButtonID, #BCM_SETIMAGELIST, 0, buttonImgList)
EndProcedure
; END for button icon

#BS_COMMANDLINK = 14
#BS_SPLITBUTTON = 12
If OpenWindow(0, 0, 0, 220, 100, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ButtonGadget (0, 10, 10, 200, 40, "close", #BS_COMMANDLINK)
; 	ButtonGadget (1, 10, 50, 200, 30, "close", #BS_DEFPUSHBUTTON)
; 	HyperLinkGadget(0, 10, 10, 200, 30, "close", $FF0000, #BS_BITMAP | #BS_ICON)
; 	TextGadget(0, 10, 10, 200, 30, "close")
; 	CheckBoxGadget(0, 10, 10, 200, 30, "close")
;  	SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) ! #BS_AUTOCHECKBOX)
;  	SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) ! #BS_DEFPUSHBUTTON)
;  	SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) ! #BS_DEFPUSHBUTTON)
	If ExtractIconEx_("shell32.dll", 4,0,@hIcon,1)
		AddIconToButton(GadgetID(0), hIcon, 16)
	EndIf

	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						CloseWindow(0)
						End
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: HyperLinkGadget + icon (?)

Post by RASHAD »

HyperLink with Icon

Code: Select all

Global dll.s

dll.s = "Shell32.dll" ;"imageres.dll" ;"ddores.dll" ;

Procedure IsMouseOver(hWnd) 
  GetWindowRect_(hWnd,r.RECT) 
  GetCursorPos_(p.POINT) 
  Result = PtInRect_(r,p\y << 32 + p\x) 
  ProcedureReturn Result 
EndProcedure

Procedure _HyperLink(id,width,height,text$,icon)
  hIcon = ExtractIcon_(0,dll,icon)
  CreateImage(id,width,height,24,$0000FF)
  hdc = StartDrawing(ImageOutput(id))
    DrawIcon_(hdc ,2,2,hIcon)
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(40,12,"HyperLink Test")      
  StopDrawing()
EndProcedure 

If OpenWindow(0, 0, 0, 640,480, "MouseOver", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
  _HyperLink(0,160,40,"HyperLink Test",10)  
  CreateImage(1,ImageWidth(0),ImageHeight(0))
  StartDrawing(ImageOutput(1))
    DrawAlphaImage(ImageID(0),0,0,180)
  StopDrawing()
  ImageGadget(0, 10,10,160,40,ImageID(1))
  Repeat 
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow 
        Quit = 1 
        
      Case #WM_MOUSEMOVE
        If IsMouseOver(GadgetID(0))
          SetClassLongPtr_(GadgetID(0), #GCL_HCURSOR, LoadCursor_(0,#IDC_HAND))
          SetGadgetState(0,ImageID(0))
        Else
          SetClassLongPtr_(GadgetID(0), #GCL_HCURSOR, LoadCursor_(0,#IDC_ARROW))
          SetGadgetState(0,ImageID(1))
        EndIf
        
      Case #WM_LBUTTONDBLCLK
        If IsMouseOver(GadgetID(0))
          SetGadgetState(0,ImageID(1))
          ShellExecute_(WindowID(0),"open","http:\\www.purebasic.com","","",#SW_SHOWNORMAL)
        EndIf
        
    EndSelect
    
  Until Quit = 1 
EndIf 
End
Egypt my love
Post Reply