20

What are the compelling features of MFC? Why would you select it for a new project?

14 Answers 14

19

MFC was a good option 10 years ago. It is still a good wrapper over Win32 API but unfortunately obsolete.

Qt is a better option with one big advantage - it is platform-independent. With MFC you're doomed to Windows.

0
11

I still use MFC for all kinds of applications. MFC got a bad rap from it's early implementations, but it is excellent now. I find it quite a bit more convenient than WTL as well. Plus the GUI tools in Visual Studio are already setup to make it easy to rapidly develop GUIs with MFC, mapping controls to variables, DDX, etc.

For desktop applications that I intend for wide distribution I still go with native Windows applications, usually in MFC, because we're still not at a point where you can depend on your customers to have the version of .NET that you'll be using installed and asking them to install it will cause you to lose sales, not to mention the customer service headache when they run into problems installing .NET as a result of trying to get your app to run.

8
  • 1
    Sorry, adequate, bearable is OK, excellent is absolutely unwarranted. I cannot wholeheartedly call something which leaks all possible Win32 details as an excellent abstraction. You have to know Win32 by heart AND THEN some additional MFC specific quirks (for instance related to message maps)
    – EFraim
    Aug 2, 2009 at 20:23
  • 7
    I'm pretty sure I never said "excellent abstraction". It's not meant to hide the details of the Win32 API, it's meant to provide a means to develop applications that use the Win32 API faster, and more uniformly, while still making it easy to call directly into the Win32 API when necessary or convenient. At that, it is excellent.
    – Gerald
    Aug 2, 2009 at 20:55
  • 5
    If you don't already know the Win32 API, then it's not for you, but if you do it most certainly does help you develop them faster. Or, at least, it helps me, and many like me. I use Qt for most of my cross-platform GUI development, but I still prefer MFC when developing for Windows only, for the very reason it exists; to eliminate a lot of the repetitive gruntwork of working with the Win32 API, while still giving you full control and access to the underlying API.
    – Gerald
    Aug 2, 2009 at 23:47
  • 2
    Resizable dialogs are trivial? Now I really want to know what MFC version you are using. (Because they are not) Anyway, I have no problem with Win32 API pre se, however I see MFC as adding lots of clusmy cruft around with really no added value (Actually every design I could think of myself, or every ready toolkit like WTL suited this case much better)
    – EFraim
    Aug 3, 2009 at 5:46
  • 2
    You capture the resize/ing messages, and you resize your controls accordingly, it's not hard. You don't get the fancy layout managers that give you automatic resizing, but my experience with those has been that, except in the simplest cases, they never give you exactly what you want. I can't say that I see the "clumsy cruft" you're talking about. Any concrete examples?
    – Gerald
    Aug 3, 2009 at 17:07
9

The advantage of MFC is that it's still nicer than coding to bare win32 and you can distribute a native .exe that doesn't require a 23-50Mb runtime like .Net.

Now, if you're concerned about those things there are better alternatives out there: C++ Builder, WxWidgets, etc. But some places won't consider non-Microsoft tools.

1
  • 1
    Personally, I prefer Win32 to MFC. I never found any seriously added value to MFC over Win32. Also, there's WTL which was pretty good several years ago and is probably great by now.
    – Asaf R
    Sep 23, 2008 at 14:13
9

You could sort of reword the question, why would you select C++ over C# for a desktop app. C++ still offers speed advantages which matter for some applications (I work for a company that creates software for electronic trading. Speed matters a lot).

If you are going to develop a desktop app aimed for Windows only in C++, then MFC is the most mature choice, with lots of free code based on MFC on the internet, lots of knowledge.

2
  • In such a scenario you could develop the speed sensitive logic in c++, compile to a dll and then build the ui with C#.
    – shsteimer
    Sep 23, 2008 at 14:38
  • 4
    In trading apps, the UI must also be fast, to keep up with last traded price, etc. Oct 3, 2008 at 13:12
8

Apart from win32 api itself, MFC is the only mainstream Windows programming technology that is still alive and well in 2011 after 15+ years. Back in 2001 everybody said 'MFC is dead, it's all Winforms now'; in 2005 everybody said 'MFC is dead, it's all XAML now'; now it's 2011 and Winforms and XAML are dead (OK XAML maybe not really dead, but way past its prime) and MFC is still being updated with the latest developments (ribbon, Aero extensions, Win7 API's etc).

Of course, that doesn't guarantee anything for the future, but over those 15+ years, a lot of MFC code written, and it will remain in use for the next decade or decades. It may not be the prettiest tech but it's well-understood (its good and bad points) and is not a moving target like other hype technologies are, meaning that people who actually want to get stuff done can sort of rely on it (well more than on the alternatives, anyway).

(same goes for C++, btw)

2
  • 2
    XAML is a big part of the new Windows 8 stuff (along with "native" code). No mention of MFC in the //Build/ keynote. Perhaps anyone who has installed the Win8 preview can comment on MFC.
    – crashmstr
    Sep 15, 2011 at 12:17
  • I've been working with MFC for 15 years for embedded system work. (Large $$$ systems that test MOST of the Integrated circuits in your PC, PHONE, fitbit etc. I can tell you that IC manufactures get pissed off bigtime if the software they developed 15 years ago won't work on the next gen platform.) MFC has to be here to stay. Otherwise only the LINUX based embedded systems will win. Oct 5, 2021 at 16:55
7

Here's a possibility - imagine an application that would require a large amount of memory, say a graphics program, a game or maybe some high performance business application. It's no secret that .NET applications hog memory - in such a case, you may want a lean MFC app for the core of your application. You can always load up and use .NET components, controls, etc through either COM callable wrappers or directly through C++/CLI.

That all being said - MFC is a pain. Consider WTL instead - you can still call into .NET if you need to, the same way as I mentioned above for MFC. WTL is a lot nicer than MFC :-)

1
  • I used to love WTL on my old project. :)
    – Jeff Yates
    Sep 30, 2008 at 20:45
5

Apparently it is still a good choice for applications for windows-based hand-held devices, such as point-of-sale devices. In these, resources are limited so things like memory management become more significant.

4

Quick Tour Of New MFC Functionality

I hear they have a new ribbon control. If you're into this sort of complexity. Here's a screenshot of a newly generated app:


(source: msdn.com)

Really, it's just a widget update. So do we need more widgets?

4
  • 2
    now you know what Office is written in, and what those guys want, they get. Sinofsky said the next release of VS would be focussed on C++, but we'll see about that when it arrives.
    – gbjbaanb
    Sep 23, 2008 at 14:12
  • 1
    These new mfc controls were bought from BCGSoft, We could have bought them at any time. Sep 23, 2008 at 14:22
  • 1
    Aaron Fischer is right. MS wanted MFC to end. Until they saw some guys trying to stretch its life. MS bought those guys. Jun 15, 2011 at 11:18
  • 2
    @HostileFork WordPad on Windows 7 and 8 appears to be native Win32 since they use the Scenic UI from Windows Ribbon Framework and not the ugly MFC ribbon.
    – Monstieur
    Aug 2, 2013 at 10:41
3

The existing windows API is entirely C based. If you want to use C++ (and you probably should) then MFC is the logical choice if you wish to stay native (i.e. not using .NET).

MFC is just a set of object-orientated classes over the top of the C API. Plus quite a few additional "helper" classes that make it easier to do everyday tasks.

3

I think not.. MFC would lose out in

  • Level of abstraction
  • Development Time
  • Troubleshooting time
  • Learning curve for new developers
  • Future proofing (although now that's questionable.. with something new coming up every 3-4 years)
  • Finding good people who know their MFC
  • Easy to use controls

The only place where MFC would probably sneak past is if you have some very performance intensive applications like you have things on screen that need to be redrawn every 10 msec or 1 sec. "Managed" apps still haven't managed to jump past that hurdle.

MFC was an important step in the evolution, but now better options are available.

2

On design & technical merits alone? Sorry to be categorical, but none. It's a poor design, a hugely leaky abstraction where you have to fall back to Win32 API programming, misuses C++ egregiously, and is firmly targeted on yesterday's technology: you won't get a modern (or even an attractive!) user experience out of an MFC app. If you can get C# developers and you don't have serious hardware limitations, go with WinForms.

External factors such as the availability of competence for hire, training programmes and third party components, on the other hand, can still extend its lifespan, at least for some kinds of applications: small & simple, targeted for special applications with reasonably few users, preferably in-house.

3
  • 1
    You could also consider WTL instead of MFC.
    – Rob
    Sep 23, 2008 at 14:20
  • Wasn't MSOFFICE pre 2007 was written in MFC!? That is neither a small nor simple app. Dec 8, 2008 at 23:10
  • @Byron: Actually my most negative sentiment about MFC is that it assumes you are writing MS Office application :) Really the document-view architecture has its merits, but for a minority (I think) of GUI applications.
    – EFraim
    Jul 31, 2009 at 11:22
2

If you are developing Windows CE and mobile apps in C++, as Einar has already mentioned, MFC is a good choice. If you make this choice, MFC then also becomes a reasonable choice for the desktop as you can use the same code across desktop and hand-held devices. MFC remains a good perfomance / easy to implement combinitation in this scenario. Personally, I use MFC in conjunction with Stingray libraries in these enivornments which gives a very good interface, good performance and is quick and easy to implement.

2

I would say that speed and footprint are good reasons over .NET.

It's probably true that you'll find it difficult to locate good MFC programmers, but thats just as much because the modern languages promote lazy programming techniques and most programming courses gravitate towards them as they are easier to teach.

1

I've written cross platform code for years so when I need to write something I always have a very thin abstraction layer between it and the system calls for almost everything except posix calls. That way you can code it go MFC but quite easily convert it a different API later if needed. My base set of c++ libraries that I use for everything does this with a small System class. I currently have it using MFC for Windows and I also have it using XWindows for Linux and a native Mac version as well. And later on when I port it for a handheld it should be quite painless.

If you want to take a peek, it's LGPL'ed and is at:

http://code.google.com/p/kgui/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.