• Welcome to Dark Bit Factory & Gravity.
 

Mouse Pointer

Started by SAB, August 27, 2006

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SAB

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?


Shockwave

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.
Shockwave ^ Codigos
Challenge Trophies Won:

SAB

I am useing setmouse and getmouse.
I just wanna be able to change the graphic pointer into something else like a crosshair.
Any ideas?

Clyde

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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

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
Challenge Trophies Won:

Clyde

Could the "windows.bi" be used to get the position of the mouse ala TinyPtc? 
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

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
Challenge Trophies Won:

Clyde

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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

It came to me in a vision.
Jim
Challenge Trophies Won:

Shockwave

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.
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

Ok then, any ideas on how I'd check for a mousebutton being used with the windows.bi and tinyptc please dude?

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

Maybe Jim knows? Or someone else. I am stuck on this too!
Shockwave ^ Codigos
Challenge Trophies Won:

Jim


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

Jim
Challenge Trophies Won:

Clyde

Cheers Jim you star. Your help is really appreciated and thankyou.

All the best,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

That had been pissing me off for such a long time, you're a real gent Jim. Thank you.
Shockwave ^ Codigos
Challenge Trophies Won:

psygate

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
He who controlles the minds commands the many.
He who commands the many, conqueres the minds.

Shockwave

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
Shockwave ^ Codigos
Challenge Trophies Won: