我想在我的.net应用程序(主要是video查看软件)中托pipe一个.exe文件,但某些应用程序不允许我使用它们的菜单或某些控件。 有没有人有过这个问题之前,或者为什么可能会发生的任何想法?
这是我的代码来承载应用程序:
#region Methods/Consts for Embedding a Window [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId); [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = true)] private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)] private static extern long GetWindowLong(IntPtr hwnd, int nIndex); [DllImport("user32.dll")] static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [DllImport("user32.dll", SetLastError = true)] private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags); [DllImport("user32.dll", SetLastError = true)] private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint); [DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)] private static extern bool PostMessage(IntPtr hwnd, uint Msg, int wParam, int lParam); private const int SWP_NOOWNERZORDER = 0x200; private const int SWP_NOREDRAW = 0x8; private const int SWP_NOZORDER = 0x4; private const int SWP_SHOWWINDOW = 0x0040; private const int WS_EX_MDICHILD = 0x40; private const int SWP_FRAMECHANGED = 0x20; private const int SWP_NOACTIVATE = 0x10; private const int SWP_ASYNCWINDOWPOS = 0x4000; private const int SWP_NOMOVE = 0x2; private const int SWP_NOSIZE = 0x1; private const int GWL_STYLE = (-16); private const int WS_VISIBLE = 0x10000000; private const int WM_CLOSE = 0x10; private const int WS_CHILD = 0x40000000; private const int WS_MAXIMIZE = 0x01000000; #endregion #region Variables private IntPtr hostedProcessHandle; private Process hostedProcess = null; private ProcessStartInfo hostedPSI = new ProcessStartInfo(); #endregion //Helper method to start a process contained within the form private void HostProcess(string processPath) { //Start the process located at processPath hostedPSI.FileName = processPath; hostedPSI.Arguments = ""; hostedPSI.WindowStyle = ProcessWindowStyle.Maximized; hostedProcess = System.Diagnostics.Process.Start(hostedPSI); //Stop watch is used to calculate time out period. Stopwatch sw = new Stopwatch(); sw.Start(); //Loop to aquire application handle. Exit loop if the time out period is past. do { hostedProcessHandle = hostedProcess.MainWindowHandle; if (sw.ElapsedMilliseconds > 10000) throw new TimeoutException(); } while (hostedProcessHandle == new IntPtr(0)); //Host the process in the forms panel. SetParent(hostedProcessHandle, this.panel1.Handle); SetWindowLong(hostedProcessHandle, GWL_STYLE, WS_VISIBLE + WS_MAXIMIZE); MoveWindow(hostedProcessHandle, 10, 10, this.panel1.Width - 20, this.panel1.Height - 20, true); } private void CloseHostedProcess() { hostedProcess.Kill(); }
这里是我的testing应用程序的主机VLC的屏幕截图,一些菜单和button,你可以看到灰色和不工作:
这不仅仅是VLC的一个问题 – 我也在托pipe其他应用程序时看到这个问题。
只是一个更新。 如果我右键单击VLC – >播放 – >添加和手动播放video回菜单栏再次工作。 但底部的video控制仍然不能正常工作! 他们改变颜色时翻转,但点击他们仍然无法正常工作!
我遇到问题的原因似乎是因为TeamViewer在后台运行。 我目前正试图找出为什么这导致我的问题,但停止TeamViewer的过程似乎纠正我的问题。