Need a quick prog to show mouse location

Please..a quick program to show the current location (x,y) of the mouse on the screen ( without clicking or pressing a command button) just as it roves around.
rbendAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tureCommented:
rbend,

Create a form with noyhing but two labels on it. Then add this code...

Private Sub Form_Activate()
  Me.WindowState = vbMaximized
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Label1.Caption = X
  Label2.Caption = Y
End Sub

Ture Magnusson
Karlstad, Sweden
0
crazymanCommented:
this one will get the mouse position in relation to the screen not just when moved on the form

Option Explicit
Public Type POINTAPI
        X As Long
        y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


Private Sub Timer1_Timer()
'(This occurs like 1000 times a second)
'This dims the variable where the current cursor pos is held
Dim mousexy As POINTAPI
dim q as long
'This gets the current cursor pos
q = GetCursorPos(mousexy)

'This sets text1.text to the x value of the cursor position
Text1.Text = mousexy.X

'This sets text2.text to the y value of the cursor position
Text2.Text = mousexy.y

End Sub
0
tureCommented:
rbend,

This modification allows the form to occupy the entire screen, except for the taskbar if it is visible.

Private Sub Form_Activate()
  Me.BorderStyle = vbBSNone
  Me.WindowState = vbMaximized
End Sub

Private Sub Form_Click()
  Unload Me
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Label1.Caption = X
  Label2.Caption = Y
End Sub

/Ture
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

richardwadsCommented:
Quick fix for 50 points

open a standard VB project

Put two command buttons, four labels and a timer control on to the form.  Leave the default names.  Paste the following code into the code module for form1

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 Sub Command1_Click()
    Timer1.Enabled = True
    Command1.Enabled = False
    Command2.Enabled = True
End Sub

Private Sub Command2_Click()
    Timer1.Enabled = False
    Command2.Enabled = False
    Command1.Enabled = True
End Sub

Private Sub Form_Load()

    Timer1.Interval = 50
    Timer1.Enabled = False
    Command1.Top = 240
    Command2.Top = 240
    Command1.Left = 120
    Command2.Left = 1440
   
    Command1.Caption = "Start"
    Command2.Caption = "Stop"
   
    Label1.Top = 1080
    Label2.Top = 1080
   
    Label3.Top = 1320
    Label4.Top = 1320
   
    Label1.Left = 360
    Label3.Left = 360
   
    Label2.Left = 1080
    Label4.Left = 1080

    Label1.Caption = "Y"
    Label3.Caption = "Y"
   
    Command2.Enabled = False
   
End Sub

Private Sub Timer1_Timer()
    Dim pt As POINTAPI
    Dim lngRetVal As Long
   
    lngRetVal = GetCursorPos(pt)
   
    Label2.Caption = pt.x
    Label4.Caption = pt.y
End Sub
0
crazymanCommented:
call me paranoid but isnt richardwads the same as mine but just with poitioning the labels and some captions ...???
0
richardwadsCommented:
Easy crazyman.  

I thought the same thing after submitting my answer.

We obviously think alike.  
0
crazymanCommented:
hehe sorry no offence meant
0
Erick37Commented:
How about this:
Display current cursor position (screen coords) in your app, even if the mouse moves off the application.  Works everywhere except the taskbar.  No timer needed.

Option Explicit
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" _
    (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SetCapture Lib "user32" _
    (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long

Private pt As POINTAPI

Private Sub Command1_Click()
    'Capture the mouse moves
    Call SetCapture(hwnd)
End Sub

Private Sub Command2_Click()
    'Release mouse capture
    Call ReleaseCapture
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
        x As Single, y As Single)
    'Assuming twips scalemode
    pt.x = x / Screen.TwipsPerPixelX
    pt.y = y / Screen.TwipsPerPixelY
    Call ClientToScreen(hwnd, pt)
    Caption = "Screen  X: " & pt.x & " Y: " & pt.y
End Sub
0
rbendAuthor Commented:
Crazyman actually had what I wanted exactly.
I do thank the rest of you for helping.
You are all brilliant.
Crazyman please answer this.
0
crazymanCommented:
posting for points
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.