I have a Windows program written in C++ using MFC. MFC handles some things very well but there are some oddities in it that are a bit painful to handle.

Using the document/view architecture is a good idea if the document can be separated from the actual view of the data but is that really possible? My program saves the view information with the document so that the document is opened with the same look that it had when it was saved. I am not sure if that makes the pan and zoom information part of the document or not. I chose to implement it as not part of the document.

And now for the issue with ProcessShellCommand(). ProcessShellCommand() is a function that is in the app class InitInstance() function. This will allow a document to be opened if it is passed to the program on the command line. Double-clicking a document file causes the shell to open the document using just such a command line. The problem is that the code in ProcessShellCommand() opens the document file before it finishes creating the frame and view windows. Those windows exist but there is no way to access them because the frame window pointer is not saved to an app-wide variable until after the document is open.

I chose to work around this problem by calling ProcessShellCommand() twice. The first call is done before ParseCommandLine() is called so that a new empty document is created. Note that this only works right if using a single document interface (SDI). I then parse the command line and call ProcessShellCommand() again if there is something to do that is not “create a new document”. This way, the document class can access the app-wide frame window pointer and then get the view and set the pan and zoom information.

    CCommandLineInfo cmdInfo;

    if( !ProcessShellCommand( cmdInfo ) )
        return FALSE;

    ParseCommandLine( cmdInfo );

    if( cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew )
    {
        if (!ProcessShellCommand( cmdInfo ) )
            return FALSE;
    }

If I was going to fix this right, I would make the pan and zoom information part of the document itself and not part of the view. It seems like an odd way to do things but there is no truly clean way to save the pan and zoom information with the document.