1

Situation

The title may be confusing but I am working on a project where I need to run any program inside my own program. There is a thread about this issue Here.

Problem

This solution is using the the win32 API and is attaching the program to a panel handle. I've made an adjustment to make this working in WPF sins it does not support calling handle on a control.

This piece of code will launch notepad.exe inside my own program. My idea was to dock it inside my program.

 [DllImport("user32.dll")] static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

 Process p = Process.Start("notepad.exe");
 HwndSource source = (HwndSource)HwndSource.FromVisual(DockPanel);
 SetParent(p.MainWindowHandle, source.Handle);

But now for some reason the program that I have opened whit the above approach can float in the boundaries of my program. Instead I only want it to be able to be docked to fill the hole dock panel. And not move out of it.

Question

How can I use boundaries so the program opened in my program will dock full in my dock panel and not move out of it. If there is a way without using dock panel it is not a problem.

What it should look like

enter image description here

What it is looking like now

enter image description here

Kcvin
  • 5,073
  • 2
  • 32
  • 54
Timon Post
  • 2,779
  • 1
  • 17
  • 32
  • 3
    Nope, this won't work. At all. Ever. Can't be done by blithely reparenting. As is discussed at a rate of about two questions a day at this very site. – David Heffernan Aug 10 '17 at 17:00
  • 2
    Just an idea: Use DWM thumbnail API to display other app inside yours. Run other app hidden. Forward clicks and key presses from your app to other app. Resize other app to the size of your "dock area" so the thumbnail image won't be scaled. – zett42 Aug 11 '17 at 06:09

0 Answers0