📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "作者:周金锋 主页:http://Jinfengnet.yeah.net"
ClientHeight = 3705
ClientLeft = 60
ClientTop = 345
ClientWidth = 6135
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3705
ScaleWidth = 6135
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 270
Left = 3000
TabIndex = 8
Top = 120
Width = 1935
End
Begin VB.CommandButton Command3
Caption = "确定"
Height = 255
Left = 5160
TabIndex = 7
Top = 480
Width = 855
End
Begin VB.TextBox Text2
Height = 270
Left = 3000
TabIndex = 6
Top = 480
Width = 1935
End
Begin VB.CommandButton Command2
Caption = "退出(&E)"
Height = 255
Left = 3960
TabIndex = 5
Top = 3360
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "开始抓取(&S)"
Height = 255
Left = 720
TabIndex = 4
Top = 3360
Width = 1455
End
Begin VB.TextBox Text1
Height = 2175
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 3
Top = 1080
Width = 5895
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 100
Left = 3120
Top = 2040
End
Begin VB.Label Label3
AutoSize = -1 'True
BackColor = &H80000000&
BackStyle = 0 'Transparent
Caption = "窗口标题:"
Height = 180
Left = 120
TabIndex = 2
Top = 840
Width = 810
End
Begin VB.Label Label2
AutoSize = -1 'True
BackColor = &H80000018&
Caption = "窗口类:"
Height = 180
Left = 120
TabIndex = 1
Top = 480
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackColor = &H80000018&
Caption = "窗口名柄: "
Height = 180
Left = 120
TabIndex = 0
Top = 120
Width = 900
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'
'该程序演示如何获取窗口的 句柄、类、标题(并可获取密码框中的密码) 以及 如何获得当前鼠标位置、如何使窗体总处于最顶端
'
'该程序作者:周金锋
'
'作者信箱:Jinfeng82@163.net
'
'作者主页:Http://Jinfengnet.yeah.net
'
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 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 Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 SetWindowText Lib _
"user32" Alias "SetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String) As Long
Private Sub Command1_Click()
If Command1.Caption = "开始抓取(&S)" Then
Timer1.Enabled = True
Command1.Caption = "停止抓取(&S)"
Else
Timer1.Enabled = False
Command1.Caption = "开始抓取(&S)"
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
jbsr = Text2.Text
lzjsb = Text3.Text
ret = SetWindowText(jbsr, lzjsb)
End Sub
Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H1 Or &H2 '使窗体位于最顶端
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
Dim tPoint As POINTAPI
Dim hWin As Long
Dim str As String * 255
Dim Abc As String * 64000
Dim Txt(64000) As Byte
Dim jbsr As Long
Dim lzjsb As Long
GetCursorPos tPoint '获得当前鼠标位置
hWin = WindowFromPoint(tPoint.x, tPoint.y) '获得窗口名柄
If hWin = Me.hwnd Or hWin = Command1.hwnd Or hWin = Command2.hwnd Or hWin = Text1.hwnd Then Exit Sub '确定窗口不在 Form1 中
GetClassName hWin, str, 255 '获得窗口类
SendMessage hWin, &HD, 64000, Txt(0) '获得窗口标题(也可使用 API 函数:GetWindowText,但效果不佳)
Label1.Caption = "窗口名柄: " & hWin
Label2.Caption = "窗口类: " & str
Text1.Text = StrConv(Txt, vbUnicode)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -