代码之家  ›  专栏  ›  技术社区  ›  David Rutten

作为非托管HWND的子级的托管窗体

  •  2
  • David Rutten  · 技术社区  · 15 年前

    我需要把我的St.Welo.Fr.s表单显示为非托管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 Error http://www.freeimagehosting.net/uploads/f29bc27823.png

    发生什么事?!?

    1 回复  |  直到 15 年前
        1
  •  2
  •   chkdsk    14 年前

    可能是因为rh-wnd为空?至少有两种情况下,您将从MainWindow()返回null。也许是个好主意

    IWin32Window rh_wnd = Rhino.RhinoApp.MainWindow();
    if ( rh_wnd != null )
       DocEditor.Show(rh_wnd);
    

    如果上面的操作停止了错误,您可能需要检查上面哪个条件返回null,然后从那里开始。

    希望这有帮助。

    推荐文章