作为非托管 HWND 子级的托管表单
我需要将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为 rh_wnd 为空?至少有 2 种情况您会从 MainWindow() 返回 null。检查可能是个好主意
,如果上述停止了错误,您可能需要检查上述哪个条件返回 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
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.