views:

158

answers:

2

Hi,

I have created some dockable panes in CChildFrame::OnCreate() The first time i start the application they are shown. The second time i start the application they are created but the splitterwindows are completly against the sides of the clients area (bottom and right), so not visible. So i have to use the mouse to pull the splitters into the clientarea so that the dockable windows become visible again. If i do File->New in my app a new client window is created and showing the dockable windows as they should be. I Think this has something to do with saving the windows layout in the registry, because if i change SetRegistryKey(_T("61sakjgsajkdg")); in the CWinApp derived class of my app. and rerun they are shown again the first time. (but not the second time i restart the app). How can i save the layout of those dockable windows as well, so if i restart my app. they are visible ? Or else how do i prevent my app. of overwritting the window layout with the one previously saved. Something to do with LoadCustomState() and SaveCustomState() ?, i could no find any info on howto implement those methods. I have here a link to the demo project to demonstrate what i mean:

http://www.4shared.com/file/237193472/c384f0f6/GUI60.html

Could someone tell me how to show those dockable windows in my CChildFrame class the second time the app starts?

+1  A: 

The new classes in the MFC Feature Pack all have their window state saved in the registry.

From the sound of it, I think you probably need to call CWinAppEx::SetRegistryBase() in your InitInstance() after you call SetRegistryKey(). MSDN describes it (with little to no detail on why) here in step #4.

adam
i tried and added SetRegistryBase(_T("Settings"));after the SetRegistryKey() as descriped in the MSDN documentation. Still no change. Did you try that using my demo project link ?
Nijenhuis
Wow, i changed something now, i call SetRegistryBase() after the CChildFrame creation (sounds logical), right at the end of InitInstance() and it now does work! Great ! many thanks adam.
Nijenhuis
The only problem is now if you change the layout of the windows with the mouse and shutdown the app. and restart, they windows dont get restored to their previous position.
Nijenhuis
I think i got it solved.
Nijenhuis
A: 

I changed it a bit in InitInstance to :

. . . if (!ProcessShellCommand(cmdInfo)) return FALSE;

LoadState((CMainFrame*)AfxGetMainWnd(),_T("Settings4"));

// The main window has been initialized, so show and update it
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();

. .

AND in:

CMainFrame::~CMainFrame() { theApp.SaveState((CMainFrame*)AfxGetMainWnd(),_T("Settings4")); }

I dont know if this is the way to do it, but it is working for now. Any comments on this are more than welcome.

Nijenhuis
of course :CMainFrame::~CMainFrame() { theApp.SaveState((CMainFrame*)AfxGetMainWnd(),_T("Settings4")); }should be: CMainFrame::~CMainFrame() { theApp.SaveState(this,_T("Settings4")); }
Nijenhuis