Board Logo
« Mouse control »

Welcome Guest. Please Login or Register.
Jan 16th, 2018, 3:29pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Mouse control  (Read 148 times)
Angelo2449
Member in Training
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 58
xx Mouse control
« Thread started on: Nov 4th, 2017, 01:46am »

Hi guys,
I would like to check the position of the mouse in a certain area, whether it is in the graphics area (graphicbox 800 x 600) or not.
I would like to know the position of the mouse to control an event.
How can I do? Thank you.
« Last Edit: Nov 4th, 2017, 01:54am by Angelo2449 » User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Mouse control
« Reply #1 on: Nov 4th, 2017, 05:27am »

I am thinking that the only way to achieve this is to use an API call to getCursorPos. There are examples on the LBPE but it needs Liberty BASIC.

I am assuming here that you are trying to find the cursor position anywhere on your desktop and not within a program window created by yourself.
User IP Logged

Angelo2449
Member in Training
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 58
xx Re: Mouse control
« Reply #2 on: Nov 5th, 2017, 04:54am »

I would like to know if the cursor is in the graphics window (Graphicbox) or in the normal window, to change the shape of the cursor from cross to arrow (with LB).
Thank you.
User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Mouse control
« Reply #3 on: Nov 5th, 2017, 07:17am »

You need to check where the mouse is. Either each event that fires or with a timer. This Liberty BASIC code uses a timer. Functions from LBPE.

Code:
nomainwin
graphicbox #w.gb, 10, 10, 150, 150
textbox #w.tb ,10,200,150,25
open "Drawing" for window as #w
#w "trapclose quit"
gbh=hwnd(#w.gb)

timer 100, [check]
wait

[check]
mh=GetMouseFocus()
#w.tb mh
if mh=gbh then cursor crosshair else cursor normal
wait

sub quit h$
timer 0
close #w
end
end sub

Function GetMouseFocus()
    'Returns the handle of the window or control whose
    'client area is under the mouse cursor.
    Struct GMFpoint, x As Long, y As Long
    Struct GMFrc, left As Long, top As Long, right As Long, bottom As Long
    Calldll #user32, "GetCursorPos", GMFpoint As Struct, ret As Void
    X = GMFpoint.x.struct
    Y = GMFpoint.y.struct
    Calldll #user32, "WindowFromPoint", X As Long, Y As Long, hWnd As Ulong
    Calldll #user32, "ScreenToClient", hWnd As Ulong, GMFpoint As Struct, ret As Void
    x = GMFpoint.x.struct
    y = GMFpoint.y.struct
    Calldll #user32, "GetClientRect", hWnd As Ulong, GMFrc As Struct, r As long
    Calldll #user32, "PtInRect", GMFrc As Struct, x As Long, _
        y As Long, PointOnClient As long
    If PointOnClient Then GetMouseFocus = hWnd
End Function

Function GetFocus()
    Calldll #user32, "GetFocus", GetFocus As Ulong
End Function

 
User IP Logged

Facundo
Board Moderator


member is offline

Avatar




PM

Gender: Male
Posts: 1302
xx Re: Mouse control
« Reply #4 on: Nov 5th, 2017, 11:26am »

But do you have a graphicBox, doesn't it Angelo? What about adding more graphicBoxes to catch the event when your mouse pointer moves leaving the main graphicBox?
Another idea, if you have some margins , using only one graphicBox, reading the mouse coordinates, and changing the pointer when it reaches the borders. Would that be enough good?
User IP Logged

cundo aka MSlayer
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Mouse control
« Reply #5 on: Nov 5th, 2017, 2:07pm »

As in my example it depends how fast the mouse moves. Windows needs a finite time to see the mouse and tell you where it is. So it is perfectly possible to "miss" the margin or fly through a bordering graphicbox.
User IP Logged

Angelo2449
Member in Training
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 58
xx Re: Mouse control
« Reply #6 on: Nov 6th, 2017, 05:55am »

Perfect!
Everything works as I wanted!
Thank you very much
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls