咖啡心情

咖啡般的生活,咖啡般的心情

« 照烧鸡饭硬盘 »

VB.NET 获得其他应用程序信息

在做一个小程序,需要在一个应用程序中找到另一个程序的文本框还要获得里面的内容。

现在刚刚实现了找到并控制显示与隐藏,如何得到内容却是一直没有实现,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里的内容,不过总是取不到任何东西,不知道为什么……

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense  theme by BokeZhuti

辽ICP备06011536号 Cafemood.net