Hi,

Embedding exe's in a form, into a Panel, for example, is fine, for such apps as notepad.exe, calc.exe, etc, but NOT for cmd.exe which throws an exception, because it is not a UI. This code demonstrates:

Form with one button and one panel:


Code:
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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        Dim proc As Process 
        proc = Process.Start("notepad.exe")'also works with calc.exe but NOT with cmd.exe 
        proc.WaitForInputIdle() 
        SetParent(proc.MainWindowHandle, Me.Panel1.Handle) 
        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0) 
    End Sub 
End Class
It is the WaitForInputIdle that is causing the exception, because it only works on exe files with a message loop, which cmd.exe does not. See the bug report here:

http://msdn.microsoft.com/en-us/libr...e2(VS.85).aspx

Has this problem ever been solved by anyone?


Rock