I want to write a program that does the same as the desktop ( like second desktop ) , I mean I want to run processes GUI not on the explorer process, I want to run it on my Form. I found that I can use User32.dll and I found the code for that . here is the code:
private void LoadApplication(string path, IntPtr handle)
{
Stopwatch sw = new Stopwatch();
sw.Start();
int timeout = 10 * 1000; // Timeout value (10s) in case we want to cancel the task if it's taking too long.
Process p = Process.Start(path);
//p.WaitForInputIdle();
IntPtr Handle = new IntPtr();
for (int i = 0; Handle == IntPtr.Zero && i < 300; i++)
{
Handle = p.MainWindowHandle;
Thread.Sleep(10);
}
while (Handle == IntPtr.Zero)
{
System.Threading.Thread.Sleep(10);
p.Refresh();
if (sw.ElapsedMilliseconds > timeout)
{
sw.Stop();
return;
}
}
SetParent(Handle, handle); // Set the process parent window to the window we want
SetWindowPos(Handle, 0, 0, 0, 0, 0, 0x0001 | 0x0040); // Place the window in the top left of the parent window without resizing it
}
if I run that code with a path to cmd , internet Explorer or even notepad it's working fine , but when I try to run It with firefox or calc.exe its opening the program but not on my form - on the explorer.exe Maybe I am doing something wrong? or maybe there are another ways to do 'virtual desktop' as I want ?
thanx