home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "Mouse Track"
- ClientHeight = 2280
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 4680
- LinkTopic = "Form1"
- ScaleHeight = 2280
- ScaleWidth = 4680
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command1
- Caption = "Start"
- Height = 495
- Left = 1200
- TabIndex = 1
- Top = 1440
- Width = 2295
- End
- Begin VB.Label Label1
- Caption = "Tracking the mouse."
- Height = 615
- Left = 360
- TabIndex = 0
- Top = 240
- Width = 3855
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
- ByVal yPoint As Long) As Long
- Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
- (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
- Private Type POINTAPI
- X As Long
- Y As Long
- End Type
- Private gStop As Boolean
- Private Sub Command1_Click()
- Dim mousePT As POINTAPI
- Dim prevWindow As Long
- Dim curWindow As Long
- Dim X As Long
- Dim Y As Long
- Dim className As String
- Dim retValue As Long
- 'Track mouse here
- If Command1.Caption = "Start" Then
- Command1.Caption = "Stop"
-
- gStop = False
- prevWindow = 0
-
- 'Track until user stops
- Do
- 'Stop tracking
- If gStop = True Then Exit Do
-
- Call GetCursorPos(mousePT)
-
- X = mousePT.X
- Y = mousePT.Y
-
- 'Get window under mouse
- curWindow = WindowFromPoint(X, Y)
-
- If curWindow <> prevWindow Then
-
- className = String$(256, " ")
- prevWindow = curWindow
-
- retValue = GetClassName(curWindow, className, 255)
- className = Left$(className, InStr(className, vbNullChar) - 1)
-
- If className = "SysListView32" Then
- Label1.Caption = "The mouse is over the desktop."
- Else
- Label1.Caption = "The mouse is over " & className
- End If
-
- End If
-
-
- DoEvents
-
- Loop
-
-
- 'Stop tracking the mouse
- Else
- Command1.Caption = "Start"
- gStop = True
- End If
- End Sub
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
- gStop = True
- End Sub
-