Proccess.start (mdi) Help Please

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
7 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Hello i am trying to boot an external program inside an MDI as a child form so that i may add handlers to button presses
to suspend the use of them i am using this code
Code: Select all
        Try
            proc = Process.Start(My.Settings.App_Path, String.Format("{0} {1} {2}", "", "12345", My.Settings.Server_Path))
            proc.WaitForInputIdle()
            SetParent(proc.MainWindowHandle, Me.Handle)
            SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
        Catch ex As Exception
        End Try
and it boots it Fine but it is no a child its booting over the top of my program and acting tottaly independent any ideas on a fix please
User avatar
bisnes_niko
Serious Programmer
Serious Programmer
Posts: 409
Joined: Tue Aug 24, 2010 1:21 pm

Removed old post, here's the new post:

I guess this is what you want to do:
1.png

Heres the full code:
Code: Select all
Public Class Form1
    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 Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZE As Integer = 61488
    Dim proc As Process

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim form As New Form
        form.MdiParent = Me

        form.Text = "Notepad inside the Form!"

        form.BackColor = Color.Green


        form.Show()

        proc = Process.Start("C:\WINDOWS\notepad.exe")
        proc.WaitForInputIdle()

        SetParent(proc.MainWindowHandle, form.Handle)
        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)


    End Sub
End Class
You do not have the required permissions to view the files attached to this post.
Last edited by bisnes_niko on Fri Jan 04, 2013 8:01 pm, edited 1 time in total.
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Add to Code:
Code: Select all
form.TopLevel = false
this allow the new "form" to be added to an existing form.

and BTW,

if you add a MsgBox() to your Tyr Catch block.
you will underswtand more what type of error you atr getting.
Code: Select all
Try

Catch ex As Exception
     MsgBox(ex.ToString)
End Try
on a error or not, the MsgBox() will tell you what is going on.
Image
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Thank you both but that code give me this error but loads both the program and a blank form system.invalidoperationexception: Process has exitedm, so the requested
information is not avaiable
User avatar
bisnes_niko
Serious Programmer
Serious Programmer
Posts: 409
Joined: Tue Aug 24, 2010 1:21 pm

muttley1968 wrote:
Thank you both but that code give me this error but loads both the program and a blank form system.invalidoperationexception: Process has exitedm, so the requested
information is not avaiable
#muttley1968 did you try the updated code I posted or the older one? This works fine on notepad.exe, but not working properly on some programs.

EDIT: Actually it works with everything I tested, just edit the WaitForIdle to:
Code: Select all
      Threading.Thread.Sleep(5000) 
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Same thing is still hapening i am trying to make it start minecraft i dont know if that makes a diffrence but that is what i need to start
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Sorry for double post but anyone got any ideas cant move on in my project until this part is working :(
7 posts Page 1 of 1
Return to “Coding Help & Support”