
关于获取记事本的文字代码。(VB)
Option Explicit
Private Const WM_GETTEXT = &HD
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal h1 As Long, ByVal h2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function RealGetWindowClass Lib "user32" (ByVal hwnd As Long, ByVal pszType As String, ByVal cchType As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () 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 Sub GetTxt()
Dim r As Long
Dim h1 As Long
Dim h2 As Long
Dim H As String
Dim dwText As String
h1 = GetForegroundWindow()
If h1 <> 0 Then
H = String(1024, 0)
r = RealGetWindowClass(h1, H, 1024)
dwText = Left(H, r)
If dwText = "Notepad" Then
h2 = FindWindowEx(h1, 0, "Edit", vbNullString)
If h2 <> 0 Then
H = String(1024, 0)
r = SendMessage(h2, WM_GETTEXT, 1024, ByVal H)
dwText = Left$(H, r)
If dwText <> "" Then
Text1.Text = dwText
Exit Sub
End If
End If
End If
End If
Text1.Text = ""
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Call GetTxt
End Sub
有不明白的问我。QQ:121935930
功能:当你打开记事本写东西就会发现。。。。