Solved

Mouse Possition

Posted on 2001-06-25
4
119 Views
Last Modified: 2010-05-02
Hi all.
All I need to know is how to get the mouse possition
on the screen.
I am using VB6,and know how to work with the mouse events
in a form or object. But I need a way to find the mouse
possition without writing a code for each form or object
in my program.
I know that the solution will be an API function,but I am
not good in APIs.
Can anybody help?
Thank you
0
Comment
Question by:HESUS
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6224150
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type POINTAPI
        x As Long
        y As Long
End Type

Private Sub Timer1_Timer()
    Dim pntCurrent As POINTAPI
    GetCursorPos pntCurrent
    x = pntCurrent.x * Screen.TwipsPerPixelX
    y = pntCurrent.y * Screen.TwipsPerPixelY
End Sub


This returns the mouse position in twips relative to the screen in its entirety, not the postion in the form. You would have to factor in the position and size of the form and any control contained therein to handle this correctly.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6224155
TimCottee: curious why you would need the DeleteFile API hehe
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6224302
Part of another question, left over from there, good point. HESUS, you can remove that line it is irrelevant here!
0
 

Author Comment

by:HESUS
ID: 6225070
Works perfect.
Thank you very much.
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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

947 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

23 Experts available now in Live!

Get 1:1 Help Now