Windows Explorer in VB.net
Hi,
I would like to know, is it possible to 'automate' an 'windows' in a VB application.
For e.g.
VB application of 1280x960,
half of it (640x960) [Box A] is used to have a 'windows' inside, where it can execute applications like a normal windows (Think of it like VPN/Remote Assistance, where an window inside an application).
Meanwhile, the another half of it [Box B], has a much smaller dialog that display exactly the same as [Box A], like a clone display of Box A (Think of it like a security camera).I need to do something like a admin system, similar to VPN/WMI where i have [Application A] that can view probably 6 Windows from 6 different PC/Monitors in smaller boxes preview and able to control them. (Maybe except for playing video/audio as it seems quite impossible)
Any help or comments regarding this will definitely helps!!Thanks,
Elvin
Answers
Elvin Ho wrote: I need to do something like a admin system, similar to VPN/WMI where i have [Application A] that can view probably 6 Windows from 6 different PC/Monitors in smaller boxes preview and able to control them. (Maybe except for playing video/audio as it seems quite impossible)
Hi Elvin,
Based on my understanding, you wish to run/control several applications inside VB.NET Form.
Please check the following code sample. I divide Form into four Panel areas and load/run application inside each Panel control.
Prerequisites: arrange four Panel controls on Form1.
Code BlockImports System.Runtime.InteropServices
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim proc As Process
'Run Notepad application inside Panel1 control
proc = Process.Start("Notepad.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
'Run Calc application inside Panel2 control
proc = Process.Start("Calc.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel2.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
'Run Wordpad application inside Panel3 control
proc = Process.Start("Wordpad.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel3.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
'Run Freecell application inside Panel4 control
proc = Process.Start("Freecell.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel4.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
End Class
Here is the illustration:

Reference: Run program in panel
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2291136&SiteID=1
Happy New Year!
Martin
All Replies
Elvin Ho wrote: I need to do something like a admin system, similar to VPN/WMI where i have [Application A] that can view probably 6 Windows from 6 different PC/Monitors in smaller boxes preview and able to control them. (Maybe except for playing video/audio as it seems quite impossible)
Hi Elvin,
Based on my understanding, you wish to run/control several applications inside VB.NET Form.
Please check the following code sample. I divide Form into four Panel areas and load/run application inside each Panel control.
Prerequisites: arrange four Panel controls on Form1.
Code BlockImports System.Runtime.InteropServices
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim proc As Process
'Run Notepad application inside Panel1 control
proc = Process.Start("Notepad.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
'Run Calc application inside Panel2 control
proc = Process.Start("Calc.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel2.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
'Run Wordpad application inside Panel3 control
proc = Process.Start("Wordpad.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel3.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
'Run Freecell application inside Panel4 control
proc = Process.Start("Freecell.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel4.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
End Class
Here is the illustration:

Reference: Run program in panel
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2291136&SiteID=1
Happy New Year!
Martin
hi Martin,
that really help me as well.
thanks for the code.
Sami Hostan
Hi Martin,
Great! Exactly what i needed. Thanks alot!!!
Thanks
Elvin
Hi Sami and Elvin,
You're welcome!
Thank you for your active participation in MSDN forums.
- Hey Martin,
This is really cool, thanks for posting this code. Let me ask you another question about this - once I have an app running within a panel using this code is there a way I can use SendKeys to automate having it run a function?
What I'm trying to do is use this to open Wordpad with a file. Then if the user of my GUI clicks a button I would like to tell my Wordpad to open a different file.
Because it's embedded though I can't use AppActivate with the processID, it tells me a processID of zero is invalid.
Any ideas?
Thanks, - Hi guys,
The code posted worked great for notpad and the other programs, though when I tried to put Explorer.exe in, it did not work, am I missing something here?
Here's the code I tried.
Imports System.Runtime.InteropServices
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim proc As Process
proc = Process.Start("explorer.exe")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
End Class
This is the error I'm getting,
Process has exited, so the requested information is not available.
I must be missing something here?
Thanks
Newander

