Results 1 to 3 of 3

Thread: Display MIDI Child of external application into your windows form.

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    13

    Question Display MIDI Child of external application into your windows form.

    Heyo! I'm not sure if this is even possible but it should be. I have an application that id like to show in my form but when I use the code from
    http://pinvoke.net/default.aspx/user32/SetParent.html

    It displays the FULL application I only want the child window from it.

    So for example. This is what it currently shows.

    Name:  b9ae7828490907920ff12d296f42a598.jpg
Views: 793
Size:  20.3 KB

    But id only like to show this.

    Name:  bd1c4d4c7248344ceb07a71e2d55dfe8.jpg
Views: 789
Size:  14.0 KB

    Here's the window layout in C.E



    Name:  d5344d84406a738b54ef479501a8fedc.jpg
Views: 727
Size:  11.8 KB

    XTPREPORT <-- Is what I want to show.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Display MIDI Child of external application into your windows form.

    How about you show us YOUR code? If there's something wrong with it then we can't magically know what that is without seeing it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    13

    Re: Display MIDI Child of external application into your windows form.

    Full code
    Code:
        'Declaring some constants to use with the SendMessage API
        Private Const WM_SYSCOMMAND As Integer = 274
        Private Const SC_MAXIMIZE As Integer = 61488
    
        'This is the API that does all the hard work
        <Runtime.InteropServices.DllImport("user32.dll")> _
        Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
        End Function
    
        'This is the API used to maximize the window
        <Runtime.InteropServices.DllImport("user32.dll")> _
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
    
        'This is the process that is currently set as a child to the form
        Dim parentedProcess As Process
     
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            'This is important! If you have a child process on your form, it will terminate along with your form if you do not set its parent to Nothing
            If Not parentedProcess Is Nothing Then
                SetParent(parentedProcess.MainWindowHandle, Nothing)
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' SetProcessParent("RblxDev")
            Dim myProcess As Process = New Process()
            Dim hwndParent As Long
    
            ' Get notepad's window handle...
            hwndParent = FindWindow(vbNullString, "Roblox - [Place1]")
    
            Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "Place1", "")
    
            ' Place it inside the MDI form...
            SetParent(hwndButton, Me.Handle)
    
    
    
        End Sub
        Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Long
    
        Private Declare Auto Function FindWindow Lib "user32.dll" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String _
        ) As IntPtr
    
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    
    
        Private Sub SetProcessParent(ByVal processName As String)
            'Retrieve an array of running processes with the given name
            Dim processes() As Process = Process.GetProcessesByName(processName)
            If processes.Length = 0 Then
                MessageBox.Show("No processes by that name found")
            Else
                'If there already is a process set as a child to our form, we set its parent to Nothing, to make it go back to its normal state.
                If Not parentedProcess Is Nothing Then
                    SetParent(parentedProcess.MainWindowHandle, Nothing)
                End If
                'This forms new child will be the process on index 0 of the array
                parentedProcess = processes(0)
                SetParent(parentedProcess.MainWindowHandle, Me.Handle)
                'SetParent(parentedprocess.MainWindowHandle,Me.Panel1.Handle) Try adding a panel to your form and use this line instead of the above line.
    
                'Now lets maximize the window of the process
                SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
            End If
        End Sub
    Form1 Code
    Code:
     ' SetProcessParent("RblxDev")
            Dim myProcess As Process = New Process()
            Dim hwndParent As Long
    
            ' Get notepad's window handle...
            hwndParent = FindWindow(vbNullString, "Roblox - [Place1]")
    
            Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "MDIClient", "")
             hwndButton = FindWindowEx(hwndParent, hwndButton, "Place1", "")
            
            SetParent(hwndButton, Me.Handle)
    But it doesn't show anything in the form.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width