Ako získať obrázok z inej, bežiacej aplikácie [API]   otázka

VB.NET, WinAPI

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

nahlásit spamnahlásit spam -1 / 1 odpovědětodpovědět

ospravedlňujem sa, že som kód neoznačil ako kód :(

nahlásit spamnahlásit spam 0 odpovědětodpovědět
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

Pro příště....

nahlásit spamnahlásit spam 0 odpovědětodpovědět

S tímto problémem nemám zkušenosti, takže mohu nabídnout pouze teoretické řešení. Nicméně, pokud dovedete získat handle okna a pak si s jeho pomocí zjistíte lokaci a rozměry, nebude problém capturnout to okno pomocí procedury Graphics.CopyFromScreen.

nahlásit spamnahlásit spam 0 odpovědětodpovědět
                       
Nadpis:
Antispam: Komu se občas házejí perly?
Příspěvek bude publikován pod identitou   anonym.
  • Administrátoři si vyhrazují právo komentáře upravovat či mazat bez udání důvodu.
    Mazány budou zejména komentáře obsahující vulgarity nebo porušující pravidla publikování.
  • Pokud nejste zaregistrováni, Vaše IP adresa bude zveřejněna. Pokud s tímto nesouhlasíte, příspěvek neodesílejte.

přihlásit pomocí externího účtu

přihlásit pomocí jména a hesla

Uživatel:
Heslo:

zapomenuté heslo

 

založit nový uživatelský účet

zaregistrujte se

 
zavřít

Nahlásit spam

Opravdu chcete tento příspěvek nahlásit pro porušování pravidel fóra?

Nahlásit Zrušit

Chyba

zavřít

feedback