Sign in to follow this  

Learning MFC

This topic is 3727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
MFC isn't too bad, especially if you need to work with native code (e.g., Direct3D). However, after using Forms 2.0 and C#, using MFC makes me feel dirty.


Yep, I don't recall MFC as a very good library. But for sure I hate Winform: I don't know if I'm saying an heresy or not, but it is the worst UI lib I've ever used...
This aside, I've found .net to be a quite good and extensive lib (easier than java, because there are not so many classes, interfaces and so on, plus c# is a very nice language to work with, and it is becoming even better)

EDIT: IIRC you can use .net with c++ as well, if you are interested

EDIT: a new UI toolkit has just been released (or will very soon be): WPF (Windows Presentation Foundation), they say it is pretty nice.

Share this post


Link to post
Share on other sites

This topic is 3727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this