This is a migrated thread and some comments may be shown as answers.

Run *.exe in DocumentWindow?

3 Answers 103 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Oleg
Top achievements
Rank 1
Oleg asked on 07 May 2015, 03:46 PM

Hello,

Probably little bit strabeg question:

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

Thank you.

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 12 May 2015, 10:43 AM
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.

 
0
Jim
Top achievements
Rank 1
answered on 06 Apr 2020, 05:46 PM

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,

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Apr 2020, 08:06 AM

 

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.
Tags
Dock
Asked by
Oleg
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jim
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or