开发者

Dockable panes created in CChildFrame not visible the second time the app. starts

开发者 https://www.devze.com 2022-12-22 13:15 出处:网络
I have created some dockable panes in CChildFrame::OnCreate() The first time i start the application they are shown.

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 the开发者_如何学运维y 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?


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.


I think the SaveState() call should be put in the CMainFrame::DestroyWindow() method, so that Main Frame's child windows are not yet destroyed when the SaveState() is called.
I tried to use the SaveState() in the destructor of CMainFrame, some assertions won't pass because the child panes are already destroyed.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消