将MFC代码转换为Windows窗体应用程序

问题描述:

大家好



我有一个MFC项目,应该转换为CLR项目,但保留旧设施。

我打开MFC项目在vs2010和解决erorrs,我的解决方案资源管理器有两个项目,第一个项目是MFC(主系统),第二个是C ++ / CLI(我在解决方案MFC中创建一个Window窗体),我想同时使用MFC和CLR。在MFC和CLR之间的通信桥是一个问题,如何解决?

这里的解决方案很简单:不要在同一个应用程序中混合使用.net表单和MFC吗?



将MFC代码转换为Windows窗体应用程序

我有一个MFC程序的大量代码,我将在Windows窗体应用程序中进行转换。什么是转换此代码的最简单方法,以便在启用/ clr的情况下编译并找到基本类,例如CObject,CString,CFile和模板?如何将类,函数和属性转换为托管代码。

我在我的本机中有对话框(或者更糟糕的是,SDI / MDI视图),如何理解,图书馆在我的cli项目中使用了什么?如何演示我在C ++ / CLI(Windows窗体)中使用库MFC。??如何在CLI项目中使用等价的MFC代码?



例如,等同于以下函数在CLI项目中使用MFC?



浮动结果;

InvokeHelper(0x1,DISPATCH_PROPERTYGET,VT_R4,(void *)&result,NULL) ;



DoDataExchange(CDataExchange * pDX)



GetDlgItem(IDC_SKIL_POP_STEP2) - > EnableWindow(FALSE) ;



CModifiedAntMinerApp * pApp =(CModifiedAntMinerApp *)AfxGetApp();



OnInitDialog()



我问了同样的问题,但还没有回复。

谢谢,machin11

Hi all

I have a MFC project ,should convert to CLR project ,but with keep old facilities .
I open MFC project in vs2010 and solve erorrs,my solution explorer have two project, the first project is a MFC(Main System) and the second is a C++/CLI(I create a Window forms in solution MFC),I want to use both MFC and CLR.The comuunication bridge bewteen MFC and CLR is a probelm,how solve??
The solution here is simple: don't mix .net forms and MFC in the same application.how do??

Converting MFC code to Windows Form App
I have a large of code for an MFC program that I would convert in a windows form appllication. What is the easiest way to "convert" this code so that it compiles with /clr enabled and finds the basic classes, e.g. CObject, CString, CFile and the templates?how convert the classes,the functions and propertys over to managed code.
I have dialogs (or worse, SDI/MDI views) in my native ,how understand that, what librarys use in my cli project ? how demonstrate i use library MFC in C++/CLI (Windows Forms).??How do I equvalent MFC code in CLI project ?

For example,what is equivalent the following functions MFC in CLI project ?

float result;
InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_R4, (void*)&result, NULL);

DoDataExchange(CDataExchange* pDX)

GetDlgItem(IDC_SKIL_POP_STEP2)->EnableWindow(FALSE);

CModifiedAntMinerApp* pApp=(CModifiedAntMinerApp*) AfxGetApp();

OnInitDialog()

I've asked this same question ,but have no reszponse yet.
Thanks,machin11

没有转换。你应该学习.NET并从头开始编写,只借用和翻译与UI无关的代码。这些概念有一些共同之处,但却截然不同。 .NET提供了更强大的UI开发功能,从本机平台中提取(仍然可以通过P / Invoke使用,除非绝对需要,否则不建议使用),而MFC在原始Windows API上相对较薄,因此它的级别要低得多,完全与具有非OOP接口的单一平台捆绑在一起。



-SA
There is no "conversion". You rather should learn .NET and write if from scratch, borrowing and translating only the code not related to UI. The concepts have something in common but very different. .NET provides much more powerful UI development capabilities abstracted from the native platforms (which can still be used via P/Invoke, not recommended unless it's absolutely needed), while MFC is relatively thin layer over raw Windows API, so it's much lower level, totally tied with a single platform with non-OOP interface.

—SA