MFC problems

There are a few subjects I would like to write about MFC and would like to compare Cocoa and MFC. I know that it is not fair to compare Cocoa and MFC, because MFC was designed at the time of ToolBox of System x. However, Cocoa was also designed at almost similar time at NeXT.
However, ToolBox and MFC was based on programming model of the past, while the NeXT API was designed with newer ideas at that time. Currently Cocoa is more comparable to .NET framework. As I compared ( unexpectedly ) at my previous blog “What Apple Inc. didn’t tell you”, there are similarities between Cocoa and .NET.
I also suggest .NET framework to Windows programmers who want to taste Cocoa to figure out how it will be like.

Anyway, in this post, I would like to talk about a problem with MFC among many problems.

Let’s take a look at LVCOLUMN structure, which is used for representing columns for CListCtrl.

typedef struct _LVCOLUMN { 
    UINT mask; 
    int fmt; 
    int cx; 
    LPTSTR pszText; 
    int cchTextMax; 
    int iSubItem; 
#if (_WIN32_IE >= 0x0300)
    int iImage;
    int iOrder;
#if (_WIN32_WINNT >= 0x0600)
    int cxMin;
    int cxDefault;
    int cxIdeal;

As you can see, the first member variable is “mask”. Then let’s take a look at the second one, fmt.

Alignment of the column header and the subitem text in the column. The alignment of the leftmost column is always left-justified; it cannot be changed. This member can be one of the following values:

Text is left-aligned.
Text is right-aligned.
Text is centered.
A bitmask used to select those bits of fmt that control field justification. To check the format of a column, use a logical “and” to combine LCFMT_JUSTIFYMASK with fmt. You can then use a switch statement to determine whether the LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER bits are set.

What is LVCFMT_JUSTIFYFYMASK? It is ANDed with LVCFMT_LEFT/RIGHT/CENTER to set those alignment setting.
Hmmm… Why is there another mask bit set here? Isn’t the 1st member variable is for masks?
Like this, here and there in MFC, there are some confusing part or illogically designed parts.

Also, although this is another aspect of MFC, it doesn’t provide easy way to work with controls. For example, instead of calling CListCtrl’s method to add, delete items and columns, it utilizes messages. You need to send messages to controls to manipulate them. Some controls don’t work like this. What I want to say is that the architecture of MFC is somewhat awkward and not designed for ease of use, which is very different from Cocoa and .NET.

When I was a university student, I found out that may other CSE student had difficulty in using MFC framework. I think it is not coincidence.
Probably MS architects at MS knew about this problem and they decided to make a new framework by hiring Borland people to adopt their Form-based and property programming paradigm.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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: