About LoadBarState and SaveBarState

I wrote a MDI program like the following...
// header file mainfrm.h
class CMainFrame : public CMDIFrameWnd
{
    ...
    CToolBar m_wndToolBar1;
    CToolBar m_wndToolBar2;
    ...
};

// source file mainfrm.cpp
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ...
    LoadBarState( _T("ToolBars\\ToolBar") );
    return 0;
}

void CMainFrame::OnClose()
{
    // TODO: Add your message handler code here and/or call default
    SaveBarState( _T("ToolBars\\ToolBar") );
    CMDIFrameWnd::OnClose();
}

The other code was created automatically by wizard. But If the two toolbars
are both
floating before the MDI program exits, the program will failed to startup in
MFC
source file DockStar.cpp at line 496(VC6). The code at this line is as the
following

    CFrameWnd* pFrameWnd = pInfo->m_pBar->GetParentFrame();

The error will be found when calling ASSERT_VALID(this), is this a bug of
VC6? And In
VC7, the error is still exist. But if there is only one toolbar, the error
will not
happen.

How to fix it?
Thanks!


0
7/20/2004 5:21:27 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
617 Views

Similar Articles

[PageSpeed] 45

> The error will be found when calling ASSERT_VALID(this), is this a bug of
VC6?
Not sure, but I highly doubt it. Many mention bugs in MFC, but they are
usually
programmer error.

> VC7, the error is still exist. But if there is only one toolbar, the error
will not happen.
That should ring a bell. There is no problem with 2 or more toolbars.

What has happened to me in the past is that
The call to LoadBarState( _T("ToolBars\\ToolBar") );
should be the last thing peformed.

I can't deduce more without seeing more of the code.
The following should be similar to your source code.

 if (!m_tbDialogs.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
   | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, ID_TOOLBAR_DIALOGS) ||
  !m_tbDialogs.LoadBitmap(IDR_TB_MISC) ||
  !m_tbDialogs.SetButtons( MiscButtons, sizeof(MiscButtons)/sizeof(UINT) )
 )
 {
  TRACE0("Failed to create toolbar\n");
  return -1;      // fail to create
 }
 m_tbDialogs.EnableDocking(CBRS_ALIGN_ANY); //For each Toolbar
 m_tbDialogs.SetWindowText("Dialogs");
 EnableDocking(CBRS_ALIGN_ANY);
 DockControlBar(&m_tbDialogs); //With each ToolBar

It seems as if both Toolbars are accessing the same variables,
or 1 is not being saved.
Maybe check the .ini or Registry to see the actual values.


Good Luck,
-- 
Christopher J. Holland [!MVP]
http://www.mvps.org/vcfaq/
http://www.codeguru.com
http://www.codeproject.com
http://www.naughter.com/
http://support.microsoft.com/default.aspx
http://msdn.microsoft.com/howto/
http://msdn.microsoft.com/library/
http://www3.pgh.net/~newcomer

"Bill Gates" <bill_gates@sina.com> wrote in message
news:%23ZDtEmhbEHA.4060@TK2MSFTNGP09.phx.gbl...
> I wrote a MDI program like the following...
> // header file mainfrm.h
> class CMainFrame : public CMDIFrameWnd
> {
>     ...
>     CToolBar m_wndToolBar1;
>     CToolBar m_wndToolBar2;
>     ...
> };
>
> // source file mainfrm.cpp
> int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
> {
>     ...
>     LoadBarState( _T("ToolBars\\ToolBar") );
>     return 0;
> }
>
> void CMainFrame::OnClose()
> {
>     // TODO: Add your message handler code here and/or call default
>     SaveBarState( _T("ToolBars\\ToolBar") );
>     CMDIFrameWnd::OnClose();
> }
>
> The other code was created automatically by wizard. But If the two
toolbars
> are both
> floating before the MDI program exits, the program will failed to startup
in
> MFC
> source file DockStar.cpp at line 496(VC6). The code at this line is as the
> following
>
>     CFrameWnd* pFrameWnd = pInfo->m_pBar->GetParentFrame();
>
> The error will be found when calling ASSERT_VALID(this), is this a bug of
> VC6? And In
> VC7, the error is still exist. But if there is only one toolbar, the error
> will not
> happen.
>
> How to fix it?
> Thanks!
>
>


