Is there a Designer for MFC in Visual Studio like for windows forms in .NET?
Asked Answered
D

3

32

I'm a .NET programmer. I've never developed anything in MFC. Currently I had to write a C++ application (console) for some image processing task. I finished writing it. But the point is I need to design GUI also for this. Well, there won't be anything complex. Just a window with few Buttons, RadioButtons, Check Boxes, PicturesBox & few sliders. thats it.

I'm using VS 2008 and was expecting a .NET style form designer.

Just to test, I created a MFC project (with all default configuration) and these files were created by default:

ChildFrm.cpp
MainFrm.cpp
mfc.cpp
mfcDoc.cpp
mfcView.cpp
stdafx.cpp

Now, I'm unable to find a Designer. There is no View > Designer. I've opened all the above *.cpp and in the code editor right clicked to see "Designer View". ToolBox is just empty because I'm in code editor mode.

How to open a designer?

Dorpat answered 25/4, 2010 at 6:54 Comment(2)
Looks like the image in your question above is broken (and now showing an ad instead). Could you please reupload the image to stack.imgur, or edit your question to remove it?Costumier
There is a designer... but it is less functional than WinForms designer. It is much harder to precisely align the baseline of a label with the one of a textbox for example or to adjust margins/paddings to the exact desired pixel.Menendez
H
40

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:

alt text

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.

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:

alt text

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:

alt text

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

alt text

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.

Hobbs answered 26/4, 2010 at 4:48 Comment(2)
Is this still available on VS 2019?Eryn
@Jack: Yes. They've changed the look and feel of the wizards a bit, but the same basic "stuff" is still there. Oh, one detail though: to install MFC, you now have to go into the "individual components" tab of the VS installer, and select the version of MFC you want. It's not installed by any of the "workload" choices they provide.Hobbs
T
11

Win32 dialog designer is available for dialogs. Create new project, selecting "Dialog-based application" on the Application Type Wizard step. When project is created, open Resource View, expand Dialogs node, double-click main dialog, and dialog designer is open.

For MDI/SDI applications, as you have created, you can select CFormView as base class on one of Wizard steps. This creates a dialog embedded to frame, designer is available in the Resource view.

Also, for every Win32/MFC application, you can add new dialog (not main window) from Resource View.

Tefillin answered 25/4, 2010 at 7:9 Comment(3)
I don't know which version of VS r u using but, there is not "Dialog based application" here. I'm using vs2008 pro. I'm unable to find the "Resource View" you are talking about.Dorpat
Where is this on VS 2019?Eryn
@Eryn View-Other Windows-Resource View. My key mapping calls for Ctrl-Shift-E to bring up the resource viewArrest
K
6

Look here. It's not like the forms designer, but should get you started.

Ketty answered 25/4, 2010 at 7:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.