作为非托管 HWND 子级的托管表单

发布于 2024-08-31 04:29:56 字数 809 浏览 1 评论 0原文

我需要将 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

再次调用,一切正常。 这是怎么回事?!?

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:

HWND Error http://www.freeimagehosting.net/uploads/f29bc27823.png

Call it again, everything works fine.
What's going on?!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2024-09-07 04:29:56

可能是因为 rh_wnd 为空?至少有 2 种情况您会从 MainWindow() 返回 null。检查可能是个好主意

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

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

希望这有帮助。

Possibly because rh_wnd is null? There are atleast 2 cases where you would return null from MainWindow(). Might be a good idea to check

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

And if the above stops the errors, you might want to check which of the above conditions returns null, and go from there.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文