<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

MFC Feature Pack for VS 2008 and 2010

Published on
34,820 Points
24,120 Views
12 Endorsements
Last Modified:
Awarded
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual Studio 2010, which is now in beta.  There are really too many new features to cover in even a long article, so I'm going to single out a few things that I think may have an important impact.

While all of the world seems to be gravitating toward a browser-centric programming model, lots of us programmers in the trenches know that there is still, and always will be, a place for desktop application programs and "thick client" application software.  MFC provides the toolkit for serious desktop application programmers.

The Ribbon
The most visible (visual) additions to MFC is support of a U/I feature that is associated with the slick Vista/Windows 7 "look" -- actually the look of Microsoft Office applications.  That look includes a "ribbon" rather than, or in addition to, an old fashioned menu bar.
A ribbon instead of a menubarNow you can create an MFC application program with the same scatter of gadgets and gizmos at the top.  The "Vista Orb" or "Pearl" (what I think of as the marble) in the top left corner really basically equates to the old "File" menu.  And the "ribbon groups" equate to menus, but in a graphical way that makes them a sort of combination menu and toolbar.

The underlying foundation does a lot of work to make all of this happen.  For instance, moving that marble and the Quick Access Toolbar buttons up onto the non-client area required quite a bit of hackwork, but it all gets done behind the scenes.  The functionality is now easily available to anyone who can click radio buttons in the AppWizard:
The AppWizard generates a marble-and-ribbon app with one clickThe way the AppWizard works for creating these template apps is that it throws in everything, including the kitchen sink.  If you don't want a feature (such as a dockable tree pane), you remove it from the program.  One result is that every AppWizard-generated program is a very detailed example of lots of new features.

Visual Studio-Style Options
Basically all of the U/I features that you see in the Visual Studios IDE are are now available for use in your own programs:  Panels that dock or float, panel groups with tabs, MDI interface that uses tabs, hide-away panes that collapse against the sides or you can "pin" open for repeated use (my favorite feature).
A Visual Studio-type application... too much?It seems like overkill to put so much into an AppWizard-generated program.  Trees and other panes are populated with fake items and tabs are given names that will have no meaning for your own program.  But I actually like what they've done.  It is very easy to replace the simulated content with your own, since you have example code that shows how to do it.  It is also very easy to remove a feature that you don't need (i.e., most of that stuff).

Did you notice how the menubar is positioned sideways in that figure?  Before taking the screenshot, I dragged the menu bar and let it snap to the left side of the client area.  There is a new class, CMFCMenubar that handles that automatically.  It basically simulates a traditional menu, but puts it all inside of a user-configurable buttonbar-type panel.  

The same support exists for traditional toolbars and for all of the other panes you see there.  As a user, you can float them and reposition them however you like.  You can even float a panel outside of the application window altogether -- which lets you take advantage of the screen real estate on your second (or third) video monitor.

If you have ever handled any of that U/I overhead yourself, you know that it can get terribly complicated.  Just keeping track of how the user set things up in order to reproduce the layout later is a big pain.  So MFC now provides new tools just to keep track of user customization actions.  It is all tied together, and that AppWizard-generated program will automatically recall tools a user adds to the toolbar(s), menus and sub-menus he's added to the menubar, locations and states of each of the panels, and the main window location -- all without the programmer needing to add a single line of program code.

Too Much?
Is all that user-customizability just too much?  What happens if your user hides the critical panel?  Are you going to get a lot of support calls?  Is that window too complicated?  Yes, Seek comfort from Cap'n Morgan, Yes, and Yes.

But I think that there is an underlying method to all of this madness.  

Webbrowser-based apps are bound to be relatively simple and offer limited functionality, supporting only the kind of customizations that can be done with a cookie.  The remaining programming niche -- desktop apps -- is for full-featured kitchen-sink programs with truckloads of bells, whistles, and --  you-guessed-it -- user-customizable panels.

What Else is New?
A lot of what's new in MFC is in support of big, complex programs.  But there are plenty of little things, too... objects that are useful in all types of programming task.  Let's look at a few of them:

Buttons, etc.Some new controls: Buttons, Font-selector, and Edit-browse tool
CMFCButton

This is a sexied-up pushbutton.  You can assign two images (one for mouse-over "hot" look) and you can easily set a tooltip and show the button with or without the button text, below or on either side of the image.  There is even an auto-repeat option.

CMFCMenuButton
This is a button that when clicked displays a pop-up menu.  It can be set as shown with a vertical bar so that clicking the arrow pops up the menu, while clicking the body of the button executes the default action (the most recent menu item selected).  That's very handy in certain situations.

CMFCFontComboBox
Select a font without going through the rigmarole of a dialog box.  One option displays the fonts as shown -- each selection is drawn in its own font face.

CMFCEditBrowseCtrl
Here's an often-needed combination:  An Edit control with a built-in "browse to locate" button.  Two common  types are provided to let your user browse to locate a particular file or a particular folder.   The "custom" version would let you browse for, say, a printer, a database, a network resource, or anything at all.

List Control VariantsNew list-control variants
CMFCListCtrl

