Link to home
Start Free TrialLog in
Avatar of stnic
stnic

asked on

Follow Form 200 Points

Hi all,
   Anyone have any working code for a form that will follow the cursor (like the well known program with the cat). Just want it to follow the cursor and then when the form touches the cursor the program will end or some other effect?

Hope this has been understood ? I program like I write:)

Thanks

stnic
Avatar of adg
adg

Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private apoint As POINTAPI

Private Sub Form_Load()
    Timer1.Interval = 200
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim x As Long, y As Long
    Dim p As Long, q As Long
    GetCursorPos apoint
    x = apoint.x * Screen.TwipsPerPixelX
    y = apoint.y * Screen.TwipsPerPixelY
    p = Me.Left - (Me.Left - x) * 0.15
    q = Me.Top - (Me.Top - y) * 0.15
    Move p, q
End Sub
Avatar of stnic

ASKER

Hi adq,
   The form moves nice ! Now, do you have a solution for triggering an event when the form touches the cursor (collision)?
Also, how do I change the cursor into say an icon or is this possible ?

Thanks for responding :)

stnic
ASKER CERTIFIED SOLUTION
Avatar of adg
adg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stnic

ASKER

Hi adq,
   I meant change the cursor in general whether it is on a form or not when the program is running ? The code you displayed for moving the form will follow the cursor. I just wanted the cursor to be something other than an arrow, you know like an icon of a baseball bat or something while the form is following it :)

thanks

stnic
Avatar of stnic

ASKER

Hi adq,
   I meant change the cursor in general whether it is on a form or not when the program is running ? The code you displayed for moving the form will follow the cursor. I just wanted the cursor to be something other than an arrow, you know like an icon of a baseball bat or something while the form is following it :)

thanks

stnic
OK, this is a little out of my area but I've done some reading and here is what I think.  Please understand that I'm guessing, I don't want to mislead you.

It seems to be easy to change the cursor for a window.  For example, it should be easy to change the cursor for the desktop and of course for your form.  Changing the cursor for EVERYTHING is probably a matter of changing the system default cursor.  I don't know how to do that but could probably figure it out given enough time.  I think it still wouldn't work for everything but only for those windows using the default which should be most.   Or maybe we could change the entire "palette" of cursors (sorry, I don't know the correct terminology yet) and that would take care of of those cases where the default cursor isn't being used?  

Perhaps some sort of hooking solution might work by blocking messages that change the system cursor. But again this is just a guess.

Anyway, I don't normally guess or speculate like this on other peoples questions.  I prefer to answer with working code, but we've gone pretty far from the original question so I hope you don't mind some floundering around.

By the way, did that cursor touching thing work for you?
Avatar of stnic

ASKER

Hi adq,
   all the code you displayed worked fine! no problem on the cursor thing, was just asking was all :) thank you for taking the time to help a novice !

stnic
stnic, thanks for the points and especially for the A grade.  I appreciate it!  I don't know if you noticed this thread but it might have the answer to your question.

http://itworld.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20170321

Good luck to you.