Solved

Follow Form 200 Points

Posted on 2001-08-16
8
141 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now