I am using SetParent
to host external app in my app (using WindowsFormHost
).
The flow is like that:
- I open my app
- I open the external app
programmaticly
- I use SetParent to host it within my app.
Due to the flow above, when the external app opens, I can see it in the taskbar/task manager for a split second (until the parent is set).
Can I somehow change the order that it will first set the parent and then open the app? all I want is to avoid what I just described..
If you have any other solution for my problem I will gladly accept it.
EDIT:
This is my code
string strPres = @"C:\Users\Ron\Desktop\Create an Office Mix.pptx";
oPPT = new Microsoft.Office.Interop.PowerPoint.Application();
oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
objPresSet = oPPT.Presentations;
objPres = objPresSet.Open(strPres, MsoTriState.msoFalse,
MsoTriState.msoFalse, MsoTriState.msoTrue);
objPres.SlideShowSettings.ShowType = Microsoft.Office.Interop.PowerPoint.PpSlideShowType.ppShowTypeWindow;
objPres.SlideShowSettings.Run();
objPres.Windows[1].Close();
objPres.Saved = MsoTriState.msoTrue;
uint oPPTID;
GetWindowThreadProcessId(new IntPtr(oPPT.HWND), out oPPTID);
_process = Process.GetProcessById((int)oPPTID);
_process.WaitForInputIdle();
SetParent(_process.MainWindowHandle, _panel.Handle);
You can't call SetParent() until you know the window handle. The app creating its window inevitably also causes the taskbar button to get created, no way to override this. ProcessStartInfo.WindowStyle could be a workaround when you ask for Hidden, except that the vast majority of apps ignore this request.
You can only be quick about it and use the same mechanism that the shell uses to notice the window getting created. And get ahead of it, that requires SetWindowsHookEx(). Very painful to do from a .NET app, the WH_SHELL hook requires a DLL that can be injected into the process so it can't be written in C#. There's a Codeproject.com project that helps, located here. It is quite dated, YMMV.