Click here to Skip to main content
13,091,996 members (60,333 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 29 May 2001

Saving and restoring window appearance in WTL

, 27 Jun 2001
Rate this:
Please Sign up or sign in to vote.
Simple, but useful classes to save/restore window appearance
<!-- Add the rest of your HTML here -->


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);
  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"))
  5. Save window and rebar settings to registry by adding the following code to the OnDestroy method of the frame class:

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

    Also you can save/restore splitter position using CSplitterSettings class


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

Magomed Abdurakhmanov
Web Developer
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralSmall adjustment to CreateEx when using splitter bars Pin
Jonathan Davies16-Mar-09 6:00
memberJonathan Davies16-Mar-09 6:00 
GeneralRe: Small adjustment to CreateEx when using splitter bars Pin
Magomed Abdurakhmanov16-Mar-09 23:50
memberMagomed Abdurakhmanov16-Mar-09 23:50 
GeneralRe: Small adjustment to CreateEx when using splitter bars Pin
Jonathan Davies17-Mar-09 2:48
memberJonathan Davies17-Mar-09 2:48 
GeneralThis is really good Pin
beaverdown10-Mar-04 10:58
memberbeaverdown10-Mar-04 10:58 
GeneralAnother suggestion Pin
yarp4-Jun-03 5:11
memberyarp4-Jun-03 5:11 
QuestionHow about.. Pin
Terry Denham30-May-01 12:22
memberTerry Denham30-May-01 12:22 
AnswerRe: How about.. Pin
Magomed G. Abdurakhmanov30-May-01 22:32
memberMagomed G. Abdurakhmanov30-May-01 22:32 
GeneralRe: How about.. Pin
Terry Denham31-May-01 6:00
memberTerry Denham31-May-01 6:00 
GeneralRe: How about.. Pin
James Pullicino3-Jun-01 22:31
memberJames Pullicino3-Jun-01 22:31 
GeneralSuggestions Pin
Maximilian Hänel30-May-01 7:56
memberMaximilian Hänel30-May-01 7:56 
First of all thanks for the code!

Unfortunately there are some problems. If you leave your app in a maximized state and you restart your app, clicking the restore button not really has an effect.
Further more: If you have an Application-Bar on the top on your screen (like the office shortcut bar (don't check "Auto Hide")) and you open and close your app a few times, then the Main Window moves higher and higher. The same applies if an AppBar is on the left(the Window moves more and more to the left).

Here are some changes I have made (not tested very well)

void CWindowSettings::ApplyTo(CWindow& Wnd, bool bDontShow/* = false*/)const

changed to
void CWindowSettings::ApplyTo(CWindow& Wnd, int nCmdShow)const
	if(m_WindowState == ws_Normal)

Restoring the Window Position happens in the global Run function:

	CWindowSettings ws;
	if(ws.Load("SoftWare\\WTLApps\\DemoApp", "MainFrame"))

// some as your code
//these two lines fix the AppBar problem;
  return err == ERROR_SUCCESS;


GeneralRe: Suggestions Pin
Magomed G. Abdurakhmanov30-May-01 22:38
memberMagomed G. Abdurakhmanov30-May-01 22:38 
GeneralRe: Suggestions Pin
Philippe Mori31-May-01 4:08
memberPhilippe Mori31-May-01 4:08 
GeneralRe: Suggestions Pin
Magomed Abdurakhmanov1-Jun-01 5:56
memberMagomed Abdurakhmanov1-Jun-01 5:56 
GeneralRe: Suggestions Pin
Maximilian Hänel2-Jun-01 12:16
memberMaximilian Hänel2-Jun-01 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 28 Jun 2001
Article Copyright 2001 by Magomed Abdurakhmanov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid