Is MFC deprecated? - windows

Currently I am working in a project that uses MFC a lot, but it seems to me that MFC technology is not widely used nowadays. How deprecated is MFC? What are the alternatives for it? I am using VS2010 on Windows.
Thank you for your answers.

Windows Forms and WPF are becoming more and more popular these days,
but seeing that a new version of MFC was released just a few months ago (see here) I wouldn't call it deprecated just yet.

Yes, MFC is not what you would call state-of-the-art. If you are starting a new (UI) application from scratch, you should come up with really strong reasons to use MFC (for example, you have already existing code). There are many disadvantages, for exeample the document/view archtiecture, which is only suitable for small UI applications or the high amount of customization you need to put in, if you want controls that are not included in this framework (and you certainly will at some point). Additionally, it is not that easy to test MFC classes, which you should have in mind as well.
Widely used are approaches with a MVC (model-view-controller) architecture. You can read more about these two archiectures here:
Document / View as used in MFC
Model View Controller
As you are considering MFC, I assume you already have knowledge in C++. Therefore, the Qt Framework from Trolltech / Nokia might be interesting for you. It supports MVC architecture, is cross-platform compatible and still actively developed.

MFC is not so bad. The problem is that most of the components (windows/widgets) are pretty bad or more precisely very inflexible. As Hans said it's 18 years of backward compatibility and therefore every clock cycle and memory byte counted. This hurts today.
I'm using it because Windows Forms and WPF is just not useable for cross platform GUI development where the lingua franca of the backend is C or C++ (if Java is not an option for your project for whatever reason).
Depending on what you want to do and how important a very native looking GUI is, MFC might be the only choice, especially when you can afford to buy third party components and use the feature-pack or Ribbons.
I not commenting on QT/GTK/FLTK or other toolkit as long as you don't tell us more about your project

Related

What's the main developing framework for the next Windows?

Some articles point to Windows 8 development being HTML-based instead of primarily using native code like C or C++ (as it has been until now) or .NET (as now, or even more so as it would have been in Longhorn, but never was.)
Is this true? Will the core APIs be accessible from Javascript then? What is the primary API / framework for Windows 8?
This is worth asking. When Windows 8 was demonstrated in June, a couple of comments by the presenter scared quite a few developers - or at least turned the Internet into panic mode. I'm surprised this question hasn't been asked here before.
The best article on the topic I have found is Windows 8 for Software Developers on Ars Technica.
The short answer is: it will remain the same.
The long answer is: it will remain the same, but several things will be added. You may want to pursue using those if you're willing to bet on new Microsoft technologies. One particularly interesting one is WinRT, which is a new object-oriented native code API exposed through COM, which is supposed to be a new version of the old flat Win32 API. Details are in the linked article.
It is very, very, very, very unlikely that anything that already exists, especially based on Win32 or .Net, would be removed. That means your existing programs written in .Net or native C++ or Delphi will continue to work fine. It is also unlikely that the primary development platform will be HTML. More likely is that HTML applications will be encourage for specific scenarios - perhaps touchscreen, kiosks and tablets.
I'd encourage you to read the article I linked to above - it covers this in far more detail than any answer here can.
There are three ways to develop for Windows 8, and they all access the same underlying API, the Windows Runtime.
Use C++ and call WinRT functions much like calling Win32 APIs back in the day (you know, yesterday)
Use C# or VB and call what appear to be .NET methods (but aren't)
Use Javascript and call WinRT functions
The UI is built with XAML using a pretty reasonable designer. More details are still coming out: check http://channel9.msdn.com/Events/BUILD/BUILD2011 for videos with detailed coding demos. http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1005 is not a bad starting point.
There are 3 language/framework combinations that are all equally supported:
C++ and XAML
C#/VB and XAML
JavaScript and CSS/HTML
All are first class ways to write Windows 8 Metro style applications. Windows Runtime provides direct access to each of these languages and so choice of development environment can be based on familiarity or feature set of the language and not on restricted availability.
Update: I forgot one: C++/Direct3D (for games).
The original quote, in the context of writing a tablet desktop weather gadget application, is that the application uses "our new developer platform, which is, uhh, it's based on HTML5 and JavaScript."
The demonstrator never said a gadget is the preferred type for applications (How many Vista sidebar gadget or Windows 7 desktop gadget have you written in your life? Even when you can write them in simple HTML!), or the platform is the preferred platform for desktop weather gadget applications (How many animation control have you add to your application with video playing requirement? It is THE control used by Windows Explorer to display video!).
Today, after spending a few minutes playing with Windows 8 developer preview, I found that you can use Expression Blend 5 to easily auto-generate metro-styled applications in HTML and Javascript. Also in Visual Studio you can create exactly looking applications in Silverlight. :)
I am very excited!!! Go Windows 8! :)

Windows Phone 7 and native C++/CLI

Microsoft recently released tools and documentation for its new Phone 7 platform, which to the dismay of those who have a big C++ codebase (like me) doesn't support native development anymore. Although I've found speculation about this decision being reversed, I doubt it. So I was thinking how viable would be to make this codebase available to Phone 7 by adapting it to compile under C++/CLI. Of course the user interface parts couldn't be ported, but I'm not sure about the rest. Anyone had a similar experience? I'm not talking about code that does heavy low-level stuff - but there's a quite frequent use of templates and smart pointers.
c++/cli can theoretically be used with WPF/Silverlight using the trick of replacing the C# generated from the XAML with a macro definition that can be used inside the main class in a code behind file. I worked out this technique but haven't had the motivation to take it beyond theory - I'm quite happy mixing languages.
As far as using c++/cli in a pure safe mode for your logic code, this may still not be possible but I'd love to hear how someone goes trying it now. Whilst researching it for Silverlight back in 2008 I found this daunting silverlight forum comment:
I just gave Silverlight&C++ it a try by compiling the MSIL from my C++ project into a Silverlight-compatible DLL. The good news: it works, and you can call this code from a Silverlight project. The bad news: The C++ compiler apparently uses MSIL instructions that Silverlight disallows.
So, if you try this, even with the simplest of programs, you'll almost immediately get the exception "Operation could destabilize the runtime." To me, this makes it seem less likely that we'll see Silverlight for C++ soon, as the compiler will need to behave quite a bit differently.
You can generate verifiable managed code in C++/CLI using the /clr:safe option. The problem is that most of your normal c++ code will not compile with that option.
C# is currently the only supported language for WinPhone7.
I fully expect that MS will add support for VB and C++/CLI in the future too, but don't expect to open up the native-code kimono anytime soon.
Native code just has too many issues to overcome, specifically around security, reliability, etc. Managed code is FAR easier to statically verify and FAR easier to control while running.
If you're upset about porting C++ code to C#, just be glad MS didn't force you to have to move to Objective-C ;)
From our own experience, the proces of porting well-written C++ to C# actually takes a lot less effort than one might at first expect. Sure, there's a learning curve, but you have that with any port. We actually got so much benefit from porting our core app and data engines to C# that we re-tooled our entire team to code in C# and port our C# back to C++ where necessary rather than the other way around! So far, we've only ported two modules back to C++ and call our C# code from our native code via interop instead.
Again, remember, WinPhone is a brand new platform using best of breed, highly-productive, next-generation development tools and platforms. It is not your father's WinMo.
If support for C++ is something you find to be crucially important, then make sure MS know - (respectfully and professionally) state your position in the MSDN forums and at developer events near you.
Update1: 2012-12-17:
While native C++ still isn't officially supported for Windows Phone 7, Windows Phone 8 now supports native C++ code so you can more easily port your existing C++ codebase(s) to Windows Phone 8 (as well as Windows 8 and Windows desktop apps).
While there isn't 100% compatibility between the Windows8/Phone8 platforms and API's right now, I expect the two platforms to become increasingly integrated over the next couple of releases.
This is especially true now that one of the key barriers to closer cooperation between Windows and other groups at Microsoft recently left the company ;)
Update2: 4/15/2014:
As per the recent announcements at //BUILD/ 2014, you can now start building "universal" apps in C++ & XAML, C#/VB & XAML or JavaScript & HTML that will run on Windows 8.1, Windows Phone 8.1 and Xbox One! For more details on building Windows Phone 8.1 Universal Apps, read this article.
The whole development idea is built on Silverlight. I think you can add your managed dll written in C++ without any problem to this Silverlight project, but it could not use native code.
I am planning to install the tools on my machine tonight and will try this out.
It is fine if MS decides to leave the path and create something new, that is MS' decision. So let's face the facts. Silverlight is no success yet. MS lost significant share due to Apple, Android and RIM. Application developers simply have to evaluate the business case for their own applications and decide if they trust in a share gain of Windows 7 phone or not. For the company that I run, we decided not to support any more MS Windows phone 7, not because of this or the other technical reason, but just because that we don't believe in the return of our investment for the port.
We start supporting Apple, Symbian, Andoid and MeeGo in the future if we see a market success of this new platform. All support C/C++ and enable us to reuse our proven application cores. So why worry at all. Personal technology preferences should not be gating. If personal preferences worry, then I would kick MS out for their to me ugly looking UI.
Thomas
It is on the horizon finally!
So a survey sent to windows phone developers about their future
development preferences and XNA isn't mentioned once in the Survey (A
survey sent to windows phone developers - did I mention that)
They do however ask:
How would you prefer to use C++ in your mobile apps/games?
Develop apps/games that are C++ from top to bottom (UI, business logic, and platform
APIs)
Use C++ for business logic and then write platform abstraction layer
Use C++ for business logic use 3rd party runtime engines
I don’t want to use C++

What technologies are you using to create your desktop UI

For the last few years i have been working as a web developer. So my desktop development skills are a little rusty. I am aware of Adobe AIR, winforms, WFP and silverlight 3.0. I was wandering what other UI frameworks/technologies people are using to implement desktop applications.
Depends on what you want to do. Some of the bigger toolkits for creating GUIs (among others) are QT (http://www.qtsoftware.com/products/), GTK (http://www.gtk.org/) and wxwidgets (http://wxwidgets.org/). Each of them allows you to code in a couple of different languages and use the GUIs on different platforms. There are plenty other toolkits though, which might fit your needs better (eg. more leight-weight ones).
AIR is pretty cool, I've enjoyed writing projects for it as there are a lot less limitations compared to winforms. winforms is quick and easy to use though in Visual Studio.
I think the list you've got is pretty good to start with.
Chrome. Our "desktop" UI is browser-based.
there's lots of different GUI stuff, SWING for java and .net forms are common.
besides what you listed, you'll also hear about Win32 and MFC (both c++), Tk (which is common with scripting languages like perl/python), the hardware languages OpenGl, glu, and glut (cross platform), DirectX (windows), and X Window System (X11) on linux (and Mac) and Cocoa and Carbon on Mac.
There are many others, but these are ones that I've seen used regularly.
WinForms is the default platform used to develop desktop applications using .NET framework (and Visual Studio 2002, 2003, 2005 and 2008). It's really a wrapper around the Win32 API that deals with CreateWindow and managing the messages sent to that window.
WinForms uses GDI/GDI+ technology while WPF (an exciting new platform offering a LOT of potential) utilizes GDI/GDI+ and DirectX (some parts at least, such as bitmap effects, transitions, fading).
Silverlight is a toned down Web version of WPF. Silverlight 3.0 allows developers to create a rich internet experience without the need to run the application inside a browser. Definitely something to keep an eye out for!
In terms of GUI design, I depend heavily on QT right now (py and c++ QT).
I recommend an excellent book: Rapid GUI Design with QT
I haven't tried it yet, but JavaFX sounds pretty cool.
It depends on the langage and the platform you're programming for. For C++, you can use either : Qt and its RAD tool: Qt designer, GTK+ / gtkmm or wxWidgets among others..

Windows GUI Programming - C + SDK or C# + Windows Forms

I'm a C programmer with lots of server code experience (AIX, HPUX, some Linux) I need to write a GUI program for Windows (2000, XP, Vista, 7) which requires CAD-like drawing functions and lots of data entry forms (it's a specialised engineering app). I've written some Win32 code many years ago using Gupta SQLwindows (now Centura Builder). The bosses have decreed that it "must be" compiled code. My perception is that C+SDK could do the job but with considerable effort and that C# + Windows Forms would be more capable, but I'm a bit concerned about the .Net framework requirement.
Based upon your experiences, What would you suggest?
If .Net, which version? 2.0, 3.0, 3.5 ??
I'm not familiar with Centura Builder, so I am not sure at what level of abstraction your prior Windows programming experience is. If you choose the native code route using C/C++ and Win32, be sure to buy a copy of Programming Windows by Charles Petzold. Reading the first few chapters of this book can help you decide if you want to go the native code route as well.
If you choose the .NET Framework and C#, and if you do not need the version 3.5-specific features (such as LINQ for database access), I recommend choosing version 3.0. It is a built-in component on Windows Vista, so you don't have to package the runtime with your program installer unless you have to support Windows XP (which you probably do, so never mind :). With version 3.0, you get Windows Presentation Foundation (to use instead of or along with Windows Forms), which gives you a lot of graphical capability without a lot of effort. I'm not knowledgeable about CAD, so I don't know if WPF would provide the drawing functions that you need, but it may provide a great platform upon which you can write your own drawing routines.
EDIT: I missed your Windows version requirements on first reading, particularly the Windows 2000 requirement. I guess you'd have to go with .NET Framework version 2.0 and Windows Forms. I have to ask, though: Wouldn't it be cost-effective to improve your engineers' productivity by upgrading their eight-year-old machines to something newer and faster and therefore get rid of your Windows 2000 support requirement?
If you're going the .NET route, you will have to use .NET 2.0 because .NET 3.0 and above is only supported for Windows XP and above (Vista, 7, 2003, 2008).
I personally wouldn't sweat the .NET framework requirement. It's a one time install on each machine, that can be streamlined through Windows updates if needed.
If you don't want .NET, Qt + C++ is definitely the way to go; it certainly beats C and Win32. .NET still allows much faster development than even Qt though. Qt has the advantage of being fast and easy to deploy (no .NET requirement), and makes portability much easier (if you want to port to Linux or Mac).
If you must use native code then I would strongly suggest RAD Studio from Codegear / Embarcadero, it's a studio product that ships with Delphi (the object oriented language that evolved from Turbo Pascal) and C++ Builder, if you are already familiar with C/C++ then it's going to be very simple for you to pick it up. The Visual Component Library that is shared by both languages is extendable, powerful and RAD.
If you are able to use Managed code, then C# with Winforms is easy to use, WPF may be a better UI choice long term, but it has a steeper learning curve.
Depending on the complexity requirements of the CAD-like drawing, I'd go with C# + Windows Forms, or even more preferrably, C# + WPF.
WPF would make the drawing much, much cleaner than trying to do it in GDI. This is especially true if you're going to do some 3D "drawing", as you can do a lot of (simple) 3D objects directly in WPF. C# will make your GUI programming much more productive than trying to do it in C/C++ with the windows API directly (or even MFC).
Personally, the .NET requirement is minimal in my opinion, but that's really up to the powers that be in your organization...
If it must be compiled code than I would recommend WTL of MFC but it would be much more faster (in terms of develeopment cost) to use C# + WinForms or WPF.
You can do everything with C or C++ / Win32 api
(Win32 samples for CAD-like drawing are in MSDN..)

