OS: Windows7 (64Bit)
Nice to meet you, I'm stuck on the subject, can you help me?
I'm trying to create a windows form application in Visual Basic and run a DOS window inside a form.
There is some information on the web and I tried to implement it for reference, but it does not work as expected.
On the sample program, if the program to be executed is Notepad (notepad.exe), it will operate as an MDI child form, but if it is a command prompt or calculator, the application will be executed, but it will start up independently instead of the child form. increase.
Does anyone know a good solution?
In that sample,
WaitForInputIdle() waits for the window to be created, but depending on the implementation of the target program, this wait may end before the window is created.
cmd seem to fall into this case, and he can get the handle properly if he waits for about 1 second and then gets it.
var proc = Process.Start("calc"); proc.WaitForInputIdle(); // 取得できてなければもう少し待ってみる while(proc.MainWindowHandle == IntPtr.Zero) Thread.Sleep(500); Console.WriteLine(proc.MainWindowHandle);
I wrote the above example briefly, but I think it is necessary to consider the case where a timeout is set in case the acquisition still fails, or the target program ends while waiting.