我需要将我的 System.Windows.Forms.Form 显示为非托管 C++ HWND 的子窗口。这是检索 NativeWindow 的 C# SDK 代码:
public static NativeWindow MainWindow()
{
Diagnostics.Process process = Diagnostics.Process.GetCurrentProcess();
if (null == process)
return null;
IntPtr handle = process.MainWindowHandle;
if (IntPtr.Zero == handle)
return null;
NativeWindow wnd = new NativeWindow();
wnd.AssignHandle(handle);
return wnd;
}
这是它在插件中的实现方式:
IWin32Window rh_wnd = Rhino.RhinoApp.MainWindow();
DocEditor.Show(rh_wnd);
这有效....大部分时间。但它也经常在我第一次调用此代码时失败:
HWND 错误 http://www.freeimagehosting.net/uploads/f29bc27823.png
再次调用它,一切正常。这是怎么回事?!?