• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Retrieve Data from a foreign process !

I want to retrieve and store in a string variable  the text in an open NotePad document .

How do I go about this ?

1 Solution
Paste this onto a form with a command button, open a notepad document and press the button.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD

Private Sub Command1_Click()
Dim nHwnd As Long
Dim nEditHwnd As Long
Dim nText As String * 256

nHwnd = FindWindow("Notepad", vbNullString)
nEditHwnd = FindWindowEx(nHwnd, 0&, "Edit", vbNullString)

SendMessageSTRING nEditHwnd, WM_GETTEXT, 256, nText

MsgBox nText

End Sub
RAFAAJAuthor Commented:

I can't believe I missed that !

I didn't want to try the sendmessage API because I just read that you can't read data in a foreign Memory space.

Apparently, this is what is read and is called InterProcess Marshalling which doesn't always work.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now