且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有Visual Studio中MFC的设计器,如.NET中的Windows窗体?

更新时间:2023-12-06 09:18:16

此扩展了Alex Farber的回答,该回答基本上是正确的,但有些不完整.

This expands on Alex Farber's answer, which is basically correct but somewhat incomplete.

首次创建应用程序时,您可以选择一种应用程序类型:

When you're first creating your application, you get to select an application type:

如您所见,Application type的默认选择是多个文档",但紧随其后的是基于对话框".选择该选项将产生一个应用程序,该应用程序的主窗口(默认情况下)具有一个确定"按钮和一个取消"按钮(以及一个静态控件,其内容类似于在此处添加控件").创建完应用程序后,可以添加更多控件以使其执行有用的操作.对于寿命相对较短的应用程序,这往往是***的选择-即,打开它们,填写一些字段,然后单击确定"(或取消")再次关闭它们.它也可以在其他情况下使用,但这确实是它的主要优势.

As you can see, the default selection for the Application type is "Multiple Documents", but just below that is "Dialog Based". Selecting that will produce an application whose main window (by default) has an "Ok" button and a "Cancel" button (and a static control that says something like "add controls here"). When you finish creating the application, you can add more controls to get it to do something useful. That tends to work best for applications that are relatively short-lived -- i.e., you open them, fill in a few fields, and click "Ok" (or "Cancel") to close them again. It can work for other scenarios as well, but that's really its primary strength.

对于更像是典型的.NET应用程序,具有常规菜单等功能以及将控件放置在窗口表面上的功能,通常会在此处选择单个应用程序",但是当您进入生成的类"屏幕:

For something more like a typical .NET application, with a normal menu and such, but also the ability to place controls on the window's surface, you'd typically select "Single Application" here, but when you get to the "Generated Classes" screen:

在视图类的基类的下拉列表中,您需要将默认的CView的选择更改为CFormView.这给了您一种组合:您的应用程序总体上是基于Document/View体系结构的,但是您的View类基本上就像一个对话框,因此可以承载控件.当您单击完成"按钮时,它会警告您打印支持将不可用.假设您同意这一点,那么它将创建您的应用程序.要编辑窗口的表单(与要查找的Designer相同的一般顺序),您将在左侧的工具窗口中找到资源视图",然后在对话框列表中打开该表单:

In the drop-down list for the base class of your View Class, you need to change the selection for the default CView to CFormView. This gives you kind of a combination: your application as a whole is based on the Document/View architecture, but your View class basically acts like a dialog, so it can host controls. When you click the "Finish" button, it'll warn you that Printing support won't be available. Assuming you agree to that, it'll then create your application. To edit the form for your window (on the same general order as the Designer you're looking for), you'll in the tool window on the left for the "Resource View", and open the form in the list of dialogs:

再次打开该对话框,您可以使用对话框编辑器将控件等放置在表单上:

Opening that will (again) let you use the dialog editor to put controls and such on your form:

总结:MFC为您提供了更多选择.这些选择中的一种(或两种)非常接近于您对.NET/WinForms的习惯.其他选项则大不相同-碰巧的是,默认选项属于不同"类别.

To summarize: MFC gives you quite a few more choices. One (or, sort of, two) of those choices correspond fairly closely to what you're accustomed to with .NET/WinForms. Others are quite different -- and as it happens, the default choices fall into the "different" category.