MFC Feature Pack Tutorial – Part 1 – Getting started

Well well, off I go with my first office ribbon bar application. It’s quite easy to get started with office ribbon bar. I will just explain you how to go about this…

  1. Install TR1 feature pack, note that feature pack installation needs VS2008 to be installed, will not work with VS2005 or install VS2008 SP1.
  2. So in your VS9 installation directory there is a samples directory, unzip “AllVCLanguageSamples.zip”. After installing Vs2008 SP1 the sample directory may no longer have feature pack samples, but don’t worry I’ve uploaded this to my blog. Download samples(Save as zip).
  3. You will see pretty cool samples for VC after unzipping, some are old and some are updated
  4. Hey I think scribble has been updated with ribbon bar support I guess.
  5. Move to this directory -> AllVCLanguageSamplesC++MFCVisual C++ 2008 Feature Pack, this is where all feature pack samples are located!
  6. To see an office 2007 demo, goto directory MSOffice2007Demo
  7. Compile, run and have fun
  8. See ribbons in full flow.
  9. One sample that I would recommend is the “NewControls” sample. Almost all new controls are implemented in this sample. Check out for some surprises!

So this was the samples part! So how can I create my own man! So here is the process…

Start devenv.exe, create a new project, of type SDI/MDI!

Check out the regions encircled in orange, it’s powerful.

Click on finish and there you have your first ribbon bar application, isn’t this cool guys, now here are some snapshots of the resulting UI without writing a single line of code.

See our first shot and the drop down to the right of this shot, we got this drop down menu because we had “Enable visual style switching” checked in our main dialog, so we can switch between different type of office themes…

1. Office 2007 Black theme!

Some tid bits on switching themes

CMFCVisualManager does visual management stuff.

// To set Win2000 look and feel call
CMFCVisualManager::SetDefaultManager (RUNTIME_CLASS (CMFCVisualManager));

// To change to office XP look and feel call…
CMFCVisualManager::SetDefaultManager (RUNTIME_CLASS (CMFCVisualManagerOfficeXP));

2. Office 2007 Silver theme

You should be seeing a small toolbar at the top, it’s called the quick access toolbar, that’s kinda cool, with all commands that are to be quickly accessed like save, new etc.

3. Office 2007 Blue theme

See the drop down menu to customize quick access toolbar. I just love these new stuff. But I shouldn’t get excited these are just eye candy stuff, real stuff will be following. I did try these apps a bit and my first feeling is that it’s fast.

4. Office 2007 Aqua theme

We can also move around the quick access toolbar control, if you remember we have the statusbar switching thingie in our view menu, well now it’s right in front of us on the ribbon bar, see the checkbox, just switch it off, that’s it.

Pretty cool eye candy stuff so far, I will try to go into more detail on some of these controls.

Now lets try out visual studio templates. See my first screenshot, there is a combo called “Visual studio templates and color” selected appropriate one for yourself also select project style(see my first screenshot) as Visual Studio and rest as usual with office ribbon bars enabled…

Without a single line of code this is what I get, I’ve got to say Microsoft did a great job!

From what I’ve seen off property windows, they are strictly following OO to insert new property items, here is an article on getting started with property sheet.

http://nibuthomas.wordpress.com/mfc-feature-pack-tutorial-part-3-cmfcpropertygridctrl/

So far good enough, it’s going to be fun. Hey do give your feedback too!

