Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 don't want to do this on my windows forms, the application I'm coding, but some other running application.

 

How can I have access to these stuff?

Posted
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 don't want to do this on my windows forms, the application I'm coding, but some other running application.

 

How can I have access to these stuff?

 

You'll have to dive into the world of Win32 Unmanaged API. You'll 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.

 

I'm going to give you a text changing example using SendMessage and WM_SETTEXT.

 

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, you'll 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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...