tags:

views:

151

answers:

1

I am currently doing this as follows:


// _Container is the panel that the program is to be displayed in.

System.Diagnostics.Process procTest = new System.Diagnostics.Process();
procTest.StartInfo.FileName = "TEST.EXE";
procTest.StartInfo.CreateNoWindow = false;
procTest.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
procTest.Start();

procTest.WaitForInputIdle();
SetParent(procTest.MainWindowHandle, _Container.Handle);
MoveWindow(procTest.MainWindowHandle, 
           0, 0, _Container.Width, _Container.Height, true);


The problem I am having with this code is that some parts of the application UI no longer function properly once I change the MainWindowHandle (ie: buttons missing text).

Is there a way to do this without causing issues with the docked application? (Either through .net or user32)?

+1  A: 

First of all, instead of simply waiting 1.5 seconds, try calling procTest.WaitForInputIdle to wait until its message loop is free. You already are.

In general, I don't think it's possible to do this without modifying the program that you're hosting.

EDIT: You could try to keep the other program above your hosting area by hiding in from the taskbar, removing its title bar, moving it as your program moves, etc. However, this still wouldn't work perfectly; I recommend that you try to find some alternative.

Try contacting the original developers of the third-party application and asking for their advice.

SLaks
Thanks, I had noticed this and modified to WaitForInput about the same time you posted your reply, otherwise I would have left it in there for others to see what you were talking about. Sorry! Right now, most of the program that I am hosting, including UI, work fine when I change the MainWindowHandle, but some portions do not. Is there any way to host without changing the MainWindowHandle?
mikeh
It looks like you are correct. The third party application grabs it's MainWindowHandle when it launches and uses this stored handle in quite a few places, so all of its code using this stored value malfunctions. Fortunately, I was able to work with the original developers. The solution that we used was to add the ability to change the stored MainWindowHandle in the hosted application's API (a few lines of C++ code in the source), the rest of the code now works fine.
mikeh