Windows 7 Ribbon – Part 1 – How to Integrate a Simple Ribbon to your MFC Application?

 

The Office 2007 changed the the conventional menu to a new vibrant, beautiful, and useful(??) ribbons. After that many third party libraries (both commercial and non commercial) vendors provided components to integrate ribbons to our application. Finally Microsoft heed the MFC guys crying a loud to get support on ribbons. Microsoft included Ribbons and other office style controls with MFC Feature Pack for Visual Studio 2008.

The following figure depicts the anatomy of a typical Ribbon.

image

In the new version of Windows, Windows 7 , it supports ribbons natively and Microsoft allows us to create it using Ribbon Frame Work.  Few Accessories application like MS Paint, Wordpad etc. got UI lift with Windows Ribbons.

Developer can create ribbon using Ribbon Markup Language (similar to XML format). For the Windows Ribbon framework (Ribbon) to consume the Ribbon markup file, the markup file must be compiled into a binary format resource file. A dedicated Ribbon markup compiler, the UI Command Compiler (UICC), is included with the Microsoft Windows Software Development Kit (SDK) (7.0 or later) for this purpose. In addition to compiling the binary version of the Ribbon markup, the UICC generates an ID definition header file that exposes all markup elements to the Ribbon host application and a resource file that is used to link the binary markup to the host application at build time.

The workflow for the Ribbon is as follows

Ribbon-Flow

OK let’s create a simple ribbon step by step. You should have Windows 7 SDK installed and Visual Studio 2005 or above is required to compile this application. I’m taking a MFC Application do this instead of a Win32 application. I’m just creating a new MFC Dialog Based Application.

We can categorize the ribbon creation in to two categories.

  • XML Markup, used to define the Ribbon structure and organization of controls
  • C++ COM interfaces, used to initialize and handle events

Step 1: Create the XML file with your ribbon. Add this XML for the solution. The following XML is a simple ribbon contains the application a Tab,Group and a button inside it.

1

[sourcecode language='xml']









My Button
My Button











Thought for the Day: Set Yourself Free!

 

Set yourself free from anything that might hinder you in becoming the person you want to be. Free yourself from the uncertainties about your abilities or the worth of your dreams, from the fears that you may not be able to achieve them or that they won’t be what you wanted.

Set yourself free from the past. The good things from yesterday are still yours in memory; the things you want to forget you will, for tomorrow is only a sunrise away. Free yourself from regret or guilt, and promise to live this day as fully as you can.

Set yourself free from the expectations of others, and never feel guilty or embarrassed if you do not live up to their standards. You are most important to yourself; live by what you feel is best and right for you. Others will come to respect your integrity and honesty.

Set yourself free to simply be yourself, and you will soar higher than you’ve ever dreamed.

- Edmund O’Neill

 

How to create a list from vector?

 

The following sample demonstrates, how to convert a vector to list(in other words, how to create a list from vector).

The simplest way is to iterate through all elements of container and add it to the destination container. the following snippet make use of std::copy function to copy contents from source to destination container. The destination and source iterator will be automatically incremented inside on each iteration. Before using this function you will have to ensure the destination container has enough room to hold the source elements. For that it may necessary to resize the container. See the snippet below. Note that you can use this technique with anu containers which supports iterator(actually that’s the purpose of std::copy function).

[sourcecode language='cpp']
#include
#include

#include
#include

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector vec;
// prepare the vector
for (int i = 0; i < 10; i++ )
{
vec.push_back( i+1 );
}

// construct list with the size of vector
list lis(vec.size());

// iterate and copy the content to list
copy( vec.begin(), vec.end(), lis.begin());

// output the content to console
copy( lis.begin(), lis.end(), ostream_iterator(cout, “\t” ) );

return 0;
}
[/sourcecode]