jli
asked on
Load and Save CDialogBar
Hello,
I tried to load and to save CDialogBar based on the Knowledge Base's article "How To Save and Restore State of Dockable Toolbars." However, I can't seem to get this to work. I embedded my CNewSldClass dialog bar which is derived from CMyOwnDialogBar inside my CMDIChildWnd code. CMyOwnDialogBar is derived from CDialogBar. I get an assert failed in DOCKSTAT.CPP line 477. Following is an excerpt of my code in the CMDIChildWnd:
int CChildFrame::OnCreate(LPCR EATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lp CreateStru ct) == -1)
return -1;
// TODO: Add your specialized creation code here
//allow docking to left, right and bottom
DWORD dwStyle = CBRS_TOOLTIPS|CBRS_FLYBY|C BRS_SIZE_F IXED;//CBR S_SIZE_DYN AMIC for allowing size change
if (!m_wndPaletteBar.Create(t his, IDD_DIALOGBAR1_DIALOG,
dwStyle,
IDD_DIALOGBAR1_DIALOG, FALSE))//TRUE to create sizeable CDialogBar
{
TRACE0("Failed to create dialog bar\n");
return -1; // fail to create
}
if (m_wndPaletteBar.CreatePal etteToolba r() == FALSE)
{
TRACE("Failed to create toolbar.");
return -1;
}
m_wndPaletteBar.SetCaption Text("Tool s");
//create the slide
dwStyle = CBRS_TOOLTIPS|CBRS_FLYBY|C BRS_SIZE_D YNAMIC;//C BRS_SIZE_D YNAMIC for allowing size change
if (!m_wndSlideBar.Create(thi s, IDD_DIALOGBAR2_DIALOG,
dwStyle,
IDD_DIALOGBAR2_DIALOG, TRUE))//TRUE to create sizeable CDialogBar
{
TRACE("Failed to create dialog bar.\n");
return -1; // fail to create
}
if (m_wndSlideBar.CreateStudy Folder(NUL L) == FALSE)
{
TRACE("Failed to create slide toolbar.\n");
return -1;
}
m_wndSlideBar.SetCaptionTe xt("Slides ");
EnableDocking(CBRS_ALIGN_L EFT | CBRS_ALIGN_RIGHT | CBRS_ALIGN_BOTTOM);
DockControlBar(&m_wndPalet teBar,AFX_ IDW_DOCKBA R_RIGHT);
DockControlBar(&m_wndSlide Bar,AFX_ID W_DOCKBAR_ LEFT);
// we need to do that ourseleves.
LoadBarState(_T("DockState "));
RecalcLayout();
return 0;
}
I called the SaveBarState(_T("DockState ")) in the OnClose() of CMainFrame. I hope someone can help me with this problem.
Jennifer
I tried to load and to save CDialogBar based on the Knowledge Base's article "How To Save and Restore State of Dockable Toolbars." However, I can't seem to get this to work. I embedded my CNewSldClass dialog bar which is derived from CMyOwnDialogBar inside my CMDIChildWnd code. CMyOwnDialogBar is derived from CDialogBar. I get an assert failed in DOCKSTAT.CPP line 477. Following is an excerpt of my code in the CMDIChildWnd:
int CChildFrame::OnCreate(LPCR
{
if (CMDIChildWnd::OnCreate(lp
return -1;
// TODO: Add your specialized creation code here
//allow docking to left, right and bottom
DWORD dwStyle = CBRS_TOOLTIPS|CBRS_FLYBY|C
if (!m_wndPaletteBar.Create(t
dwStyle,
IDD_DIALOGBAR1_DIALOG, FALSE))//TRUE to create sizeable CDialogBar
{
TRACE0("Failed to create dialog bar\n");
return -1; // fail to create
}
if (m_wndPaletteBar.CreatePal
{
TRACE("Failed to create toolbar.");
return -1;
}
m_wndPaletteBar.SetCaption
//create the slide
dwStyle = CBRS_TOOLTIPS|CBRS_FLYBY|C
if (!m_wndSlideBar.Create(thi
dwStyle,
IDD_DIALOGBAR2_DIALOG, TRUE))//TRUE to create sizeable CDialogBar
{
TRACE("Failed to create dialog bar.\n");
return -1; // fail to create
}
if (m_wndSlideBar.CreateStudy
{
TRACE("Failed to create slide toolbar.\n");
return -1;
}
m_wndSlideBar.SetCaptionTe
EnableDocking(CBRS_ALIGN_L
DockControlBar(&m_wndPalet
DockControlBar(&m_wndSlide
// we need to do that ourseleves.
LoadBarState(_T("DockState
RecalcLayout();
return 0;
}
I called the SaveBarState(_T("DockState
Jennifer
What the assert is saying is that one of the toobar identifiers (IDD_...) that is in the registry entry does not match an existing toolbar. Did you change identifiers during development? You should probably check to see what is in the registry for your application.
ASKER
No I did not change the IDD during development. For some reason the registry only shows DockState-Bar0 containing BarID=0x0000e801 and DockState-Summary containing Bars=0x00000001,ScreenCX=0 x00000480 and ScreenCY=0x00000360 even though I create two dialog bars in CChildFrame. When I first ran the program for the first time without anything entries in the registry, I created my dialog bars docked as you have seen in the code. Then I dragged one of the two dialog bar to floated state to test the SaveBarState(). I then exit the program. After this, I ran the program again, and I got the assertion that I have mentioned in my question. I don't understand why the IDD of the dialog bar in the registry does not match the existing dialog bars.
Jennifer
Jennifer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
xbwen,
I changed the SaveBarState(_T("DockState ")) call to the destructor of the CMDIChildWnd. The registry still only shows DockState-Bar0 containing BarID=0x0000e801 and DockState-Summary containing Bars=0x00000001,ScreenCX=0 x00000480 and ScreenCY=0x00000360. However, I do not get the assertion and invalid operation after moving to the MDI child. Still my problem is not resolved. When I call the LoadBarState(_T("DockState ")) in the OnCreate() of the MDI child the two dialog bar still were docked even though I purposely floated the two dialog bars before I exited the program. Please help because my deadline is coming up soon. Thanks.
Jennifer
I changed the SaveBarState(_T("DockState
Jennifer
If you move all your stuff in CMDIChildWnd::OnCreate() to CMainFrame, which means all the toolbars are define as the member
of CMainFrame,(I think it is the recommand way), I am sure the
LoadBarState,SaveBarState( ) things will work very well.
but in CMDIChildWnd, I am not sure, maybe it cann't support in MDIChildWnd or maybe it is a bug of MFC, please check with the online document about FrameWnd. The normal way we use is put toolbar in MainFrame.
Hope this can help you.
of CMainFrame,(I think it is the recommand way), I am sure the
LoadBarState,SaveBarState(
but in CMDIChildWnd, I am not sure, maybe it cann't support in MDIChildWnd or maybe it is a bug of MFC, please check with the online document about FrameWnd. The normal way we use is put toolbar in MainFrame.
Hope this can help you.