0
msnews (126)
7/20/2004 6:09:17 AM
Thanks and sorry:)

    I made a mistake...
    I set the IDs of the two toolbar to be same value mindlessly.

Thanks!

"Christopher J. Holland" <msnews@microsoft.com> д���ʼ�
news:OCTFYAibEHA.3524@TK2MSFTNGP12.phx.gbl...
> > The error will be found when calling ASSERT_VALID(this), is this a bug
of
> VC6?
> Not sure, but I highly doubt it. Many mention bugs in MFC, but they are
> usually
> programmer error.
>
> > VC7, the error is still exist. But if there is only one toolbar, the
error
> will not happen.
> That should ring a bell. There is no problem with 2 or more toolbars.
>
> What has happened to me in the past is that
> The call to LoadBarState( _T("ToolBars\\ToolBar") );
> should be the last thing peformed.
>
> I can't deduce more without seeing more of the code.
> The following should be similar to your source code.
>
>  if (!m_tbDialogs.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
>    | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, ID_TOOLBAR_DIALOGS)
||
>   !m_tbDialogs.LoadBitmap(IDR_TB_MISC) ||
>   !m_tbDialogs.SetButtons( MiscButtons, sizeof(MiscButtons)/sizeof(UINT) )
>  )
>  {
>   TRACE0("Failed to create toolbar\n");
>   return -1;      // fail to create
>  }
>  m_tbDialogs.EnableDocking(CBRS_ALIGN_ANY); //For each Toolbar
>  m_tbDialogs.SetWindowText("Dialogs");
>  EnableDocking(CBRS_ALIGN_ANY);
>  DockControlBar(&m_tbDialogs); //With each ToolBar
>
> It seems as if both Toolbars are accessing the same variables,
> or 1 is not being saved.
> Maybe check the .ini or Registry to see the actual values.
>
>
> Good Luck,
> -- 
> Christopher J. Holland [!MVP]
> http://www.mvps.org/vcfaq/
> http://www.codeguru.com
> http://www.codeproject.com
> http://www.naughter.com/
> http://support.microsoft.com/default.aspx
> http://msdn.microsoft.com/howto/
> http://msdn.microsoft.com/library/
> http://www3.pgh.net/~newcomer
>
> "Bill Gates" <bill_gates@sina.com> wrote in message
> news:%23ZDtEmhbEHA.4060@TK2MSFTNGP09.phx.gbl...
> > I wrote a MDI program like the following...
> > // header file mainfrm.h
> > class CMainFrame : public CMDIFrameWnd
> > {
> >     ...
> >     CToolBar m_wndToolBar1;
> >     CToolBar m_wndToolBar2;
> >     ...
> > };
> >
> > // source file mainfrm.cpp
> > int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
> > {
> >     ...
> >     LoadBarState( _T("ToolBars\\ToolBar") );
> >     return 0;
> > }
> >
> > void CMainFrame::OnClose()
> > {
> >     // TODO: Add your message handler code here and/or call default
> >     SaveBarState( _T("ToolBars\\ToolBar") );
> >     CMDIFrameWnd::OnClose();
> > }
> >
> > The other code was created automatically by wizard. But If the two
> toolbars
> > are both
> > floating before the MDI program exits, the program will failed to
startup
> in
> > MFC
> > source file DockStar.cpp at line 496(VC6). The code at this line is as
the
> > following
> >
> >     CFrameWnd* pFrameWnd = pInfo->m_pBar->GetParentFrame();
> >
> > The error will be found when calling ASSERT_VALID(this), is this a bug
of
> > VC6? And In
> > VC7, the error is still exist. But if there is only one toolbar, the
error
> > will not
> > happen.
> >
> > How to fix it?
> > Thanks!
> >
> >
>
>


0
7/20/2004 6:53:34 AM
> Thanks and sorry:)
>     I made a mistake...
>     I set the IDs of the two toolbar to be same value mindlessly.
No Problem. I've made a lot of those types of mistakes in the past.
At least you know what to look for now.

Good Luck,
-- 
Christopher J. Holland [!MVP]
http://www.mvps.org/vcfaq/
http://www.codeguru.com
http://www.codeproject.com
http://www.naughter.com/
http://support.microsoft.com/default.aspx
http://msdn.microsoft.com/howto/
http://msdn.microsoft.com/library/
http://www3.pgh.net/~newcomer

"Bill Gates" <bill_gates@sina.com> wrote in message
news:%23l67kZibEHA.2812@TK2MSFTNGP11.phx.gbl...
> Thanks and sorry:)
>
>     I made a mistake...
>     I set the IDs of the two toolbar to be same value mindlessly.
>
> Thanks!
>
> "Christopher J. Holland" <msnews@microsoft.com> д���ʼ�
> news:OCTFYAibEHA.3524@TK2MSFTNGP12.phx.gbl...
> > > The error will be found when calling ASSERT_VALID(this), is this a bug
> of
> > VC6?
> > Not sure, but I highly doubt it. Many mention bugs in MFC, but they are
> > usually
> > programmer error.
> >
> > > VC7, the error is still exist. But if there is only one toolbar, the
> error
> > will not happen.
> > That should ring a bell. There is no problem with 2 or more toolbars.
> >
> > What has happened to me in the past is that
> > The call to LoadBarState( _T("ToolBars\\ToolBar") );
> > should be the last thing peformed.
> >
> > I can't deduce more without seeing more of the code.
> > The following should be similar to your source code.
> >
> >  if (!m_tbDialogs.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
> >    | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, ID_TOOLBAR_DIALOGS)
> ||
> >   !m_tbDialogs.LoadBitmap(IDR_TB_MISC) ||
> >   !m_tbDialogs.SetButtons( MiscButtons,
sizeof(MiscButtons)/sizeof(UINT) )
> >  )
> >  {
> >   TRACE0("Failed to create toolbar\n");
> >   return -1;      // fail to create
> >  }
> >  m_tbDialogs.EnableDocking(CBRS_ALIGN_ANY); //For each Toolbar
> >  m_tbDialogs.SetWindowText("Dialogs");
> >  EnableDocking(CBRS_ALIGN_ANY);
> >  DockControlBar(&m_tbDialogs); //With each ToolBar
> >
> > It seems as if both Toolbars are accessing the same variables,
> > or 1 is not being saved.
> > Maybe check the .ini or Registry to see the actual values.
> >
> >
> > Good Luck,
> > -- 
> > Christopher J. Holland [!MVP]
> > http://www.mvps.org/vcfaq/
> > http://www.codeguru.com
> > http://www.codeproject.com
> > http://www.naughter.com/
> > http://support.microsoft.com/default.aspx
> > http://msdn.microsoft.com/howto/
> > http://msdn.microsoft.com/library/
> > http://www3.pgh.net/~newcomer
> >
> > "Bill Gates" <bill_gates@sina.com> wrote in message
> > news:%23ZDtEmhbEHA.4060@TK2MSFTNGP09.phx.gbl...
> > > I wrote a MDI program like the following...
> > > // header file mainfrm.h
> > > class CMainFrame : public CMDIFrameWnd
> > > {
> > >     ...
> > >     CToolBar m_wndToolBar1;
> > >     CToolBar m_wndToolBar2;
> > >     ...
> > > };
> > >
> > > // source file mainfrm.cpp
> > > int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
> > > {
> > >     ...
> > >     LoadBarState( _T("ToolBars\\ToolBar") );
> > >     return 0;
> > > }
> > >
> > > void CMainFrame::OnClose()
> > > {
> > >     // TODO: Add your message handler code here and/or call default
> > >     SaveBarState( _T("ToolBars\\ToolBar") );
> > >     CMDIFrameWnd::OnClose();
> > > }
> > >
> > > The other code was created automatically by wizard. But If the two
> > toolbars
> > > are both
> > > floating before the MDI program exits, the program will failed to
> startup
> > in
> > > MFC
> > > source file DockStar.cpp at line 496(VC6). The code at this line is as
> the
> > > following
> > >
> > >     CFrameWnd* pFrameWnd = pInfo->m_pBar->GetParentFrame();
> > >
> > > The error will be found when calling ASSERT_VALID(this), is this a bug
> of
> > > VC6? And In
> > > VC7, the error is still exist. But if there is only one toolbar, the
> error
> > > will not
> > > happen.
> > >
> > > How to fix it?
> > > Thanks!
> > >
> > >
> >
> >
>
>


0
msnews (126)
7/20/2004 3:43:41 PM
Reply:

Similar Artilces:

SaveBarState fails when it is called from a thread
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

LoadBarState problem
I am running an application from the command line. It runs OK but when it has finished I want it to restore to it's normal position to display the results. The function below fails in LoadBarState. Tracing into LoadBarState I find that the problem is that m_listControlBars in GetControlBar does not exist. The same code works OK when it is called during initialization from CMainFrame::OnCreate but it fails when called from CEasyNNDoc::ShowWindow, the function below. Any ideas? Steve BOOL CEasyNNDoc::ShowWindow(CString strParams) { int nIndex = 0, nLength = strParams.GetLength(); CStr...

About LoadBarState and SaveBarState
I wrote a MDI program like the following... // header file mainfrm.h class CMainFrame : public CMDIFrameWnd { ... CToolBar m_wndToolBar1; CToolBar m_wndToolBar2; ... }; // source file mainfrm.cpp int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ... LoadBarState( _T("ToolBars\\ToolBar") ); return 0; } void CMainFrame::OnClose() { // TODO: Add your message handler code here and/or call default SaveBarState( _T("ToolBars\\ToolBar") ); CMDIFrameWnd::OnClose(); } The other code was created automatically by wizard. But If the tw...

Problem with LoadBarState/SaveBarState
Hi, I've got multiple toolbars (with unique IDs) and use LoadBarState in OnCreate and SaveBarState in OnClose. It works pretty good with one exception: Wherever the toolbars are when I close the app, the next time I open the app the toolbars are always shifted in the x direction by about 4 units. Using VS .NET. Thanks for any help:). Steve Here's what it looks like: http://www.rick-n-steve.com/temp/help.html Why does MFC and LoadBarState/SaveBarState boink the coordinates? On a side note, the problem appears to be because I am not using the DOC/VIEW architecture in MFC. I'm man...

SaveBarState() fails when it is called from a thread
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

LoadBarState() & SaveBarState()
Env: WindowsXP, VC++6.00 I am trying to make a MDI application with two dynamic toolbars. I did as follows, BOOL CTest1App::InitInstance() { //using *.ini to save the information LoadStdProfileSettings(); } class CMainFrame : public CMDIFrameWnd { CToolBar m_wndToolBar; CToolBar m_wndToolBar2; } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to ...

SaveBarState fails when it is called from a thread #9
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

LoadBarState causing Assertion Failed when using two toolbars
Hello, I've got a problem with the functions LoadBarState and SaveBarState, which I can reproduce with a simple AppWizard generated project. I create a standard MFC application, add a second toolbar and calls to SaveBarState (in OnClose) and LoadBarState (in InitInstance). I start the application, drag the two toolbars to be floating and close the application again. The toolbar states/positions are now saved in the registry. When I start the application again, the states/postions are read in the LoadBarState method. However, this generates an Assertion Failed in GetParentFrame... I use M...

SaveBarState fails when it is called from a thread #8
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

SaveBarState fails when it is called from a thread #7
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

SaveBarState Fails when it is called from a thread #6
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

SaveBarState fails when it is called from a thread #5
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

SaveBarState fails when it is called from a thread #4
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

SaveBarState fails when it is called from a thread #3
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

SaveBarState fails when it is called from a thread #2
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...