Click here to Skip to main content
Click here to Skip to main content

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 -->

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

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

Share

About the Author

Magomed Abdurakhmanov
Web Developer
Russian Federation Russian Federation
No Biography provided

Comments and Discussions

 
GeneralSmall adjustment to CreateEx when using splitter bars PinmemberJonathan Davies16-Mar-09 7:00 
GeneralRe: Small adjustment to CreateEx when using splitter bars PinmemberMagomed Abdurakhmanov17-Mar-09 0:50 
GeneralRe: Small adjustment to CreateEx when using splitter bars PinmemberJonathan Davies17-Mar-09 3:48 
GeneralThis is really good Pinmemberbeaverdown10-Mar-04 11:58 
GeneralAnother suggestion Pinmemberyarp4-Jun-03 6:11 
QuestionHow about.. PinmemberTerry Denham30-May-01 13:22 
AnswerRe: How about.. PinmemberMagomed G. Abdurakhmanov30-May-01 23:32 
GeneralRe: How about.. PinmemberTerry Denham31-May-01 7:00 
GeneralRe: How about.. PinmemberJames Pullicino3-Jun-01 23:31 
GeneralSuggestions PinmemberMaximilian Hänel30-May-01 8: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)
 
First:
void CWindowSettings::ApplyTo(CWindow& Wnd, bool bDontShow/* = false*/)const
changed to
void CWindowSettings::ApplyTo(CWindow& Wnd, int nCmdShow)const
{
	if(SW_SHOWNORMAL!=nCmdShow)
	{
		Wnd.ShowWindow(nCmdShow);
		return;
	}
 
	if(m_WindowState == ws_Normal)
	{
		Wnd.MoveWindow(m_rcNormal,FALSE);
		Wnd.ShowWindow(SW_SHOW);
	}
	else
		Wnd.ShowWindow(SW_MAXIMIZE);
}
 
Restoring the Window Position happens in the global Run function:
 
	//wndMain.ShowWindow(nCmdShow);
	CWindowSettings ws;
	if(ws.Load("SoftWare\\WTLApps\\DemoApp", "MainFrame"))
		ws.ApplyTo(wndMain,nCmdShow);
	else
		wndMain.ShowWindow(nCmdShow);
 
 
Second:
CWindowSettings::Load(...)
{
// some as your code

//these two lines fix the AppBar problem
  m_rcNormal.top+=rc.top;
  m_rcNormal.left+=rc.left;
 
  return err == ERROR_SUCCESS;
}
 
CU
 
Max

GeneralRe: Suggestions PinmemberMagomed G. Abdurakhmanov30-May-01 23:38 
GeneralRe: Suggestions PinmemberPhilippe Mori31-May-01 5:08 
GeneralRe: Suggestions PinmemberMagomed Abdurakhmanov1-Jun-01 6:56 
GeneralRe: Suggestions PinmemberMaximilian Hänel2-Jun-01 13:16 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 28 Jun 2001
Article Copyright 2001 by Magomed Abdurakhmanov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid