Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Declare Function SendMessageByString Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Const WM_SETTEXT As Integer = &HC Public Const WM_GETTEXT As Integer = &HD Public Const WM_GETTEXTLENGTH As Integer = &HE Private Const GWL_ID As Long = -12 Private Function GetText(ByVal WindowHandle As Integer) Dim TextLen As Integer TextLen = SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0, 0) + 1 Dim Buf As String = New String(" "c, TextLen) SendMessageByString(WindowHandle, WM_GETTEXT, TextLen, Buf) Return Buf End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox2.Text = Nothing Dim editHwnd As Long, nextHwnd As Long, cID As Long Dim pHwnd As Integer pHwnd = FindWindow(vbNullString,"Form1") Do nextHwnd = FindWindowEx(pHwnd, editHwnd, Nothing, vbNullString) If nextHwnd = 0& Then Exit Do editHwnd = nextHwnd cID = GetWindowLong(editHwnd, GWL_ID) Dim txtfromapp As String txtfromapp = GetText(editHwnd) ' MsgBox(txtfromapp) TextBox2.Text = TextBox2.Text & vbNewLine & txtfromapp Loop End Sub Pomocou tohto kódu dokážem prečítať obsah Labelu/Textboxu... z inej, bežiacej aplikácie. Dá sa nejako podobne grabnúť aj obrázok ? Za odpoveď vopred veľmi pekne ďakujem
|