Run *.exe in DocumentWindow?

4 posts, 1 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. Answer
    Dimitar
    Admin
    Dimitar avatar
    2881 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. Jim
    Jim avatar
    1 posts
    Member since:
    May 2015

    Posted 06 Apr Link to this post

    Sorry to reply to an older thread, but I am attempting to achieve this as well, host another telerik winforms application within the DocumentWindow. What Dimitar posted works with notepad.exe, however with I haven't been able to recreate it using my basic RadForm application I created to host.

    Using notepad.exe, I am getting exactly the results I am looking for (telerik2.png). Unfortunately, using my winforms application seems to have no effect (telerik1.png).

     

    Thank you,

     

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 09 Apr Link to this post

     

    Hello, Jim,  

    Your question has already been answered in the support thread  you have opened on the same topic. Please, see our answer there for more information.
    We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

    Thank you for your understanding.

    However, I am posting the answer here as well in order the community to benefit from it. I would like to note that the provided approach in the referred forum post uses Windows API and our RadDock doesn't have any effect on it. The same piece of code can be executed in a standard WinForms application with an identical result. 

    After researching in general programming forums, it seems that the following threads may be suitable for your custom scenario:
    https://stackoverflow.com/questions/758494/how-can-i-run-another-application-within-a-panel-of-my-c-sharp-program
    https://stackoverflow.com/questions/35858788/launch-a-exe-application-not-notepad-inside-a-panel-in-a-winform-using-enum

    Please have in mind that RadDock is not intended to host external applications. However, it does support hosting other RadForms. Hence, if it is suitable for you case, I would recommend you to dock a separate form: https://docs.telerik.com/devtools/winforms/controls/dock/docking-usercontrols-and-forms/docking-singleton-forms

    I hope this information helps.  

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top