1,488
社区成员
发帖
与我相关
我的任务
分享
'模块部分
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const MK_LBUTTON = &H1
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public btnIndex As Long '全局变量,保存第多少个Button类型的窗口(其实就是按钮)
Public Function EnumChildProc_Notepad(ByVal hwnd As Long, ByVal lParam As Long) As Long '回调函数
Dim s As String
s = Space(255)
GetClassName hwnd, s, Len(s) '取得窗口的类型名
s = Left(s, InStr(s, Chr(0)) - 1)
If s = "Edit" Then '要是文本框的话...
s = Space(255) '文本多的话,这儿的255可以加大
SendMessage hwnd, WM_GETTEXT, Len(s), ByVal s
s = Left(s, InStr(s, Chr(0)) - 1)
MsgBox "记事本中的文本为:" & vbCrLf & s
End If
EnumChildProc_Notepad = True
End Function
'窗体部分
Private Sub Command1_Click()
Me.AutoRedraw = True
Dim hWindow As Long
hWindow = FindWindow(vbNullString, "无标题 - 记事本")
If hWindow = 0 Then
MsgBox "请打开一个记事本", vbInformation
Exit Sub
End If
EnumChildWindows hWindow, AddressOf EnumChildProc_Notepad, ByVal 0&
End Sub