how can i open an exe file in a C# window?
i see an example in other site which open all open exe files in diffrent tabs.
but i want open my exe file in a panel ... how can i do this?
blah blah blah is here! blah blah » Close
2 answers
These sort of tricks are generally done by calling the API function SetParent.
Here's some sample code, assuming the exe is suitable for embedding:
EDIT
It's preferable to use proc.CloseMainWindow() to close a GUI process in an orderly fashion. However, sometimes (as with Word) this doesn't close the whole process (you can check this in Task Manager) so you'll then need to use proc.Kill() instead.
I've also added some code to position the top left hand corner of the exe's window at the top left hand corner of the panel and to make their dimensions the same using another API function, MoveWindow().
answered one year ago by:
17279
thank u my friend
i use this code and it doesnt work properly.
i mean when i normally run it, it open exe file like a seprate process and in its own window.
and when i put trace poit at this line:
proc.WaitForInputIdle();
program stops at this line when i click on continue button ,now exe file move to panel!
why this happen?
how can i open exe file in panel at start.
i mean exe file doesnt run saprately and from the first it open in panel.
answered one year ago by:
0
17279
The problem is that you need the handle of the exe's main window in order to call SetParent(). Now this handle isn't created when the process starts but sometime before the main window is displayed. It therefore recommends in the documentation (see http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx) that you should call the WaitForInputIdle() method to be sure that the handle has been created before trying to use it. An alternative to using this method would be to call Thread.Sleep for an interval of one or two seconds. However, this method is a bit 'hit or miss' because different applications take different times to start up and you can't even assume that a given application will always take the same time to start up. Also, even if you could get the handle before the main window is shown, MoveWindow won't work properly until it is. I therefore think that using WaitForInputIdle() is the best approach even if there is a noticeable flash as the application starts and is moved to the panel.