Older Version Newer Version

Alyce Alyce Jun 14, 2011

Simulated Hyperlink in Liberty Basic

Originally published in NL 129
by David Conner and - StPendl StPendl
Simulated Hyperlink in Liberty Basic | Clickable Link | Screenshot | Demo

Clickable Link


The development of a pseudo (or simulated) hyperlink in Liberty Basic came about in response to a query posted by Ilmar. He asked: Is it possible to add a link to a URL in a statictext control. Like the blue&undelined stuff I've seen?

David Conner and Stefan Pendl, working as a team managed to develop an very acceptable alternative to the native windows control, written using Liberty Basic with a few API calls thrown in. The program was developed in stages, based on the initial posting by David.

This is the final product, showing a hyperlink that will cause the mouse pointer to change to a hand and the link to change colors as you pass the pointer over it. A job well done.

Screenshot


Demo


 ' Demo of clickable text 
' by David Conner, 2004, public domain
'
'Cursor Example by Mitchell Kotler
'How to use LoadCursor and SetCursor to access more Window's Cursors
'No more flickering!
'modified Nov 26, 2000 awatson
'modified Jan 07, 2004 s.pendl
'modified Jan 08, 2004 s.pendl

NoMainWin
WindowWidth=400:WindowHeight=400
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)

Stylebits #1.g, 0, _WS_BORDER, 0, 0
Graphicbox #1.g, 100,100,85,25
statictext #1.txt, " to open LB home page", 185, 106, 200, 25
Open "Clickable Text" for window_nf as #1
#1.g "when leftButtonDown [checkClick]"
#1.g "when mouseMove [changeCursor]"
#1 "Trapclose [quit]"
#1.g "down; fill buttonface; color black; backcolor buttonface"
#1.g "font times_new_roman 12 underscore bold"
#1 "font times_new_roman 12 bold"
#1.g "place 10 21"
#1.g "\Click Here"
#1.g "flush"
call setClass hwnd(#1)
Wait

[quit]
Close #1: End

[checkClick]
run "explorer http://libertybasic.com"
wait

[changeCursor]
x = MouseX
y = MouseY

if x > 5 and y > 5 and x < 80 and y < 20 then
IDC.HAND = 32649
CursorHandle=LoadCursor(IDC.HAND)
#1.g "color blue ;place 10 21 ;\Click Here"
else
cursor normal
#1.g "color black ;place 10 21 ;\Click Here"
end if
wait

function LoadCursor(CursorName)
calldll #user32, "LoadCursorA",_
Instance As ulong,_
CursorName As ulong,_
hCursor As ulong

call SetCursor hCursor
LoadCursor = hCursor
end function

sub SetCursor hCursor
calldll #user32, "SetCursor",_
hCursor as ulong,_
result as ulong
end sub

sub setClass hWnd
index = _GCL_HCURSOR or 0
value = 0

calldll #user32, "SetClassLongA",_
hWnd as ulong,_
index as ulong,_
value as ulong,_
result as ulong
end sub

Simulated Hyperlink in Liberty Basic | Clickable Link | Screenshot | Demo