Jump to content
Fórum Script Brasil
  • 0

Executável como MdiChild

Wencesláu Pereira De Abreu Filho


O código abaixo somente funciona com o notepad.exe

Os demais executáveis (Calculadora, Word e Excel), abrem fora do formulário pai.

Que posso fazer para que qualquer executável rode dentro dos limites do MdiContainer?

Desde já, agradeço qualquer ajuda!

Public Class Form1

    Dim myProcess As Process = New Process()
    Public WithEvents Btn As Button = New System.Windows.Forms.Button
    Public Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As System.IntPtr

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        WindowState = FormWindowState.Maximized
        Text = "Executável Mdi Child"
        IsMdiContainer = True
        Btn.Location = New System.Drawing.Point(20, 20)
        Btn.Name = "Btn"
        Btn.Size = New System.Drawing.Size(100, 30)
        Btn.TabIndex = 1
        Btn.Text = " Abre executável "
        Btn.UseVisualStyleBackColor = True
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
        myProcess.StartInfo.FileName = "C:\Windows\notepad.exe"
        'myProcess.StartInfo.FileName = "C:\Windows\System32\calc.exe"
        'myProcess.StartInfo.FileName = "C:\Program Files (x86)\Microsoft Office\Office12\WinWord.exe"
        'myProcess.StartInfo.FileName = "C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE"
    End Sub

    Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn.Click
        SetParent(myProcess.MainWindowHandle, Me.Handle)
    End Sub
End Class

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...