打印

[原创] 关于获取记事本的文字代码。(VB)

关于获取记事本的文字代码。(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
功能:当你打开记事本写东西就会发现。。。。
本帖最近评分记录
  • flyli 金币 +5 原创! 有共享受精神! 2006-12-1 20:21

TOP

很简单啊,没什么特别。
我觉得这种共享源代码的行为还是挺好的,
只要有耐心读完,
不会的人可以学到不少东西
会的人也可以看看他的特别之处啊~
三人行必有我师嘛~呵呵:handshake
学了6年了,还是初学者。。。。。。。。

TOP

呵呵,是啊,互相学习是编程很重要的一个环节。 :handshake

Processed in 0.024347 second(s), 6 queries, Gzip enabled