Winforms在MFC内部没有CLR

发布于 2025-02-08 06:40:52 字数 754 浏览 3 评论 0原文

我有一个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 技术交流群。

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

发布评论

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

评论(1

守不住的情 2025-02-15 06:40:52

为了实现这一点,我所做的就是编译view.cpp文件。在其中。也需要在标题文件中导入该库
但是,只能通过简单地制定条件来引起托管代码的访问:

    //view.h
    #ifdef _MANAGED
        #include <afxwinforms.h>
    #endif 

对于标题文件中的控件,我们还需要相同的方法:

   //view.h
   #ifdef _MANAGED
        CWinFormsControl<MainuserControlLib::UserControl2> m_ctrl1;
    #endif

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 :

    //view.h
    #ifdef _MANAGED
        #include <afxwinforms.h>
    #endif 

and for declaring the control in the header file we need also the same approach:

   //view.h
   #ifdef _MANAGED
        CWinFormsControl<MainuserControlLib::UserControl2> m_ctrl1;
    #endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文