在做一个小程序,需要在一个应用程序中找到另一个程序的文本框还要获得里面的内容。
现在刚刚实现了找到并控制显示与隐藏,如何得到内容却是一直没有实现,sendmessage也没研究明白。今晚就这样了,先把现有的代码贴上来,希望有牛人来指导吧……
<==============================代码======================================>
Public Class Form1
Private Declare Ansi Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Ansi Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Declare Auto Function ShowWindow Lib "user32" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As IntPtr
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal ByValhWnd As Long, ByVal ByValwMsg As Long, ByVal ByValwParam As Long, ByVal lParam As Object) As Long
Public Const wm_gettext = &HC4
Dim IntPtrnHandle As IntPtr
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Title As String = ""
Dim Resule As Long
Resule = FindWindow(vbNullString, "无标题 - 记事本")
IntPtrnHandle = FindWindowEx(Resule, IntPtr.Zero, "Edit", Nothing)
Dim tempstr = Space(255)
Dim strlong = Len(tempstr)
Dim rtn = SendMessage(IntPtrnHandle, wm_gettext, strlong, tempstr) '到底应该怎么写啊,唉!!!!!!
TextBox1.Text = tempstr
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShowWindow(IntPtrnHandle, 0) '显示
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ShowWindow(IntPtrnHandle, 5) '隐藏
End Sub
End Class
<==============================代码======================================>
希望通过SendMessage来获得edit里的内容,不过总是取不到任何东西,不知道为什么……