An Overview of MFC, Part 1 - What is MFC anyway?
(Page 3 of 5 )
So let’s talk about MFC. Why do we need MFC when we can create a full fledged Windows application using the Windows API? One reason is that, when doing the latter, you have to write a lot of boilerplate code. Another reason is that, once your code exceeds a few thousand lines, it is difficult if not impossible to manage.
The focus of developing applications is to fulfill client needs in most cases -- and you have to develop them without asking a lot of questions if the client is a non-techie guy. So both of you have a very different perspective about the same problem. Say you need to write a program that allows fast searching and viewing of very large image files on a number of disks that also lets the user edit them. "Where do I begin?" is the first question that comes to your mind.
Yes, it is quite a pain to isolate the application logic from the code that you use to make the application, but with MFC you have a solution. Using Object-oriented programming concepts that wrap up the Windows API in a well defined manner makes this possible. Imagine one class that wraps up the User Interface of your application and another that encapsulates the processing logic of your application. Now you can be sure what goes where. This is much simpler than the structured way. We shall shortly see this in action!
Another advantage is that if you have the User Interface separated from logic, you can play with the user interface elements without affecting the application logic as you do in Visual Basic. But you may have this capability with the raw power of C++ using the MFC classes that encapsulate almost all of the Windows API.
The MFC library that comes straight from Microsoft is essentially a C++ class library that wraps most of the raw Windows APIs to let us write programs in a better, managed way. The biggest benefit that we get by using this library is efficiency. It greatly reduces the amount of code that must be written to create a Windows program. It also allows us to design our solutions using object oriented methodologies and some other features that come bundled with C++ like RTTI.
As we discussed earlier, the code we write using MFC is portable. By this I mean that code written under Windows 3.1 can be moved to Windows NT or Windows 95 very easily, perhaps just with a recompile, but I don’t believe that it is done nowadays. Anyway, now we can surely conclude that MFC is a preferred way for developing Windows applications.
From a developer's point of view, it lets you capture the client's requirements and design an appropriate User Interface. If you find that it does not have a user interface (as in the case of a Windows service), you can still use MFC to write code or use the Dialog Editor to create the designed user interface and other controls (like menus, buttons, toolbars, and so forth) and customize their appearance. You then begin with writing code that responds to user interactions with these controls. For example, if the user clicks a menu item, you might want to load a large image file. In this way you essentially are writing event handlers that will form the logic of any application. Once the application behaves properly to all possible user requests, you may begin with testing and deployment.
From the above discussion you’ll find that the creation of a Windows program is a very simple process when we code using MFC.
Next: Using the Windows Event Driven Model >>
More C# Articles
More By Digvijay Chauhan