65.9K
CodeProject is changing. Read more.
Home

Saving and restoring window appearance in WTL

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.71/5 (9 votes)

May 30, 2001

viewsIcon

100385

downloadIcon

1444

Simple, but useful classes to save/restore window appearance

Overview

Now you can use simple classes CWindowSettings, CReBarSettings, CSplitterSettings with your WTL projects to quickly save/restore window appearance (size, position). Settings are saved in registry. Additional properties saved for ReBar Control including bands sequence and position. So your window will appear next time when opened as user customized him.

How to use these classes in your WTL App

  1. Add two files RegSettings.h and RegSettings.cpp to your project.
  2. Add the header file RegSettings.h to the Frame or Window source code that will be using the classes.
  3. Load window settings from registry by adding the following code to the method that shows the window (the global Run function for a main frame):

    CWindowSettings ws;
    if(ws.Load("Software\\WTLApps\\DemoApp", "MainFrame"))
       ws.ApplyTo(wndMain, nCmdShow);
    else
       wndMain.ShowWindow(nCmdShow);
    
  4. Load rebar settings from registry by adding the following code to the OnCreate method of the frame class:

    CReBarSettings rs;
    CReBarCtrl rbc = m_hWndToolBar;
    if(rs.Load("Software\\WTLApps\\DemoApp", "ReBar"))
      rs.ApplyTo(rbc);
    
  5. Save window and rebar settings to registry by adding the following code to the OnDestroy method of the frame class:

    CWindowSettings ws;
    ws.GetFrom(*this);
    ws.Save("Software\\WTLApps\\DemoApp", "MainFrame");
    
    CReBarSettings rs;
    CReBarCtrl rbc = m_hWndToolBar;
    rs.GetFrom(rbc);
    rs.Save("Software\\WTLApps\\DemoApp", "ReBar");
    

    Also you can save/restore splitter position using CSplitterSettings class