Run *.exe in DocumentWindow?

2 posts, 0 answers
  1. Oleg
    Oleg avatar
    2 posts
    Member since:
    Jul 2011

    Posted 07 May 2015 Link to this post

    Hello,

    Probably little bit strabeg question:

    Is it possible to run some external WinForms exe in DocumentWindow?

    Thank you.

     

     

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 12 May 2015 Link to this post

    Hi Oleg,

    Thank you for contacting us.

    It appears that this is possible and you just need to use some methods from user32.dll. For example:
    private void radButton1_Click(object sender, EventArgs e)
    {
        DocumentWindow document = new DocumentWindow();
        document.Text = "New Document";
     
        this.radDock1.AddDocument(document);
     
        Process p = Process.Start("notepad.exe");          
        Thread.Sleep(500); //time is needed for the process starting
        SetParent(p.MainWindowHandle, document.Handle);
        SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);         
        MoveWindow(p.MainWindowHandle, 0, 0, document.Width, this.Height, true);
    }
     
    [DllImport("usesome r32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
     
    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
     
    [DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
    private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
     
    private const int GWL_STYLE = (-16);
    private const int WS_VISIBLE = 0x10000000;

    Please let me know if there is something else I can help you with. 

    Regards,
    Dimitar
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top