如何在本机窗口上显示托管控件? [英] How to display managed control on native window?

查看:143
本文介绍了如何在本机窗口上显示托管控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C ++ / CLI,如何在以本地代码创建的窗口上显示托管控件(例如:System :: Windows :: Forms :: Panel ^)。



外部程序调用我的本地方法,其中我可以通过

访问它的窗口

  SubclassWindow(hNativeWindow,MyNativeWindowProc);然后我创建类似的控制:








$ b

  MyNameSpace :: MyControl ^ ctrl = osozKomunikator = gcnew MyControl(SomeText,hNativeWindow); 
ctrl-> Show();

MyControl 源自 System :: Windows :: Forms :: UserControl ,并已覆盖 CreateParams ,将Parent设置为 hNativeWindow





请帮助。

div class =h2_lin>解决方案

Windows Forms支持在本地窗口中像ActiveX一样托管自.Net 1.1 。主机需要实现一些接口,但。 MFC 8.0包装在CWinFormsDialog和CWinFormsView中的必要代码。如果可以,使用MFC的支持类。如果你不能,从Visual C ++ 2005或更高版本安装MFC,并检查MFC的OLE支持类的源代码,如COleControlContainer,COleControlSite等。


Using C++/CLI, How to display a managed control (eg. System::Windows::Forms::Panel^) on a window created in native code?

An external program calls my native method where i can access it's window via

SubclassWindow(hNativeWindow, MyNativeWindowProc);

Then I create control with something similar to:

MyNameSpace::MyControl^ ctrl = osozKomunikator = gcnew MyControl("SomeText", hNativeWindow);
ctrl->Show();

MyControl is derived from System::Windows::Forms::UserControl and has overriden CreateParams to set Parent to hNativeWindow.

As the result the control flashes and dissapears, does not show at all or shows only after I slow down the execution with the debugger.

Please help.

解决方案

Windows Forms supports being hosted like ActiveX in native windows since .Net 1.1. The host needs to implement some interfaces, though. MFC 8.0 wrapped around the necessary code in CWinFormsDialog and CWinFormsView. Use MFC's support classes if you can. If you can not, install MFC from Visual C++ 2005 or higher and check the source code of MFC's OLE support classes, like COleControlContainer, COleControlSite, etc.

这篇关于如何在本机窗口上显示托管控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