大家好,我正在开发一个项目,我需要在c#面板中运行谷歌浏览器应用程序,但它不是图片中的代码。
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Process p = Process.Start(@"D:\\chrome.lnk");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, panel1.Handle); //Exception thrown here
}
例外文本。
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=İşlemden çıkıldığından istenen bilgiler kullanılamıyor.
Source=System
StackTrace:
konum: System.Diagnostics.Process.EnsureState(State state)
konum: System.Diagnostics.Process.get_MainWindowHandle()
konum: AnyMinWin.Form1.button1_Click(Object sender, EventArgs e) c:\users\anyone\documents\visual studio 2010\Projects\AnyMinWin\AnyMinWin\Form1.cs içinde: satır 36
konum: System.Windows.Forms.Control.OnClick(EventArgs e)
konum: System.Windows.Forms.Button.OnClick(EventArgs e)
konum: System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
konum: System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
konum: System.Windows.Forms.Control.WndProc(Message& m)
konum: System.Windows.Forms.ButtonBase.WndProc(Message& m)
konum: System.Windows.Forms.Button.WndProc(Message& m)
konum: System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
konum: System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
konum: System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
konum: System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
konum: System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
konum: System.Windows.Forms.Application.Run(Form mainForm)
konum: AnyMinWin.Program.Main() c:\users\anyone\documents\visual studio 2010\Projects\AnyMinWin\AnyMinWin\Program.cs içinde: satır 18
konum: System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
konum: System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
konum: Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
konum: System.Threading.ThreadHelper.ThreadStart_Context(Object state)
konum: System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
konum: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
konum: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
konum: System.Threading.ThreadHelper.ThreadStart()
InnerException: