CWinAppEx - how do I get rid of LoadState/SaveState ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am held back day after day by the behavior of my MDI app with seemingly intractable issues .. one of which has to do with load/save state from the Registry. In short ... I want to turn it off so I can have more control of my toolbars (not have their
position, etc, reloaded every time I run the app). I have added the following to my derived class definition (.h):
virtual BOOL LoadState(CMDIFrameWndEx* pFrame, LPCTSTR lpszSectionName = NULL );
and the following to my implementation (.cpp):
BOOL MyApp::LoadState (CMDIFrameWndEx* pFrame, LPCTSTR lpszSectionName )<br/>
{<br/>
// do nothing to pre-load the state from the Registry<br/>
return FALSE;<br/>
}
For good measure I have added the following to the constructor of the App:
// do not save the layout of the toolbars<br/>
m_bSaveState = FALSE;

What Ive noticed is that my override LoadState() method is not being called no matter whether m_bSaveState is set to FALSE or not.
Furthermore, my toolbars seem to be reloaded and reconfigured the way they were in the previous invocation of the app even though I have my own derived Toolbar class in which Ive added (.h):
class CMyToolBar : public CMFCToolBar<br/>
{<br/>
public:<br/>
virtual BOOL LoadState(LPCTSTR lpszProfileName = NULL, int nIndex = -1, UINT uiID = (UINT) -1);<br/>
<br/>
virtual BOOL SaveState(LPCTSTR lpszProfileName = NULL, int nIndex = -1, UINT uiID = (UINT) -1);<br/>
};

and in my implementation file (.cpp):
BOOL CMyToolBar::LoadState(LPCTSTR lpszProfileName, int nIndex, UINT uiID)<br/>
{<br/>
return FALSE;<br/>
}<br/>
<br/>
BOOL CMyToolBar::SaveState(LPCTSTR lpszProfileName, int nIndex, UINT uiID)<br/>
{<br/>
return FALSE;<br/>
}

These methods above *are* called, and yet:

- the state that I set up for my toolbars during initialization (viz. visibility, docked/floating) is mysteriously overridden
- the attributes I have set up are ignored, e.g. even though I have specified fixed size and no gripper with:
int CMainFrame::createToolBar (CMFCToolBar *TB, int resourceID, int nameID)<br/>
{<br/>
// need to give each toolbar a unique name in the CreateEx()<br/>
if (!TB->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED,<br/>
CRect(1,1,1,1), nameID) ||<br/>
!TB->LoadToolBar(resourceID))<br/>
{<br/>
TRACE0("Failed to create toolbarn");<br/>
return -1; // fail to create<br/>
}

... I still end up with toolbars with grippers which are resizable.

What gives?

Thx,
<SMALL-RANT> As I convert my massive C app to MFC/C++ while I am also experimenting with JAVA and C#, I notice that both JAVA & C# are sooo much easier to use. MFC is perhaps faster and more flexible .... but remarkably more complex!
</SMALL-RANT>


View the full article
 
Back
Top