Getting form properties from another running application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to retrieve properties such as position and size of another
application running at the same time as my .NET application. The other
application may or may not be .NET. I understand how to retrieve the handle
and window name, using, eg:

Dim proc() As Process
proc = Process.GetProcessesByName("process_name")
Dim i As System.IntPtr = proc(0).MainWindowHandle()

But I can't work out how to use the handle information to access the other
application's properties from windows.
 
Never mind, I have figured it out using PInvoke and User32.dll. eg.

Private proc() As Process

<DllImport("user32")> _
Public Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef rect As
Rectangle) As Integer

End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
proc = Process.GetProcessesByName("process_name")

Dim i As System.IntPtr = proc(0).MainWindowHandle()

Dim r As Rectangle

GetWindowRect(i, r)

End Sub
 
Back
Top