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.

Visual C++ 2008 Feature Pack: MFC Enhancements

For applications generated with one of the Office 2007 visual styles, the application will contain a drop-down menu on the top of the ribbon control to change among the various Office 2007 color schemes, as shown in Figure 3.

Figure 3: Changing the color for a Office 2007-styled application

Using a ribbon rather than a standard menu is accomplished with the app wizard setting shown in Figure 4. Even if an existing application is being upgraded to support a ribbon-based UI, it is worth generating a new skeleton application just to get a template for the menu bitmaps required to support the ribbon; these are quite detailed. The ribbon control generated by the application wizard can be seen in Figure 3.

Figure 4: Using a Ribbon Bar in a New MFC Application

In addition to the ribbon control, the MFC Feature Pack supports docking of windows in the same style as Visual Studio. Setting up the docking is relatively easy—to support smart docking, a call to the docking manager is all that is required:

CDockingManager::SetDockingMode(DT_SMART);

With smart docking applied, windows being dragged around the screen will have the same visual clues as to their destination that Visual Studio shows, as shown in Figure 5.

Figure 5: Smart Docking in Action

The Visual C++ 2008 Feature Pack updates MFC to a level that it has never previously attained, making it possible to quickly and simply develop an application that is visually similar to the lastest version of Microsoft Office. For developers who have struggled for years with owner-drawn controls and poorly-supported third-party toolkits, having such powerful UI functionality being co-developed and supported by the Visual C++ team is great news, and, as evidence of the continuing renaissance of native development in Visual C++, the Feature Pack is a wonderful piece of software.

About the Author

Nick Wienholt is an independent Windows and .NET consultant based in Sydney. He is the author of Maximizing .NET Performance and co-author of A Programmers Introduction to C# 2.0 from Apress, and specialises in system-level software architecture and development, with a particular focus of performance, security, interoperability, and debugging.

Nick is a keen and active participant in the .NET community. He is the co-founder of the Sydney Deep .NET User group and writes technical articles for Australian Developer Journal, ZDNet, Pinnacle Publishing, CodeGuru, MSDN Magazine (Australia and New Zealand Edition) and the Microsoft Developer Network. An archive of Nick's SDNUG presentations, articles, and .NET blog is available at www.dotnetperformance.com.

In recognition of his work in the .NET area, he was awarded the Microsoft Most Valued Professional Award from 2002 through 2007.



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds