Visual C++ 2008 Feature Pack: MFC Enhancements

As Microsoft promised last year, the focus for Visual C++ features going forward is development in native code and code that spans the gap between the native and managed worlds. Keeping full-feature parity with managed-only languages like C# and Visual Basic.NET does not make a lot of sense for Visual C++ as a product, because focusing on managed-feature parity distracts from the areas where Visual C++ stands alone as a product: native and interoperability coding. Visual C++ 2008 provides strong proof for Microsoft’s renewed commitment to native code, with significant MFC updates providing full support with the Windows common control library for the first time in a decade. Not content with merely covering Windows, the Visual C++ team has released the Visual C++ 2008 Feature pack (currently in beta, and available for download here) that provides built-in support for developing applications that have Visual Studio- and Microsoft Office-like user interfaces. As this article on the MSDN web site explains, the MFC update has been completed with an external company (BCGSoft) partnering with Microsoft’s Visual C++ team.

Installing the Beta of the Visual C++ 2008 Feature Pack can be a little tricky; the installer has a bug that terminates the installation if a full installation of Visual Studio 2008 is not present OR the original media from where Visual C++/ Visual Studio has been installed is not available. The simplest workaround is simply to put the Visual Studio 2008 DVD in the disc drive or ensure that network access to the original Visual Studio installation location is available. In addition, the 303MB download of the Feature Pack does not include any documentation, and a separate 3MB download is required from MSDN to gain access to the two CHM files that describe the new features.

The Feature Pack is divided into two distinct areas of functionality: MFC updates and TR1 functionality. TR1 is a set of additions to the C++ language that are an interim step towards the new features set to be formally adopted as part of C++ in the C++0x release (0x designating that the new standard is expected to be adopted this decade). TR1 is more fully described in this MSDN blog post, and will be covered in depth in an upcoming article.

MFC Updates

Since Visual C++ 6 was released in 1998, MFC went into a gradual decline, where the features of controls released as part of the Windows operating system where not included in subsequent MFC releases as they had been in the days before .NET. With Visual C++ 2008, MFC received a major update, as covered previously. With the Feature Pack, the update of MFC continues, and the development of an application that looks good running on the Vista operating system and next to applications such as Internet Explorer 7 and Office 2007 is easy. To gain a quick appreciation of what an MFC application built using the Feature Pack looks like, running the samples gives a strong indication that this isn’t your grandfather’s MFC.

Figure 1 shows the MSOffice2007Demo sample application that ships with the Feature Pack. At a casual glance, the application would easily pass as part of Office 2007, and the fact that this is a MFC application without any third-party controls and without hundreds of lines of owner-drawn GUI hacks is stunning considering how dated MFC used to look compared to its Windows Forms and WPF cousins.

Figure 1: MSOffice2007Demo sample application.

Even though there a number of new UI elements shown in Figure 1, the Ribbon control is the most obvious update that instantly delivers the wow-factor to the application. A ribbon control offers a huge range of functionality to a user, and trying to implement a ribbon control from scratch is a massive undertaking. To gain some sense of the complexity involved in the MFC ribbon implementation, there are 25 separate CPP files that make up the ribbon control implementation, and they weigh in at a massive half a megabyte of source code.

Upgrading an existing application to move from a standard menu and toolbar UI to a ribbon-based UI is not an overly difficult undertaking. The main task is adding CMFCRibbonBar and CMFCRibbonApplicationButton member variables to the applications CMainFrame class, and then adding a CMFCToolBarImages member variable to hold the various images that will be shown on the ribbon. Each tab on a ribbon (like the Home, Insert, and Page Layout tabs in Microsoft Word 20007) are referred to as a category, and new categories are added to a ribbon by calling the CMFCRibbonBar::AddCategory method, which takes a large and small icon strip.

In addition to the new member variables needed in the CMainFrame class, most of the base classes in the MFC-generated code need to be modified to use the new style Ex clases; CWinAppEx, CMDIFrameWndEx, CMDIChildWndEx, and CSplitterWndEx all need to be substituted for their non-Ex versions. Because the new Ex classes are all derived from the non-Ex versions, the impact on an application is fairly minimal.

Thankfully, the MFC application wizard also isupdated by the installation of the Visual C++ 2008 Feature Pack, and it is possible to generate an Office-2007–like application with full ribbon support directly from the application wizard. Within the MFC app wizard, the Application Type step has been updated with the inclusion of a number of new Visual Style and Colors, as shown in Figure 2.

Figure 2: Visual Styles for a new MFC Application.

More by Author

Must Read