I need to show my System.Windows.Forms.Form as a child window of an unmanaged C++ HWND. This is the C# SDK code that retrieves the NativeWindow:
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;
}
This is how it is implemented in the plug-in:
IWin32Window rh_wnd = Rhino.RhinoApp.MainWindow();
DocEditor.Show(rh_wnd);
This works.... most of the time. But it also fails often the first time I call this code:
Call it again, everything works fine. What's going on?!?