SetParent - Process - MDI - VB.NET

MatP

Newcomer
Joined
Oct 12, 2004
Messages
11
Hi,

First of all, my problem is in VB.NET 2003.

I'm trying to use Windows API SetParent to bring back a Process (it runs in a command prompt window) into my MDI form, but I can't figure out what I'm doing wrong.

This is my code :
Code:
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer

  Private Sub mnuCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCalculate.Click
        Dim myProcess As Process = New Process

        ' allow the process to raise events
        myProcess.EnableRaisingEvents = True

        ' add an Exited event handler
        AddHandler myProcess.Exited, AddressOf Me.ProcessExited
 
        myProcess.StartInfo.FileName = "C:\Eficos\Eficos.exe"
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
        myProcess.StartInfo.UseShellExecute = True
        myProcess.StartInfo.CreateNoWindow = False
        myProcess.Start()

        SetParent(myProcess.Handle.ToInt32, Me.Handle.ToInt32)

  End Sub

Thanks for the help,
Mat
 
Iceplug said:
You should probably be sending a Window Handle to SetParent instead of a Process Handle.
Use:
myProcess.MainWindowHandle.ToInt32
:)

Thank you, it works. :)
 
Back
Top