Learning MFC

Started by
10 comments, last by cignox1 16 years, 6 months ago
Hi, I've just started learning MFC and I have some un-answered question I thought I might find answers for them here: 1)Is it wise ? should I go on learning MFC ? or should I switch to C# .NET instead when it's about windows forms ? Is MFC becoming outdated ? 2)should I instead try to learn other portable libraries like wxWidgets ? I know that learning one of them will make it easier to write for the other when needed (well, something like OpenGL and DirectX APIs).I mean do you have a recommendation ? 3)As for the " string's hell" of MFC(various kinds of string representations for different types), is using things like : (L"To be converted to LPCTSTR") is a LEGAL C++ programming practise ? or it's a Microsoft modification to the standards ? Is there any better way to make the life easier than using such things (L, _T,..) ? Do you have any good link/site about this topic, as I can't even remember all these things ? Thanx in Advance
D:...You are a Muslim, and you don't understand our freedom...M:And you are a Western who doesn't know Muhammad ...
Advertisement
It would probably be better just to move on to C#, or even to pick a different library for C++. Not only is MFC dated, it's also a very poorly designed API.
Quote:
1)Is it wise ? should I go on learning MFC ? or should I switch to C# .NET instead when it's about windows forms ? Is MFC becoming outdated ?
Unless you can think of a good reason, switching to .NET is best. Non-game programming is moving out of C++ and C# is getting very popular. WPF is the new thing.
Quote:
2)should I instead try to learn other portable libraries like wxWidgets ? I know that learning one of them will make it easier to write for the other when needed (well, something like OpenGL and DirectX APIs).I mean do you have a recommendation ?
Is it for a game? Then maybe. If it's not for a game, then no.
Quote:
3)As for the " string's hell" of MFC(various kinds of string representations for different types), is using things like : (L"To be converted to LPCTSTR") is a LEGAL C++ programming practise ? or it's a Microsoft modification to the standards ? Is there any better way to make the life easier than using such things (L, _T,..) ? Do you have any good link/site about this topic, as I can't even remember all these things ?

Thanx in Advance
Strings in MFC are just plain bad. You have COM/VB BSTR strings, CString (which is actually pretty good) and lots of char*. But then you also have the unicode WSTR types and converting is horrible. This is a big enough reason on its own to leave C++ for Windows coding.

Quote:Original post by yehdev_cc
1)Is it wise ? should I go on learning MFC ? or should I switch to C# .NET instead when it's about windows forms ? Is MFC becoming outdated ?


Every time I use MFC, it feels like re-learning it even though I read all of the massive book by Jeff Prosise on MFC. I think MFC only feels "natural" to people who spend all their time programming in MFC. If you have no legacy MFC code, I'd recommend using Windows Forms and .NET instead.

Quote:2)should I instead try to learn other portable libraries like wxWidgets ? I know that learning one of them will make it easier to write for the other when needed (well, something like OpenGL and DirectX APIs).I mean do you have a recommendation ?


Learn wxWidgets if you have to write GUI applications that need to be portable across platforms (Mac, Win, unix). If you don't need to write GUI apps that need to be portable across platforms, then don't bother.

Quote:
3)As for the " string's hell" of MFC(various kinds of string representations for different types), is using things like : (L"To be converted to LPCTSTR") is a LEGAL C++ programming practise ? or it's a Microsoft modification to the standards ? Is there any better way to make the life easier than using such things (L, _T,..) ? Do you have any good link/site about this topic, as I can't even remember all these things ?


The L"" business is standard C++, not some MS invention. Windows evolved in a world where sometimes you compiled an ANSI build (Win9x) and sometimes you built a UNICODE build (WinNT/2K/XP/Vista). Everything in the Win32 API is built around this dual string mechanism. Personally, I don't use CString unless I'm in MFC land and even then it feels grungy. I use std::string or std::wstring, or for Windows I use std::basic_string<TCHAR> to get ANSI/UNICODE agnostic code. In .NET everything is a Unicode string, with .NET marhsalling to/from ANSI if necessary.

wxWidgets deals with ANSI/UNICODE stuff in the same way as Windows, with a macro that supplies the L"" business if necessary.

My free book on Direct3D: "The Direct3D Graphics Pipeline"
My blog on programming, vintage computing, music, politics, etc.: Legalize Adulthood!

Thank you guys for the replys, I'm really grateful.

I was looking in MFC for the the last few days, and I think I'll be so for one or two days to come in order to get a fundamental good understanding of it, as portable APIs are somehow similar,however I think I'm going to switch to .NET for windows programming.

one more question, how is L"" is a C++ standard ? It's not a macro or a compiler directive I think...is it built into the language for converting from ANSI to UNICODE ?
D:...You are a Muslim, and you don't understand our freedom...M:And you are a Western who doesn't know Muhammad ...
Quote:Original post by yehdev_cc
Hi, I've just started learning MFC and I have some un-answered question I thought I might find answers for them here:

1)Is it wise ? should I go on learning MFC ? or should I switch to C# .NET instead when it's about windows forms ? Is MFC becoming outdated ?

2)should I instead try to learn other portable libraries like wxWidgets ? I know that learning one of them will make it easier to write for the other when needed (well, something like OpenGL and DirectX APIs).I mean do you have a recommendation ?

3)As for the " string's hell" of MFC(various kinds of string representations for different types), is using things like : (L"To be converted to LPCTSTR") is a LEGAL C++ programming practise ? or it's a Microsoft modification to the standards ? Is there any better way to make the life easier than using such things (L, _T,..) ? Do you have any good link/site about this topic, as I can't even remember all these things ?

Thanx in Advance

1) If you have no compelling reason i.e. work tells you to use it probably not. It's like learning C before C++ it's not really necessary.
MFC is supported well into the future and if you look at the latest DX SDK they still use it in some of the sample programs. If you are thinking like that then windows forms is also outdated and being replaced with WPF as was stated.

2) If you plan on making your programs cross-platform yeah.

3)A variable of __wchar_t designates a wide-character or multibyte character type. By default wchar_t is a typedef for unsigned short. Use the L prefix before a character or string constant to designate the wide-character-type constant. When compiling with /Zc:wchar_t or /Za, the compiler can distinguish between an unsigned short and wchar_t for function overload purposes.

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Quote:Original post by daviangel
MFC is supported well into the future and if you look at the latest DX SDK they still use it in some of the sample programs.


LOL! The last place you should be looking for general programming practices to emulate is the DX SDK sample programs. They're a mess.

My free book on Direct3D: "The Direct3D Graphics Pipeline"
My blog on programming, vintage computing, music, politics, etc.: Legalize Adulthood!

For what it's worth, Herb Sutter recently mentioned in his blog that MFC is about to get a "huge update".

If there are still enough people using MFC that MS is willing to invest time in it (after focusing on .NET so much for the past few years), I'd say it's still going to be around for a good while.
If you're stuck on using C++ you should probably look in to WTL (Windows Template Library), however I tend to agree with the others above: unless you have a good reason you should probably move on to C# and WPF.
I have been using MFC lately, and I must say that is isn't quite as horrid as everyone tends to make it out to be. I have not used C# or WinForms yet, but MFC more than suffices for my needs. It you have access to both , however , I'd recommend something more modern just because it would be supported better.

This topic is closed to new replies.

Advertisement