Advertising links

New to FreeBASIC? Post your questions here.
TurtleProgrammer
Posts: 37
Joined: Jan 26, 2017 7:54

Advertising links

Postby TurtleProgrammer » Jun 06, 2017 21:27

Seems to me I read somewhere freebasic can open external web links. If so how can I do this?
Boromir
Posts: 451
Joined: Apr 30, 2015 19:28
Location: Texas,U.S., Earth,Solar System
Contact:

Re: Advertising links

Postby Boromir » Jun 06, 2017 21:49

You could open a web address in the default browser through the shell.

Windows

Code: Select all

Shell "start http://www.freebasic.net/forum"

This works in Ubuntu Linux

Code: Select all

Shell "xdg-open http://www.freebasic.net/forum"


Example website button code:

Code: Select all

Screenres 640,480,32'Initiate screen
Dim as integer mx,my,click,lclick'mouse x and y,click and last click

do
screenlock
cls
'write the name of the link
Draw String (20,20),"FreeBASIC",rgb(255,255,255)
'make dashed border around the link
line (18,18)-(91,29),rgb(255,255,255),b,&b1001001001001001
'render underline if the mouse is hovering our link
if mx>=18 and mx<=91 and my>=18 and my<=29 then line (18,29)-(91,29),rgb(255,255,255)
screenunlock

getmouse mx,my,,click'get the mouse co-ords and button state

'If the mouse is hovering the button and the user has finished clicking then open the link in the default browser
#IFDEF __FB_LINUX__'Linux method
    if mx>=18 and mx<=91 and my>=18 and my<=29 and click=0 and lclick=1 then Shell "xdg-open http://freebasic.net"
#ELSE 'Windows method
   if mx>=18 and mx<=91 and my>=18 and my<=29 and click=0 and lclick=1 then Shell "start http://freebasic.net"
#ENDIF

'store this loop iteration's click value for the next iteration
lclick=click

'sleep to avoid cpu hogging
sleep 1
loop until multikey(1)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests