您的位置首页百科问答

vb中的statusbar的使用问题。。

vb中的statusbar的使用问题。。

'---Wonderfarm Studio 提供---

'在Form1上画一个Timer1就可以用了~

Option Explicit

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long '获取xPoint与yPoint坐标下窗体句柄~

Private Declare Function GetCursorPos Lib "user32" (LpPoint As POINTAPI) As Long '获取鼠标当前坐标,存在LpPoint里面~

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long '获取窗口类名

Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long '获取目标句柄包含的文本长度~

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long '这个当然就是获取文本了~

Private Type POINTAPI '定义POINTAPI结构,存放坐标用~

X As Long

Y As Long

End Type

Private Sub Form_Load()

Timer1.Interval = 100 '我设了个100,你要是觉得慢,可以改小

End Sub

Private Sub Timer1_Timer() '注释懒的写了...= =

Dim MousePos As POINTAPI

Dim CurrenthWnd As Long

Dim TargetObjText As String

Dim ClassName As String

Dim RetForClassName As Long

Me.Cls

GetCursorPos MousePos

Me.Print "当前鼠标坐标为: " & MousePos.X & "," & MousePos.Y

CurrenthWnd = WindowFromPoint(MousePos.X, MousePos.Y)

Me.Print "当前指向窗口句柄为: " & CurrenthWnd

ClassName = Space(256)

RetForClassName = GetClassName(CurrenthWnd, ClassName, 256)

Me.Print "当前指向窗口类为: " & Left(ClassName, RetForClassName)

TargetObjText = Space(GetWindowTextLength(CurrenthWnd) + 1)

GetWindowText CurrenthWnd, TargetObjText, 100

Me.Print "当前指向窗口文字内容为: " & TargetObjText

End Sub

'有时候本窗体会被其它窗体遮住,你可以试试用SetWindowPos把本窗体置于最前,这样就OK了~