Click here to Skip to main content
Licence 
First Posted 12 Oct 2000
Views 74,971
Bookmarked 51 times

Persistent Frames

By | 6 Jan 2001 | Article
A collection of classes that allows MFC SDI and MDI applications to remember the positions and sizes of their main frame and child frame windows.
  • Download source files - 12 Kb
  • Download demo project - 64 Kb
  • Introduction

    A standard MFC SDI application has a main frame window and an MFC MDI application has a main frame and additional child frame windows. The classes presented here allow these frame windows to remember their last positions on the screen, their sizes and their minimized/maximized states. So, next time the application starts, its frame windows will restore their positions, sizes and minimized/maximized states.

    Features:

    • Save / Restore of the position, size and minimized/maximized state of the frame window
    • Save/Restore of the position of docked control bars
    • Information is stored in the application's registry or .INI file - CWinApp::WriteProfileString() and CWinApp::WriteProfileInt() methods are used
    • Each window can have its own set of properties saved in its own registry/.INI file section
    • If the user changes the screen resolution, the next time he/she starts the application the frames are resized to fit in new screen size.

    How to use Persistent Frames classes

    You should include the files PersistFrameImpl.cpp, PersistFrameImpl.h, PersistMDIChildFrame.cpp, PersistMDIChildFrame.h, PersistMDIFrame.cpp, PersistMDIFrame.h, PersistSDIFrame.cpp, PersistSDIFrame.h and PersistFrames.h in your project.

    I usually include this line in my StdAfx.h file.

    #include "PersistFrames.h"

    to make all classes available everywhere in the project.

    To make your frame window persistent just follow these steps:

    1. Inherit your frame window class from the appropriate Persistent Frames base class. I usually let MFC Application or Class Wizard to make the class and then using the feature Find&Replace replace all occurences of the base class in both .h and .cpp files.
    2. In the constructor of your frame window class call SetProfileHeading( LPCTSTR szHeading ) and specify the registry section that will be used to store this frame window properties. By default this is set to "Window size".
    3. In the constructor of your frame window class call SetManageBarStates( bool bManage ) and specify whether positions of control bars should be saved/restored too. By default this is set to false.

    Depending on the type of your frame window you should inherit it from different classes:

    Persistent Frames base classes
    CPersistSDIFrame A base class for SDI frame windows.
    CPersistMDIFrame A base class for MDI main frame windows.
    CPersistMDIChildFrame A base class for MDI child frame windows.

    That's it. Now compile and run your application.

    The accompanying demo .zip file contains a VC 6.0 workspace with two projects - the one is MFC SDI and the other is MFC MDI application.

    How do Persistent Frames work?

    There is a class called CPersistFrameImpl which is used in all of the other classes. Its main methods are Load() which loads the properties from the registry and Save() which saves the properties into the registry. Each of CPersistSDIFrame, CPersistMDIFrame and CPersistMDIChildFrame have an object of CPersistFrameImpl and call its Load() and <code>Save() where appropriate.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Stefan Chekanov

    Software Developer (Senior)
    D-Bross
    Bulgaria Bulgaria

    Member

    Stefan is based in Plovdiv, Bulgaria. It is a very nice and peaceful place combined with an enjoyable weather.
     
    Stefan does programming since his early ages 20 years ago. Later he began programming at his work and now he is very happy to work his hobby. He owns a Master's degree in Computer Science.
     
    During his professional career, Stefan has worked with many technologies. His programming experience includes C/C++, Java, C#, MFC, ATL, ASP, ASP.NET, TCP/IP, SQL. He has worked with different operating systems: Windows, Linux, Solaris, FreeBSD, NetBSD and QNX.
     
    Currently his professional interests are in building large scale distributed systems that operate over the Internet. This involves building server components as well as developing system level software.

    More information about his current work could be found here:
     
    Enterprise Instant Messaging
    Free Instant Messenger
    Software development for the Internet and desktop
    VoIP solutions
    Internet tunneling solutions
     
    Enterprise Instant Messaging Blog
     
    Hosted Instant Messaging
    Hosted Instant Messenger
     
    Stefan has a wife and 2 children. He likes in his spear time to travel with his family to see new and interesting places.

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Generaltoolbars Pinmemberarkon6:56 25 Jul '01  
    GeneralBar States PinmemberRalph Borchardt22:44 10 Jan '01  
    GeneralRe: Bar States PinmemberStefan Chekanov23:25 10 Jan '01  
    GeneralEasier as a lib PinmemberBryan Anslow8:40 10 Jan '01  
    General:( Not UNICODE Compatable PinmemberJim Richardson3:56 1 Dec '00  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Mobile
    Web04 | 2.5.120517.1 | Last Updated 7 Jan 2001
    Article Copyright 2000 by Stefan Chekanov
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid