code_junkie

Reading from a text field in another application's window

Nov 12th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. HWND hwnd = (HWND)0x00310E3A;
  2. char szBuf[2048];
  3. LONG lResult;
  4.  
  5. lResult = SendMessage( hwnd, WM_GETTEXT, sizeof( szBuf ) / sizeof( szBuf[0] ), (LPARAM)szBuf );
  6. printf( "Copied %d characters. Contents: %sn", lResult, szBuf );
  7.  
  8. ...
  9. EnumWindows((WNDENUMPROC)on_enumwindow_cb, 0);
  10. ...
  11.  
  12. BOOL CALLBACK on_enumwindow_cb(HWND hwndWindow, LPARAM lParam) {
  13. TCHAR wsTitle[2048];
  14. LRESULT result;
  15. result = SendMessage(hwndWindow, WM_GETTEXT, (WPARAM) 2048, (LPARAM) wsTitle);
  16. ...
  17.  
  18. hwndEdit = FindWindowEx(hwndWindow, NULL, L"RichEdit20W", NULL);
  19.  
  20. result = SendMessage(hwndEdit, WM_GETTEXT, (WPARAM) 4096, (LPARAM) wsText);
  21.  
  22. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  23. Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
  24.  
  25. Dim MyStr As String
  26. MyStr = String(GetWindowTextLength(TextBoxHandle) + 1, Chr$(0))
  27. GetWindowText TextBoxHandle, MyStr, Len(MyStr)
  28. MsgBox MyStr
Add Comment
Please, Sign In to add comment