Solved

Follow Form 200 Points

Posted on 2001-08-16
8
140 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:stnic
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:adg
ID: 6395669
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
0
 

Author Comment

by:stnic
ID: 6395724
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
0
 
LVL 3

Accepted Solution

by:
adg earned 200 total points
ID: 6395751
hi stnic, glad thats what you were looking for!  Sorry I didn't read the part about cursor touching.  I'm not sure if I understand - do you mean something like this?

In Timer1_Timer()

    If (x >= Left) And _
        (x <= Left + Height) And _
        (y >= Top) And _
        (y <= Top + Width) Then
        Label1.Caption = "Cursor Touching"
    Else
        Label1.Caption = "Cursor Not Touching"
    End If

Regarding cursor icon, the form has a mouseicon property that will change the cursor icon while it is on the form.  Do you mean that or mean to change the cursor icon more general?  
0
 

Author Comment

by:stnic
ID: 6395789
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:stnic
ID: 6395806
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
0
 
LVL 3

Expert Comment

by:adg
ID: 6395848
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?
0
 

Author Comment

by:stnic
ID: 6396795
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
0
 
LVL 3

Expert Comment

by:adg
ID: 6399653
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now