tags:

views:

1175

answers:

9

I recently started learning MFC (Prosise book), and I feel like it's difficult. But the most difficult part seems to be about creating user interfaces. It seems like you have to know the positions your controls should be positioned at (not the case with dialog based apps).

How do you get around that? Do you first draw the application in Photoshop, then measure the distances there?

And also, are there any GUI designers for it? (to ease the pain). I like it a lot, especially because of the speed and the fact it doesn't require a big framework.

Anyone who does MFC programming regularly is welcome to give me advice on how to get good at programming MFC.

A: 

A lot of the time you use the dialog resource editor and data-binding to create a UI in MFC (you can have a dialog based view). If you're not creating a dialog, then usually you have some algorithm in mind for layout of the controls, and implement that.

Pete Kirkham
+1  A: 

MFC is a pain, IMO. Unless you need to program with c++, I recommend using C# with WPF or WinForms. It's much easier. And if you need to use c++ there are better GUI solutions, like Qt.

JimDaniel
If you need c++ because there are a lot of libs and want a gui I recommend wxWidgets or QT. I would recommend to go the MFC Path.
schoetbi
+1  A: 

A typical MFC app has a top level frame window and some number of child view window and control bars. None of those things typically need to be manually positioned, although you sometimes need to specify an initial size during construction. You can use Visual Studio's dialog box editor to layout dialog boxes. It should be very rare to have to manually write positioning code.

Brian Ensink
+3  A: 

I'd have to agree that for MFC work, the resource editor which is part of Visual studio is probably the easiest way to get going with MFC. You can just lay your controls out on a dialog and stretch them to appropriate proportions. For the record, MFC is a framework it's just that it comes bundled as part of Windows.

If you want your controls to resize, you'll need to add some code to handle the resize (ON_SIZE I think it is) messages delivered as the dialog is resized. This isn't too bad as long as you don't want to resize / reposition too many things at once.

Personally, I'd recommend avoiding MFC in favour of WxWidgets. There's some great GUI layout programs like wxDesigner which can make creating resizeable dialogs and property pages fairly effortless.

Jon Cage
+1  A: 

Which version of Visual C++ are you using ? All the versions I have used come with a pretty good graphical tool for placing and editing GUI components. I usually add the basic components required write some code for them to see how they look and then move things around trying different layouts before I settle on one and add the other component parts.

Even though I have been writing MFC apps on and off for years and quite like it I have to agree with the poster who asked why you are bothering learning. These days you would probably be better using your time learning either C# or Java.

IanW
+1 from me. That was the way I used to hack together MFC apps. Now, I use wxPython it takes no time at all to get a working program running and usable!
Jon Cage
+2  A: 

MFC is simple when you keep withing bounds of what it's supposed to do (basic Doc/View, dialogs, no fancy candy UI...); as soon as you need to extend the basic behaviour, it get harder and harder to do.

Max
A: 

MFC applications can get pretty bloated (e.g. large application executable size, memory footprint, and/or require runtime DLLs to be used along with your application). If you are focused on C++, I'd recommend looking at WTL instead (used to be a Microsoft library but it's now on SourceForge). It's a very lightweight alternative (using templates) to MFC with similar syntax.

Lately I've abandoned C++ for Java for most of my applications including GUIs, and I don't plan on going back.

Jason S
MFC is bloated and Java isn't:))?
Valentin Galea
I can't stand the look and feel of java GUIs. They are horrible. I don't know anyone who prefers java ui over native UIs
Tim
+1  A: 

If you want the layout features of a dialog in an MFC application derive your CView class from CFormView. This should seem a lot like the "forms" based GUI of .NET WinForms, VB6, etc...

This can be done via the new application wizard, under the Generated Classes' Base Class dropdown section (I checked this on VS 2008).

You can also just create a dialog-based application - which you seem to already be familiar with.

There are several other CView-derived classes that provide other ways to design the "views" of your application. Using the default CView as your base class (as the wizards create by default) assumes you'll handle manually creating "controls" and/or painting the screen. Painting (actually drawing the display with the GDI) being something old-school Win32 developers are familiar but is often never done in more modern frameworks.

Aardvark
+1  A: 

I have used MFC for over 10 years. Its not bad and I would recommend it over other non Microsoft frameworks as long as you are not interested in running your application on other platforms. If you want your application to look like a dialog, then use CFormView like Aardvark suggested and lay it out with the dialog editor. In a lot of my MFC programs the views are CListViews or an explorer like application with a tree on the left and a ListView on the right. Another one we use a lot is a generic CView with a tab control and a property pages. In those, you don't have the layout issues. You simply create the controls and position them at some predefined distance from the edges. The Prosise is very good. That's what got me going on MFC. Check out CodeProject.com for some classes that extend MFC, for example, resizing dialogs and property sheets. Brian

BrianK