Article ID: 151446
Article Last Modified on 11/21/2006
void CMainFrame::OnClose()
{
// SaveBarState saves everything but the number of Columns in
// the Palette we need to do that ourselves.
SaveBarState(_T("General"));
// Following code was added to the sample with Visual C++ 4.1
#if _MFC_VER == 0x0400 || _MFC_VER == 0x0410
CDockState state;
GetDockState(state);
CleanUpControlBarState(state);
state.SaveState(_T("General"));
#endif
...
// In this case the function is defined as a global function.
// You could make it a member of one of your classes
Add the following prototype to the end of your stdafx.h:
#if _MFC_VER == 0x0400 || _MFC_VER == 0x0410
void CleanUpControlBarState(CDockState& state);
#endif
and add the following code to one of your CPP files:
#if _MFC_VER == 0x0400 || _MFC_VER == 0x0410
void CleanUpControlBarState(CDockState& state)
{
for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo1 = (CControlBarInfo*)state.m_arrBarInfo[i];
for (int j = 0; j < state.m_arrBarInfo.GetSize(); j++)
{
if (i == j)
continue;
CControlBarInfo* pInfo2 =
(CControlBarInfo*)state.m_arrBarInfo[j];
if (pInfo1->m_uMRUDockID == pInfo2->m_nBarID)
continue;
int nSize = pInfo2->m_arrBarID.GetSize();
for (int k = 0; k < nSize - 1; k++)
{
if ((LONG)pInfo2->m_arrBarID[k] ==
(LONG)pInfo1->m_nBarID + 0x10000)
pInfo2->m_arrBarID[k] = NULL;
}
}
}
for (i = 0; i < state.m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
int nSize = pInfo->m_arrBarID.GetSize();
for (int j = 0; j < nSize - 1; j++)
{
if (pInfo->m_arrBarID[j]==NULL)
continue;
for (int k = j + 1; k < nSize; k++)
{
if (pInfo->m_arrBarID[k]==NULL)
continue;
if (pInfo->m_arrBarID[k]==pInfo->m_arrBarID[j])
pInfo->m_arrBarID[k] = NULL;
}
}
while ((nSize!=0) && (pInfo->m_arrBarID[nSize-1]==NULL))
{
nSize--;
pInfo->m_arrBarID.RemoveAt(nSize);
}
if (nSize)
pInfo->m_arrBarID.InsertAt(nSize, (void*)NULL);
}
}
#endif
NOTE: The sample code above uses undocumented functionality of the MFC. To
be compatible with future versions of MFC, enclose the code between the
following directives:
#if _MFC_VER == 0x0400 || _MFC_VER == 0x0410 ... ... #endifAlso include any call to CleanUpControlBarState between these directives.
Additional query words: kbVC400bug 4.00 4.10 4.20 LoadBarState SaveBarState ini grow vcfixlist420 kbui MfcUI
Keywords: kbbug kbfix kbnoupdate kbtoolbar kbuidesign kbvc420fix KB151446