Visual Basic 6.


- 2


13.7. MouseMov

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 IpClassName 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 Commandl_Click()

Dim mousePT As POINTAPI

Dim prevWindow As Long, curWindow As Long

Dim X As Long, Y As Long

Dim className As String

Dim retValue As Long

If Commandl.Caption = "Start" Then

Commandl.Caption = "Stop"

gStop = False prevWindow = 0

,

Do

If gStop = True Then Exit Do

Call GetCursorPos(mousePT)

X = mousePT.X

Y = mousePT.Y

,

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

Labell.Caption = "The mouse is over the desktop."

( .)

Else

Labell.Caption = "The mouse is over" & className

( ...)

End If

End If

DoEvents

Loop

Else

Command1.Caption = "Start"

gStop = True

End If

End Sub

 

Private Sub Form QueryUnload(Cancel As Integer,

UnloadMode As Integer)

gStop = True

End Sub

MousePos, ­ -.