Results 1 to 8 of 8

Thread: Mouse Position

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Perth, WA
    Posts
    35

    Post

    How do i get the position of the mouse??

    i wanna make a second cursor thing follow it round according to its position

    frivolous i know but any help would be appreciated

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Post

    Put this in the MouseMove event of your form and you'll get the idea. Debug.Print "X coordinate is " & X & " Y coordinate is " & Y BTW I think you will need to put code in all of your form's objects as well as the form.

    ------------------
    Marty

    [This message has been edited by MartinLiss (edited 11-30-1999).]

  3. #3
    Addicted Member
    Join Date
    May 1999
    Location
    Californ-I- A
    Posts
    207

    Post

    Also, as Aaron showed me in a question I posted earlier, the GerCursorPos API will return the position of the cursor in pixels with reference to the top left corner of the screen. Then, although I may be wrong, I've only been experimenting for a couple hours with this, you can multiply the result by 15 to get a value in twips.

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

    Private Type POINTAPI
    x As Long
    y As Long
    End Type

    Private Sub Form_Load()
    Timer1.enabled = True
    Timer1.interval = 100
    End Sub

    Private Sub Timer1_Timer()
    Dim tPos as POINTAPI
    Call GetCursorPos(tPos)
    Label1.Caption = "Pixels: " & tPos.x & "," & tPos.y
    Label2.Caption = "Twips: " & Str(tPos.x * 15) & "," & Str(tPos.y * 15)
    End Sub


    This, as far as my own experiments have me thinking, will have the two labels showing the mouse's current position, one in pixels and one in twips.

    Hope that is of some help to ya.

    This

    ------------------
    Micah Carrick
    Ordinary joe with a new found passion for code.
    http://micah.carrick.com
    micah@carrick.com

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Actually, depending on the current screen resolution, there aren't always 15 twips in a pixel. To make it always correct, use the ScaleX and ScaleY functions:

    Replace:
    1) tPos.x * 15
    2) tPos.y * 15
    With:
    1) ScaleX(tPos.x, vbPixels, vbTwips)
    2) ScaleY(tPos.y, vbPixels, vbTwips)

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879
    AIM: RYoni69

  5. #5
    Addicted Member
    Join Date
    May 1999
    Location
    Californ-I- A
    Posts
    207

    Post

    Oh really? Cool good to know. That makes sence ... duh

    ------------------
    Micah Carrick
    Ordinary joe, only not named joe.
    http://micah.carrick.com
    micah@carrick.com


  6. #6

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Perth, WA
    Posts
    35

    Post

    cheers guys, that helped a lot, all i needed was something that said where it was so i could feed back a negative value of the position to have the cursor mirrored across a line.

    i am having difficulty when its over an object and incase any one decides to try it, you get a very funky result when you put something like

    public sub picture1_MouseMove(button as ........)

    picture1.left = (3000 - x ) + picture1.width
    picture1.top = (3000 - x ) + picture1.height
    end sub

    public sub form1_resize()
    form1.width = 6000
    form1.height = 6000
    end sub

    i found that thats how you make the button avoid the cursor.

  7. #7
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    ok...this probably sounds ridiculous, but i am curious how you would find the mouse's position with respect to the form.top and form.left. i'm sure it is just a little math to be done, but for some reason i can't think of how to do it. i think my brain is fried from the all-nighter i just pulled trying to get this program written for the class i have in 3 hours.

  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You could Convert the Forms Top, Left Properties to Pixels and Subtract them from the X/Y Values.

    Or you could use the ScreenToClient API passing the X/Y Coords and a Window Handle to the Form.

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width