MFC Smart Frames





1.00/5 (1 vote)
May 24, 2002
2 min read

62141

2993
Save window sizes, positions and state for all frames in an MDI MFC Application
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.
- Saving and restoring toolbar states;
- Saving and restoring SDI frames and child frames.
Programming Tasks
To implement Smart Frames in your MFC MDI Applications follow these steps:
- Insert the Smart Frames CPP and H files into your project;
- Derive your main MDI frame (typically
CMainFrame
) fromCSMDIFrameWnd
; - Derive your child MDI frames (typically
CChildFrame
) fromCSMDIChildWnd
.
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
toCSMDIFrameWnd
; - Change all references to
CMDIFrameWnd
toCSMDIFrameWnd
in your mainframe implementation; - Change the derivation of your child frame class from
CMDIChildWnd
toCSMDIChildWnd
; - Change all references to
CMDIChildWnd
toCSMDIChildWnd
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
The Smart Frames CPP and H files
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!