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 -> AllVCLanguageSamples\C++\MFC\Visual 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.

https://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!

  1. December 18, 2015 at 9:27 am

    Hello there, just changed into aware of your blog thru Google, and located that it’s truly informative. I’m gonna watch out for brussels. I’ll be grateful if you happen to proceed this in future. Numerous other people will likely be benefited out of your writing. Cheers!|

  2. KANNAN PARAMALAI
    January 11, 2011 at 1:24 pm

    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 writing\n”);
    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(“%d\n”, 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 Port\n”);
    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], “ATE0\r”);
    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=1\r”);
    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 failed\n” );
    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(“%s\n”, 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;
    }

    • January 11, 2011 at 9:15 pm

      Unfortunately I don’t have time to go through the whole code you pasted. Can you please paste only relevant part of the code?

  3. December 24, 2009 at 3:44 am

    Thanks for explaining what happened to the feature pack and providing a download link. I spent way too much time looking for this.

Comment pages
  1. January 6, 2011 at 2:46 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: