How can I access form control propeties from other apps?

Nazgulled

Well-known member
Joined
Jun 1, 2004
Messages
119
I want to access some form controls (like a textbox and buttons) and read some properties for those controls; for the textbox I also want to be able to write some text on it... The thing is, I dont want to do this on my windows forms, the application Im coding, but some other running application.

How can I have access to these stuff?
 
Nazgulled said:
I want to access some form controls (like a textbox and buttons) and read some properties for those controls; for the textbox I also want to be able to write some text on it... The thing is, I dont want to do this on my windows forms, the application Im coding, but some other running application.

How can I have access to these stuff?

Youll have to dive into the world of Win32 Unmanaged API. Youll need the following procedures:
- SendMessage - PInvoke.NET - SendMessage
- FindWindow - PInvoke.NET - FindWindow
- FindWindowEx - PInvoke.NET FindWindowEx
- WM_SETTEXT - PInvoke.NET - WM_SETTEXT

The PInvoke links have the .NET Declarations and also provides example usage.

Im going to give you a text changing example using SendMessage and WM_SETTEXT.

Code:
Dim hWnd As Integer = 0

hWnd = FindWindow("notepad", vbNullString) Find Notepad

If hWnd = 0 Then
  MessageBox.Show("Notepad is not open.")
End If

hWnd = FindWindow(hWnd, 0, "edit", vbNullString) Find the Edit Box

SendMessage(hWnd, WM_SETTEXT, 0, "This is my Custom Text!")

This should work, youll want to use WM_GETTEXT to get the text from the Edit box. Win32 Unmanaged API is something that can be easy to learn if you read the documentation very closely.

Good Luck,
-Allen
 
Back
Top