Introduction to Smart Frames for MFC
Smart Frames are a set of MFC Classes which implement the following functionality:
- Saving and restoring window state of
CMDIFrameWnd
derived classes; - Saving and restoring window state of
CMDIChildWnd
derived classes.
The Smart Frame classes do
NOT offer the following functionality:
- Saving and restoring toolbar states;
- Saving and restoring SDI frames and child frames.
If these functions are ever implemented this article will be updated with the changes.
Programming Tasks
To implement Smart Frames in your MFC MDI Applications follow these steps:
Notes on deriving from CSMDIFrameWnd and CSMDIChildWnd
The easiest way to derive from these classes is to create your mainframe and childframes using the
MFC Class Wizard or MFC App Wizard as you normally would and then following these steps. Please note
that these are only suggestions:
- Include SMDIFrameWnd.h and SMDIChildWnd.h in stdafx.h;
- Change the derivation of your mainframe class from
CMDIFrameWnd
to CSMDIFrameWnd
; - Change all references to
CMDIFrameWnd
to CSMDIFrameWnd
in your mainframe implementation; - Change the derivation of your child frame class from
CMDIChildWnd
to
CSMDIChildWnd
; - Change all references to
CMDIChildWnd
to CSMDIChildWnd
in your child frame
implementation(s);
How do Smart Frames work?
To persist and restore frame states I use techniques described in another article which I
submitted to Code Project some time ago. Here is the link: Saving a windows size position and state
in MFC
Smart Frames consist of the following CPP and H files:
- SMDIFrameWnd.h and SMDIFrameWnd.cpp (CSMDIFrameWnd)
- SMDIChildWnd.h and SMDIChildWnd.cpp (CSMDIChildWnd)
The Smart Frames Classes
Smart Frames are implemented in the following classes:
CSMDIFrameWnd
CSMDIChildWnd
The Smart Frames Demo Project
Included with this article is a Demo Project which is a bare-bones implementation of Smart Frames.
It was created and tested with Visual Studio Version 6.
Happy Coding!