This packages and simplifies the "report-style" version of the common ListView control.   It adds a number of handy features, including built-in sorting (and display of an arrow-decorated sort header) including multiple-column sorting.   It also lets you display specific cells in a desired font, color, and/or background shade.

CVSListBox
A user-editable list control.   It lets your users put the items in a desired order by moving them up or down in the list.  You can let the user add or delete items.  There are standard buttons for these actions and you can add new buttons (for instance, a "disable but leave in the list" button came in handy in a program I wrote recently).

Masked Edit BoxMasked-edit control
CMFCMaskedEdit

Here's one that most GUI programmers have had to write themselves at one time or another.  You want the user to input data in a certain format... say a phone number or a Social Security Number, or a product serial number, etc... and you'd like the control to enforce certain character types at certain locations, while filling in certain literal characters as well.

This new control offers great flexibility.  You set up a mask with ds and cs (and a few other characters) to identify which types of character can be input and where.  Then you can provide a template with any characters you want to be shown in the input box and underscore characters (_) for input character placeholders.  For instance, the code below sets up the masks for the two input boxes in the above figure.

m_wndMaskEdit1.EnableMask( 
    " ddd  ddd dddd",  // The mask string
    "(___) ___-____",  // Literal, "_" char = character entry
    ' '                // Default char
); 
m_wndMaskEdit1.SetValidChars(NULL); // Valid string characters

m_wndMaskEdit2.EnableMask( 
    "       cc       ddddd-dddd"), 
    "State: __, Zip: _____-____", 
    ' '
); 

Open in new window

The GetWindowText() member has been overridden to extract just the user input... so this works perfectly (and automatically) with MFC's DDX_Text() (Dynamic Data Exchange) handling.

Tear-off MenusTear-off menu support
CWinAppEx::EnableTearOffMenus

Here's a little feature that sort of illustrates how far the MFC coders went toward whiz-bang user customization.  You can create a menu that your user can "tear off" and turn into a floating palette.

Desktop Alert Popup BoxDesktop Alert box
CMFCDesktopAlertWnd

The now-standard way to inform your user about updates, task completion, or other important information is to display a small box near the status tray in the taskbar.  MFC supports this with all imaginable options -- animation effects, semi-transparency, user controls, auto-close timing... In fact, your little notification box can be entirely customized by using a dialog box template.

Shell/Windows Explorer ViewsShell/Explorer toolkitCMFCShellTreeCtrl and CMFCShellListCtrl

These are standard Tree and List controls that have been enhanced to automatically provide views of all Windows Shell objects.  If you have ever gone through the process of reproducing your own version of the Windows Explorer, you know that handling PIDLs can be a complex task.   This makes it effortless.  I found it unusual that the sample projects (and the AppWizard-generated projects) all show the tree with the old-fashioned "pluses and dotted-lines" look rather than the new-fangled Win7-look trees.  

The Sample Programs
I had trouble obtaining the sample projects that I used to generate the screenshots for this article.  It appears that they were removed from the VS 8 MFC Feature Pack download.  I eventually found them here:

    Microsoft Visual C++ 2008 SP1 Sample Library
    http://www.microsoft.com/downloads/details.aspx?familyid=9761BB57-F066-4B70-9318-3965C5E68AAD

But even then, they would refuse to install.  So I used WinRAR to break out the files from the download distribution EXE.  I understand that if you download the VS 2010 beta, you will get the full set of "Feature Pack" sample projects, so you might consider going that way.  Note, however that VS2010 solution and project files are not compatible with VS2008.

References:

MFC Feature Pack for Visual C++ 2008
http://msdn.microsoft.com/en-us/library/bb982354.aspx

Walkthroughs (MFC Feature Pack)
http://msdn.microsoft.com/en-us/library/bb982451.aspx

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If you liked this article and want to see more from this author, please click the Yes button near the:
      Was this article helpful?
label that is just below and to the right of this text.   Thanks!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
12
Comment
Author:DanRollins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 40

Expert Comment

by:evilrix
Great article Dan.

Gets my yes vote, above.
0
 

Expert Comment

by:baiello
MFC is awesome if you know how to use it. Go Native!
0
 
LVL 40

Expert Comment

by:mrjoltcola
Like it. Thanks Dan, nice coverage of new features. I use MFC w/2008 and was not aware of some of these controls.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:HappyCactus
Great Dan, this article complete all the missing documentation on the VS2008 Feature Pack. Great Work. Thank you
0
 

Expert Comment

by:tullhead
Great article Dan.  I am just about to commence a 'port' of my App from VS C++ 6.0 IDE up to VS2010 IDE and environment.  Are there any good guides, articles, or postings on EE that give some hints as to a methodology to update an old project and to take advantage of these new GUI elements?  Its great when starting a new App to use the wizard-generated sample as a guide -- but what should I be fore-warned about as far as attempting to changeover the look and feel of my old App?  Thanks.
0
 
LVL 30

Expert Comment

by:Axter
Great article Dan.  
I don't understand why MS didn't put something like this together themselves.  
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Join & Write a Comment

This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month