Results 1 to 3 of 3

Thread: open 3rd party exe in my winform as tab?

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    open 3rd party exe in my winform as tab?

    I wanted to open a exe as a tabs in program that im creating.

    so far i haven't had much luck.

    the code ive been trying to use is

    c# Code:
    1. public class Native
    2.         {
    3.             [DllImport("user32.dll", SetLastError = true)]
    4.             private static extern uint SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    5.             public static void LoadProcessInControl(string _Process, Control _Control)
    6.             {
    7.                 System.Diagnostics.Process p = System.Diagnostics.Process.Start(_Process);
    8.                 p.WaitForInputIdle();
    9.                 Native.SetParent(p.MainWindowHandle, _Control.Handle);
    10.             }
    11.         }

    but even though it runs with out error i don't get anything when i run the method like so.


    Code:
    Native.LoadProcessInControl(@"D:\WINDOWS\notepad.exe", this.splitContainer1.Panel2);

    any ideas if im barking up the right tree or why this code might not be working?

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: open 3rd party exe in my winform as tab?

    You are on the right track. Odds are your problem is that the window position is loading off the screen. You can call SetWindowPos to move the window to the top left corner:

    Code:
        [DllImport("user32.dll", SetLastError = true)]
        private static extern uint SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
        [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
        
        public static void LoadProcessInControl(string _Process, Control _Control)
        {
            uint SWP_NOSIZE = 1;
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(_Process);
            p.WaitForInputIdle();
            Native.SetParent(p.MainWindowHandle, _Control.Handle);
            SetWindowPos(p.MainWindowHandle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE);
        }

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: open 3rd party exe in my winform as tab?

    that's what it was

    thanks

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