Advertisement
IVDZ

SendMessage API Get Text From Notpad.exe

Aug 7th, 2014
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2. Public Class Form1
  3. Declare Function FindWindowA Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr 'Int32
  4. Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
  5. Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
  6. Public Const WM_GETTEXT = &HD
  7. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8. Dim ParentHWND As IntPtr = FindWindowA("Notepad", Nothing) ' جلب مقبض نافذة الرئسية او النافذة الأب
  9. Dim ChildHWND = FindWindowEx(ParentHWND, Nothing, "Edit", Nothing) 'جلب مقبض الليست فيو عن طريق الكلاس نايم الخاص بها
  10. Dim StringAddress = Marshal.AllocHGlobal(255) 'حجز مساحة 255 بايت في الذاكرة لوضع النص فيها
  11. Dim pp = SendMessage(ChildHWND, WM_GETTEXT, 255, StringAddress) ' ارسال الرسالة
  12. Dim text As String = Marshal.PtrToStringUni(StringAddress) ' جلب النص من العنوان الذي في الذاكرة
  13. MsgBox(text) 'عرض الرسالة
  14. End Sub
  15. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement