Chase Button Demo

© 2003, David Drake

author website:

http://www.foundrysearch.com

Home

Password Textbox API

Character Replacement

LB Isam Library

Beginning Games 2

Rubber Band Objects

WMLiberty Primer

LB Browser

Beginning Programming 5

INPUTTO Demo

Chase Button

Questionaire Wizard

MIDI Output Thoughts

MIDI-Tunes

Play MIDI DLL

Directory Search Function

Newsletter help

Index

Chase Button Demo

On May 18 David Drake posted a fun little demo to the Liberty Basic conforums site with this note:

Here's a little "chase the button" demo I cooked up. Enjoy!

David has graciuosly allowed me to reprint that fun little demo here. Please note how it makes excellent use of the locate command, as well as a simple API call to get the current mouse pointer coordinates:

'Button chasing example
'by David Drake
nomainwin
WindowWidth = 550
WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.me, "Vote Republicrat", [me], UL, 100, 150, 150, 70
button #main.other, "Vote Demolican", [other], UL, 250, 150, 150, 70
graphicbox #main.gb, 0, 0, 550, 410

open "Vote" for window as #main

#main "font ms_sans_serif 0 16"
#main "trapclose [quit]"
#main.gb "down;fill lightgray;"
#main.gb "place 125 92;color black;backcolor lightgray;\Vote for One Candidate for President:"
#main.gb "flush"
#main.gb "setfocus"

ButtonX = 245
ButtonY = 145

struct point, x as long, y as long
timer 100, [checkMove]
wait



[checkMove]
'Get mouse position (on screen)
calldll #user32, "GetCursorPos", _
point as struct, _
result as void

'Convert screen position to a window position
x = point.x.struct - UpperLeftX - 6
y = point.y.struct - UpperLeftY - 25

if y > ButtonY and _
y < ButtonY + 70 and _
x > ButtonX and _
x < ButtonX + 75 then
ButtonX = ButtonX + 10
redraw = 1
end if

if y > ButtonY and _
y < ButtonY + 70 and _
x > ButtonX + 75 and _
x < ButtonX + 150 then
ButtonX = ButtonX - 10
redraw = 1
end if

if y > ButtonY and _
y < ButtonY + 35 and _
x > ButtonX and _
x < ButtonX + 150 then
ButtonY = ButtonY + 10
redraw = 1
end if

if y > ButtonY + 35 and _
y < ButtonY + 70 and _
x > ButtonX and _
x < ButtonX + 150 then
ButtonY = ButtonY - 10
redraw = 1
end if

'Move button as needed
if redraw = 1 then
#main.other "!locate ";ButtonX;" ";ButtonY;" 155 65";
#main "refresh"
redraw = 0
end if

wait


[other]
wait

[me]
notice "Thanks for voting!"

[quit] 'End the program
close #main
end


Home

Password Textbox API

Character Replacement

LB Isam Library

Beginning Games 2

Rubber Band Objects

WMLiberty Primer

LB Browser

Beginning Programming 5

INPUTTO Demo

Chase Button

Questionaire Wizard

MIDI Output Thoughts

MIDI-Tunes

Play MIDI DLL

Directory Search Function

Newsletter help

Index