0

Here I am trying to run some window based application(s) inside a window form's panel and allow me to minimize it inside. i was able to run and minimize inside this "notepad.exe" but not with win apps.

here's my code for reference(working only for notepad):

[DllImport("USER32.DLL")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);[DllImport("USER32.dll")]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

Process process = Process.Start("someapp.exe");
process.WaitForInputIdle();
SetParent(process.MainWindowHandle, this.panel1.Handle);
MoveWindow(process.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);

please kindly tell me if it's possible to achieve and how?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
David dela cruz
  • 145
  • 1
  • 2
  • 10
  • 1
    I would recommend to avoid such things (read [this](http://blogs.msdn.com/b/oldnewthing/archive/2013/04/12/10410454.aspx) and also google for "oldnewthing" and "SetParent" in general) to see why. My favourite quote "It is technically legal. ... It is also technically legal to juggle chainsaws." – Christian.K Aug 10 '15 at 06:42
  • so basically it's possible but not a good idea right? – David dela cruz Aug 10 '15 at 06:51

1 Answers1

0

Ok, all you need to do is to replace

process.WaitForInputIdle();

with

Thread.Sleep(500); // Allow the process to open it's window

this is the results app1 executes "For test app" several times and minimize them all