Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: SAB on August 27, 2006

Title: Mouse Pointer
Post by: SAB on August 27, 2006
Does anyone know how to add mouse controls
into a freebasic program? includeing buttons

and sencond'ly how to change to pointer into say like crosshair?

Title: Re: Mouse Pointer
Post by: Shockwave on August 27, 2006
I depends. If you are using Tinyptc then there is no way of doing it that I know.
Are you using gfxlib?
If so then I think I can help.
Title: Re: Mouse Pointer
Post by: SAB on August 27, 2006
I am useing setmouse and getmouse.
I just wanna be able to change the graphic pointer into something else like a crosshair.
Any ideas?
Title: Re: Mouse Pointer
Post by: Clyde on August 27, 2006
It sounds to me that you may want to be looking into windows api stuff, sadly I can't help you there as i've not ventured into any of that myself.

Or just thinking whilst I was typing that above, it might be a simple case of using an image as your pointer and use the position of the mouse to place it.

Hope this is of some use and give some ideas to you.

Cheers,
Clyde.
Title: Re: Mouse Pointer
Post by: Jim on August 27, 2006
You need to use the Windows API to do that.
Use a freeware program to create some .cur cursor files, or download some, then

#include "windows.bi"
...
Dim c as HCURSOR
Dim arrow as HCURSOR

c=LoadCursor(0, "cursor.cur")
...
arrow=SetCursor(c)

When you call SetCursor() it returns back the previous cursor.
(might not work straight out of the tin - I typed this straight into the forum from MS help).

Jim
Title: Re: Mouse Pointer
Post by: Clyde on August 28, 2006
Could the "windows.bi" be used to get the position of the mouse ala TinyPtc? 
Title: Re: Mouse Pointer
Post by: Jim on August 28, 2006
Windows doesn't really work like that - you don't ask devices about their state, the devices tell you when something happened to them.
Every Windows window has a WindowProc which gets called any time something happens to the system or something happens to the window.  For instance, every time the mouse changes position, a WM_MOUSEMOVE message is sent to your window.  From there you store the xy position that comes with it, and use that until you get a new position sent.
In general, the keyboard works the same way, although you can get the state of the keymap other ways.

If you *must* interrogate the mouse directly do

Dim mousepos as POINT
Dim x as LONG
Dim y as LONG
...
GetCursorPos(@mousepos)
x=mousepos.x
y=mousepos.y

The problem with that is you have no idea whether some other app is using the mouse and you have to deal with multiple desktops and the like.  All that stuff is done for you if you use the WindowProc.

Jim
Title: Re: Mouse Pointer
Post by: Clyde on August 29, 2006
Cheers Jim, where are you looking to get hold of this info please dude? As I dont want to topic hijack ( sorry SAB ) and I want to look into checking the mousebuttons.

Thanks immensly,
Clyde.
Title: Re: Mouse Pointer
Post by: Jim on August 29, 2006
It came to me in a vision.
Jim
Title: Re: Mouse Pointer
Post by: Shockwave on August 29, 2006
Quote from: Clyde on August 29, 2006
Cheers Jim, where are you looking to get hold of this info please dude? As I dont want to topic hijack ( sorry SAB ) and I want to look into checking the mousebuttons.

Thanks immensly,
Clyde.

Well you could just start a new topic :) I don't think you've put this OT though, it's all relevant to the mouse.
Title: Re: Mouse Pointer
Post by: Clyde on August 29, 2006
Ok then, any ideas on how I'd check for a mousebutton being used with the windows.bi and tinyptc please dude?

Cheers,
Clyde.
Title: Re: Mouse Pointer
Post by: Shockwave on August 29, 2006
Maybe Jim knows? Or someone else. I am stuck on this too!
Title: Re: Mouse Pointer
Post by: Jim on August 29, 2006

Dim L as SHORT
Dim R as SHORT
Dim M as SHORT
L=GetAsyncKeyState(VK_LBUTTON) AND 32768
R=GetAsyncKeyState(VK_RBUTTON) AND 32768
M=GetAsyncKeyState(VK_MBUTTON) AND 32768

Again, though, you lose something by doing it this way.  It doesn't know if the mouse buttons have been swapped in the control panel for a left handed user.
Where do I get this stuff from?
MSDN, either as part of Visual Studio or online
GetAsyncKeyState (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/getasynckeystate.asp)

Jim
Title: Re: Mouse Pointer
Post by: Clyde on August 29, 2006
Cheers Jim you star. Your help is really appreciated and thankyou.

All the best,
Clyde.
Title: Re: Mouse Pointer
Post by: Shockwave on August 30, 2006
That had been pissing me off for such a long time, you're a real gent Jim. Thank you.
Title: Re: Mouse Pointer
Post by: psygate on September 10, 2006
Just wanted to post a (I think so) fast way of changing/erasing the mouse pointer with the freebasic build-in functions:

Yeah, It's easy, but it looks more or less good.


option explicit

dim as integer xm,ym
dim as integer ptr cross

screenres 640,480,32,,

setmouse ,,0
cross=imagecreate(32,32)
line cross,(0,32/2)-(32,32/2)
line cross,(32/2,32)-(32/2,0)

while inkey$<>chr(27)
    screelock
    cls
    getmouse xm,ym
    put (xm-16,ym-16),cross,trans
    screenunlock
wend
Title: Re: Mouse Pointer
Post by: Shockwave on September 11, 2006
Looks cool, works well :)

Quick edit as there was a small typo in the source above and it wouldn't run;


option explicit

dim as integer xm,ym
dim as integer ptr cross

screenres 640,480,32,,

setmouse ,,0
cross=imagecreate(32,32)
line cross,(0,32/2)-(32,32/2)
line cross,(32/2,32)-(32/2,0)

while inkey$<>chr(27)
    screenlock
    cls
    getmouse xm,ym
    put (xm-16,ym-16),cross,trans
    screenunlock
wend