'获得鼠标指针位置函数
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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'设置窗体位置 函数
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags 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
Const StringLen = 80
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Private Sub Form_Click() '这里是窗体点击置顶和取消
Dim CancelVal As Long
Static Choose As Integer
If Choose = 0 Then
CancelVal = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
Me.Caption = "已经成为顶层窗体"
Choose = 1
Else
CancelVal = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
Me.Caption = "已还原为一般窗口"
Choose = 0
End IfEnd Sub
Private Sub Form_Load()
Timer1.Interval = 100 '设置timer属性
Form1.Caption = "单击本窗体成为顶层窗体"
End Sub 
------------------------------------------------
Private Sub LABEL1_Click(Index As Integer)
Form_Click
End Sub
-------------------------------------------------Private Sub Lb1_Click()End SubPrivate Sub Timer1_Timer()
Dim PointXY As POINTAPI
Dim WinHwnd&, WinCancelValue As Long
Dim WinCaption As String * StringLen
Dim ClassName As String * StringLen
GetCursorPos PointXY
WinHwnd = WindowFromPoint(PointXY.x, PointXY.y)
'WinCancelValue = GetWindowText(WinHwnd, WinCaption, StringLen)
'下一句若为此句就会非发关闭:WinCancelValue = SendMessage(WinHwnd, WM_GETTEXT, StringLen,WinCaption) 缺少ByVal
WinCancelValue = SendMessage(WinHwnd, WM_GETTEXT, StringLen, ByVal WinCaption)
WinCancelValue = GetClassName(WinHwnd, ClassName, StringLen - 1)
Label1(0).Caption = "鼠标的X坐标:" & PointXY.x
Label1(1).Caption = "鼠标的Y坐标:" & PointXY.y
Label1(2).Caption = "鼠标所在窗口句柄为:" & WinHwnd
Label1(3).Caption = "窗口的标题为:" & Trim(WinCaption)
Label1(4).Caption = "窗口的类名为:" & ClassName
End Sub
为什么在横线中间出现错误
过程声明与同名事件或过程的描述不匹配