Solved

Mouse Possition

Posted on 2001-06-25
4
121 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

776 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