For any new Win32 application development, are you foregoing .NET?

Are you choosing not to use managed code for any new applications for Win32? Why? Are there resources you need that aren't available from the CLR?
(Note "New" - not enhancements to existing codebases.)
One significant reason is ease of deployment. I can build a Win32 application (using MFC or WTL libraries), and with static linking there are no dependencies on external libraries (yes, I know that static linking is not the recommended approach).
Users can install and run this application without having to install anything else first: no framework library required, and no DLL hell. For comparison, read these posts from the author of Paint.Net to see how painful it can be for a user to install a .Net application.
I guess my last reason to write Win32 is portability. C++ compiles on all platforms, simply and without crazy dependencies. So for portable code, I still end up needing to access Win32 for the GUI.
I'm not bypassing .NET to do Win32 programming. I am bypassing both of them to do Java programming since I want my applications to run on as many platforms as possible. Windows may control a majority of the market but I don't see any reason to cut out even small possibilities for profit, especially since I can write Java code much faster than C++ or C# (that's based on my ability, not a reflection of the languages themselves).
Neither .NET not Win32 give me that cross-platform ability at the moment. They may eventually, with Mono, but I still consider that less-than-production-ready and there's still a question over its future in my mind.
At my workplace there are some old-timers who prefer using MFC because that's what they are familiar with. A few days ago we were to create a simple app and, naturally, they wanted to whip it out in MFC. Only that "whipping out" would have taken about a week and we needed the app in a day. I can't really blame them - old habits die hard. Eventually we went with C# and let the MFC-ers fiddle with the GUI design (which they much appreciated).
Yes and no. I use C++/CLI if I need to do any Win32/COM stuff. C++/CLI is wonderful. Our UIs are entirely .NET, but occasionally we do have need to use straight C++.

Resources