23 thoughts on “MFC Feature Pack Tutorial – Part 1 – Getting started

    • U have to keep the options in Toolbar with check box for each item like properties,output.
      If you close anything then you can detect that event and uncheck the toolbar item, if you recheck that item, the window should re appear agian. This is just an idea. You can have your own way of showing. The Pane property “Show” can be used for showing the closed pane again.

  1. I do not find the feature pack samples in the zip. I even downloaded the latest zip from msdn and its not there either. Would you be kind enough to email it or point me to it? Thanks.

  2. hi,
    I downloaded the MFC feature pack and also Sp1, still cant locate the feature pack. the link above just go round n round. Could you provide me just more help?

    Thanks
    Eric

  3. Hi,
    Is there anyway we can have the ribbon style in VS 2003?
    I am suppose to make a GUI in VS 2003 and I am finding it difficult to get the ribbon style.

      • I am using VS2003 because the exe of VS 2008 was not working without a .net framework.

        I don’t think a third party ribbon controls would be a solution to it. Is there any other way I could give a 3D look to my toolbar and status bar.

  4. hello Nibu Thomas
    sorry for possting twice
    as you said ” i renamed file ” but in 80% break.
    i can not download it .
    is it possible to send me correct version ?
    thankyou

  5. This blog is veri good for learners.Iam going through throgh this blog and i suppose to add more feature soon

  6. Feature pack related things we can grab here.These are very basic things,I suppose to add more snippets soon.

  7. Dear Sir,
    Recently, I viewed your “Some Tricks with Peek Message”. I tried to use but I failed to obtain the result. Can you please help me to solve my problem? I have sent you the code(C) for your verification. I successfully accessed the GSM Modem using DoEvents in MS VB 6.0. But, In C, I am fighting and not received any positive result yet. Kindly help me in this regard.

    #include
    #include
    #include

    using namespace std;

    //STRUCTURE TO STORE TELEPHONE BOOK (THE COM OUTPUT)
    typedef struct{
    char splitRecs[25];

    } phBook;
    phBook record[50];

    char INBUFFER[500];
    char OUTBUFFER[500];
    char * chrArray;
    static string strArray;
    bool greaterSign = false;

    //SMS VARIABLES

    bool Message_Store = false;
    string Message_Buffer;
    char *SMS_MesgNum = NULL;
    char *SMS_TelephoneNum = NULL;

    // PORTS
    HANDLE h_GSM = NULL;
    DCB dcbConfig;
    COMMTIMEOUTS CommTimeouts;

    DWORD dwEventMask;
    DWORD bytes_read = 0; // Number of bytes read from port
    DWORD bytes_written = 0;

    //VARIABLES USED IN FUNCTION ComEvent

    bool OK = false;
    bool Error = false;
    bool RING = false;

    // FUNCTIONS USED IN THIS PROGRAM

    int WriteCOM();
    int ReadCOM();

    static void doEvents();
    void wait_for_response();
    char *substring(size_t start, size_t stop, char src[]);
    int split(char input[], const char *delims);
    void ComEvent(char Event[]);
    void wait_for_response();
    static void doEvents();

    // WRITE TO THE PORT

    int WriteCOM(){

    if(!WriteFile(h_GSM, // Handle
    &OUTBUFFER, // Outgoing data
    20, // Number of bytes to write
    &bytes_written, // Number of bytes written
    NULL)){
    // error processing code here
    printf(“Error in writingn”);
    return 0;
    }
    return 0;
    }

    // READ THE PORT

    int ReadCOM(){
    strcpy(&INBUFFER[0], “”);
    memset(INBUFFER, 0, sizeof(INBUFFER));

    do
    {
    if(ReadFile(h_GSM, &INBUFFER, sizeof(INBUFFER), &bytes_read, NULL) != 0){

    }

    }while(bytes_read > 0);

    //printf(“%dn”, bytes_read);
    return 0;
    }

    // FUNCTION TO EXTRACT SPECIFIED NUMBER OF SUBSTRING FROM THE OUTPUT
    char *substring(size_t start, size_t stop, char src[])
    {

    size_t size = sizeof(src);

    char* dst = (char*) malloc(strlen(src) * sizeof(char));

    int count = stop – start;

    sprintf(dst, “%.*s”, count, src + start);
    return dst;
    }

    //SPLIT COM OUTPUT AND STORE THE PHONE BOOK INTO ARRAY

    int split(char input[], const char *delims){

    char *output[500];
    int loop;
    double NumOfStr_Input = strlen(input);
    int i = 0;

    output[0] = strtok(input, delims);

    if(output[0]==NULL)
    {
    printf(“No text to search.n”);
    exit(0);
    }

    for(loop=1;loop<NumOfStr_Input;loop++)
    {

    output[loop]=strtok(NULL,delims);
    if(output[loop]==NULL)
    break;
    }

    for(loop=0;loop<NumOfStr_Input;loop++)
    {
    if(output[loop]==NULL)
    break;
    //printf("Item #%d is %s.n",loop,output[loop]);

    //split(output[loop], delim);
    strcpy(record[i].splitRecs, output[loop]);
    i++;

    }
    /*
    int j=0;

    for(;j = 5){
    break;
    }
    }
    }

    static void doEvents(){

    MSG msg;
    HWND hWnd;

    while( PeekMessage( &msg, hWnd, 0, 0, PM_REMOVE )){

    TranslateMessage( &msg );
    DispatchMessage( &msg );

    }
    }

    //******************************************************************************

    int main(int argc, char* argv[]){

    h_GSM = CreateFile(TEXT(“COM1”), // open com1:
    GENERIC_READ | GENERIC_WRITE, // for reading and writing
    0, // exclusive access
    NULL, // no security attributes
    OPEN_EXISTING, // Existing Port
    FILE_ATTRIBUTE_NORMAL, // Non-overlapped *********
    NULL);

    if (h_GSM == INVALID_HANDLE_VALUE){
    // error processing code
    printf(“Error Opening Portn”);
    return 0;
    }

    // Set timeouts in milliseconds
    CommTimeouts.ReadIntervalTimeout = 0;
    CommTimeouts.ReadTotalTimeoutMultiplier = 0;
    CommTimeouts.ReadTotalTimeoutConstant = 100;
    CommTimeouts.WriteTotalTimeoutMultiplier = 0;
    CommTimeouts.WriteTotalTimeoutConstant = 100;

    if(!SetCommTimeouts(h_GSM ,&CommTimeouts)){
    // error processing code
    printf(“Error setting timeouts”);
    return 0;
    }

    // Set Port parameters.

    if(!GetCommState(h_GSM, &dcbConfig)){
    printf(“Error getting Comm Settings”);
    return 0;
    }

    dcbConfig.BaudRate = 9600;
    dcbConfig.StopBits = ONESTOPBIT;
    dcbConfig.ByteSize = 8;
    dcbConfig.Parity = NOPARITY;

    if(!SetCommState(h_GSM, &dcbConfig)){
    printf(“Error getting Comm Settings”);
    return 0;
    }

    // DISABLE GSM MODEM ‘ECHO’ THE INPUT (TYPING)
    strcpy(&OUTBUFFER[0], “ATE0r”);
    WriteCOM();
    wait_for_response();

    ******** HERE I HAVE TO CHECK THE STATUS OF “OK”. IF IT IS ‘1’ THEN START TO EXECUTE THE NEXT LINE. BUT I COULD NOT ABLE TO RECEIVE THE CORRECT STATUS OF THE “OK’**********

    // SET THE SMS IN TEXT MODE (PDU MODE IS DEFAULT = 0)
    strcpy(&OUTBUFFER[0], “AT+CMGF=1r”);
    WriteCOM();
    //wait_for_response();

    // SETTING COM MASK TO FORCE THE PORT TO INFORM THE USER ONLY
    // IF IT RECEIVES ANY EVENTS FROM GSM MODEM

    //if(!SetCommMask(h_GSM, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING | EV_RLSD)){
    if(!SetCommMask(h_GSM, EV_RXCHAR)){
    printf(“Set Comm Mask Error!!!n”);
    return 0;
    }
    // IF WAIT COM EVENT FAILURE
    if (!WaitCommEvent(h_GSM, &dwEventMask, NULL)){
    printf(“Wait Comm Event Error!!!n”);
    return 0;
    }

    //WAIT UNTIL EVENTS OCCURED IN THE PORT
    while(WaitCommEvent(h_GSM, &dwEventMask, NULL)) {

    // IF CHARACTER RECEIVED (EV_RXCHAR)
    if (dwEventMask & EV_RXCHAR){

    // READ THE OUTPUT OF PORT
    ReadCOM();

    int lenStrArray;
    int j = 0;

    // STORE BUFFER VALUES INTO STRING
    strArray = INBUFFER;
    lenStrArray = strArray.length();

    //POINTER DECLARED AS GLOBAL VARIABLE (SEE AT THE TOP)
    chrArray = (char*) realloc(chrArray,lenStrArray * sizeof(char));
    //chrArray = (char*) malloc(lenStrArray * sizeof(char));

    if (chrArray == NULL){
    printf(“Memory allocation failedn” );
    return 0;
    }

    // READ OUTPUT DATA ONE BY ONE TO ELIMINATE CARRIAGE RETURN CHARACTERS AND
    // LINE FEED CHARACTERS AND TO EXTRACT ONLY VALID DATA
    for(int i = 0; i 0){
    printf(“%sn”, chrArray);
    ComEvent(chrArray);
    j=0;
    }

    break;

    default:

    chrArray[j] = strArray[i]; //Store the data one by one into buffer
    j++;

    break;
    }
    }

    free(chrArray); // free memory
    chrArray = ”; // nullify the pointer
    }
    }
    CloseHandle(h_GSM); // Closing the Port
    h_GSM = INVALID_HANDLE_VALUE;
    return 0;
    }

Appreciate your comments...