2

What are the similarities between MFC and WPF?

Is it worthy to learn MFC before WPF?

Jalayn
  • 9,789
  • 4
  • 39
  • 58
logeeks
  • 339
  • 1
  • 3
  • 6

5 Answers5

10

Both MFC and WPF (along with Windows Forms, VB6 forms, and plenty of other things) contain concepts that come from the Windows UI - the basic set of controls (button, text box, checkbox etc), the idea of properties for those controls (text, contents, checked...) and that some properties are common to all controls while others are just for certain controls. They also have the idea of separating the definition of the UI (I want the button to be blue, and to have Click Me on it) from the code that runs when you interact with the UI.

However, the actual nuts and bolts of how they work, and what you learn while you're first using them, could hardly be more different:

  • MFC is for native C++ development, WPF is for managed code, primarily C# and VB. In theory you can do WPF in C++/CLI but the absence of a designer makes that pretty much a nonstarter
  • MFC "declares" the UI in code that is generated by a designer (x = new Button(...); kind of thing) while WPF "declares" the UI in XAML ( <Button> ... </Button> kind of thing.)
  • MFC contains a TON of classes that are not about UI, from the relatively harmless CString to the don't-go-there CDatabase.

If you're a C++ developer, don't learn C# so you can learn WPF. Instead, get your feet wet in XAML development by writing C++/XAML apps for Windows 8. (It's not hard.) If you're a C# developer, ignore MFC, it's not for you.

Kate Gregory
  • 17,465
  • 2
  • 50
  • 84
  • 2
    (Added as a comment so it can be removed if anyone objects) I wrote a course on Win 8 C++ XAML development. It's at http://www.pluralsight-training.net/microsoft/Courses/TableOfContents?courseName=win8-cpp – Kate Gregory Mar 05 '12 at 13:15
  • 1
    though to be fair, MFC declares its code in a .rc file with "BUTTON, x,y,w,h" type semantics. Its not that different though WPF has more flexibility. – gbjbaanb Mar 05 '12 at 13:50
  • I am planning to learn some MFC. Could you articulate what's wrong with `CDatabase` and what you would suggest instead? – Aykhan Hagverdili Nov 11 '20 at 05:18
  • 1
    it's over 20 years old. It predates whatever database you're actually trying to work with. Use MFC for your GUI if that's right for you, but build your data and business layers another way. – Kate Gregory Nov 11 '20 at 05:36
3

MFC is an old class based wrapper around Win32, its not particularly difficult to learn and use but it is pretty much legacy today.

WPF is a .NET only GUI technology based around an XML-style declarative layout. This is kindof like HTML with javascript, only it used C# for the code-behind aspects.

So they're totally different.

You should look into a few more options before making your mind up. There's the well-respected Qt for C++ developers (and its extensions in the form of QML and Wt), or HTML. Microsoft has said that HTML5 is its (new) primary GUI technology and a lot of other companies are doing work with it, so you might see more developer resources ploughed into that compared to all the other GUI technologies put together.

gbjbaanb
  • 48,354
  • 6
  • 102
  • 172
2

MFC and WPF are completely different technologies and methodologies.

If you are getting into Windows desktop development right now then I'd recommend just learning WPF - this is the skill that will be transferable to to Metro development (both use XAML to define the UI).

MFC was used for C++ projects before .NET was developed and is effectively dead - except for legacy projects.

ChrisF
  • 38,878
  • 11
  • 125
  • 168
2

MFC was a nice framework for its time. It let you abstract the Win32 API, and made things much simpler to develop, especially when it came to GUI and MVC development. I developed in it for several years, it was much nice than using straight Win32 api.

There is nothing particularly terrible about MFC. Bad software can be written in any language. And there certainly is a learning curve to MFC, as there is to any other language. Add in a badly written application, and I can see confusion happening.

In fact as I've developed WinForms, WPF, etc, I've found the basic concepts of windows development really hasn't changed. You still have buttons, dialog windows, events, threads, mutexes, etc, etc....

George S
  • 21
  • 1
0

If you wish to learn C++ and have a future in the language then avoid MFC like the plague. Nobody uses it anymore unless they are maintaining an old legacy application. I worked at one place where I was assigned to fix a few bugs with a legacy MFC application and silly me, I thought that since I had a little C++ experience that I could just "pick it up". It was one of the few times I found myself completely in over my head and thoroughly confused.

I couldn't tell if the application was designed and written poorly or if MFC was just an awful framework. Fortunately I wasn't the only developer to have problems with it at that company, they eventually decided to rewrite the application in WPF and with good design and unit tests the application turned out rather extraordinary.

There is still work in MFC but you probably don't want these kinds of jobs. WPF is more modern, and if your strengths are in C++ then just about any other C++ UI framework is preferrable to MFC.

maple_shaft
  • 26,401
  • 11
  • 57
  • 131