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

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 6:00 
GeneralRe: Small adjustment to CreateEx when using splitter bars PinmemberMagomed Abdurakhmanov16-Mar-09 23:50 
GeneralRe: Small adjustment to CreateEx when using splitter bars PinmemberJonathan Davies17-Mar-09 2:48 
I suppose it says something about how long lasting WTL is as well.
 
One more small hint to be correct - and seeing as how it took me 3 hours to find it! My original message shows how the problem of a vertical splitter that has the CMainFrame for parent moving to the right when restoring position was solved. I thought the same fix would apply to a horizontal splitter (which has the vertical splitter for a parent). It didn't. Though there is a suggestion here [^] that it should.
The same source also suggested setting the frame's m_hwndClient and calling UpdateLayout as an alternative. This did work. So my code for creating and restoring position on a horizontal splitter that has a vertical splitter for a parent is now:
 
// Create the a horizontal splitter. Note that vSplit (a vertical splitter) is parent of hzSplit
CRect rcHorz;
m_vSplit.GetSplitterPaneRect(SPLIT_PANE_RIGHT, &rcHorz);
m_hzSplit.Create(m_vSplit.m_hWnd, rcHorz, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
 
	
 
// These two lines are essential to get the horizontal splitter in the correct position.
// See: http://codecoolest.com/t/cpp/6122.aspx
m_hWndClient = m_vSplit.m_hWnd;
UpdateLayout();
 
// Restore the horizontal splitter position if it's saved in the registry
CSplitterSettings hSet;
if(hSet.Load(_T("Software\\Domain\\Aplication"), _T("HzSplit")))
	hSet.ApplyTo(m_hzSplit);
else
	m_hzSplit.SetSplitterPos(100);
 
Why is this needed? Calling UpdateLayout caused the client area to be recalculated allowing the height of a Rebar added to the main frame to be taken into account. Without this when the horizontal splitter internally makes a call to GetClientRect it returns the client area without allowing for the rebar. This then results in the splitter in the wrong position.
GeneralThis is really good Pinmemberbeaverdown10-Mar-04 10:58 
GeneralAnother suggestion Pinmemberyarp4-Jun-03 5:11 
QuestionHow about.. PinmemberTerry Denham30-May-01 12:22 
AnswerRe: How about.. PinmemberMagomed G. Abdurakhmanov30-May-01 22:32 
GeneralRe: How about.. PinmemberTerry Denham31-May-01 6:00 
GeneralRe: How about.. PinmemberJames Pullicino3-Jun-01 22:31 
GeneralSuggestions PinmemberMaximilian Hänel30-May-01 7:56 
GeneralRe: Suggestions PinmemberMagomed G. Abdurakhmanov30-May-01 22:38 
GeneralRe: Suggestions PinmemberPhilippe Mori31-May-01 4:08 
GeneralRe: Suggestions PinmemberMagomed Abdurakhmanov1-Jun-01 5:56 
GeneralRe: Suggestions PinmemberMaximilian Hänel2-Jun-01 12: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 | Mobile
Web02 | 2.8.140721.1 | Last Updated 28 Jun 2001
Article Copyright 2001 by Magomed Abdurakhmanov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid