Winforms在MFC内部没有CLR
我有一个MFC应用程序,该应用程序与CLR一起使用一些特定文件,但没有整个项目。
挑战是我想在MFC项目中嵌入Winforms用户控件,而没有使用CLR编译的整个项目。
如前所述,在现有的托管文件之一中,我创建了一种与CTRL进行交换的方法:
#include <afxwin.h>
#include <afxwinforms.h>
#include "Managedfile.h"
void CWinformsUtil::CreateFullListeUc(CDataExchange* pDX, int Idc)
{
CWinFormsControl<MainuserControlLib::UserControl2> m_ctrl1;
DDX_ManagedControl(pDX, Idc, m_ctrl1);
}
我在MFC App Source中的dodataexchange
方法内在dodataexchange
方法中调用此方法:
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
CWinformsUtil::CreateFullListeUc(pDX, IDC_STATIC1);
}
但是这种方法的问题是它不会显示Winforms用户控件。
I have an MFC application that uses some specific files with CLR but not the whole project.
The challenge is I want to embed a WinForms user control inside the MFC project without the whole project compiled with CLR.
As mentioned before, in one of the existing managed files I created a method that does the exchange with the ctrl like so:
#include <afxwin.h>
#include <afxwinforms.h>
#include "Managedfile.h"
void CWinformsUtil::CreateFullListeUc(CDataExchange* pDX, int Idc)
{
CWinFormsControl<MainuserControlLib::UserControl2> m_ctrl1;
DDX_ManagedControl(pDX, Idc, m_ctrl1);
}
And I am calling this method inside the DoDataExchange
method in the MFC app source:
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
CWinformsUtil::CreateFullListeUc(pDX, IDC_STATIC1);
}
But the problem with this approach is that it does not display the WinForms user control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了实现这一点,我所做的就是编译view.cpp文件。在其中。也需要在标题文件中导入该库
但是,只能通过简单地制定条件来引起托管代码的访问:
对于标题文件中的控件,我们还需要相同的方法:
In order to acheive this what i've did was to compile the view.cpp file in wich i want to display the user control in clr,then included <afxwinforms.h> in it .Also in the header file i need to import that library
but it should only be visile to managed code by simply making a condition :
and for declaring the control in the header file we need also the same approach: