Re: ToolBar error when enter Dialog 2nd time.
I'm going home, and didn't want to leave you hanging.
I am assuming that you are using the same Dialog box object to show the
dialog box twice. CToolBar has a member variable called m_hbmImageWell that
if it is not NULL will cause LoadToolbar to fail. And the only place that is
is set to null is in CToolBar's constructor. (It should be doing that when
the toolbar is destroyed!)
2 ways to fix this problem.
1. don't reuse the same dialog object between the DoModal calls (easy fix)
2. Change the toolbar object to a pointer, set it to NULL in the dialog
box's constructor. new it in the OnInitDialog method and delete it in the
WM_DESTROY of the dialog:
BOOL CTestDlg::OnInitDialog()
{
.....
ASSERT(m_peditorTB == NULL);
m_peditorTB = new CToolbar;
if (!m_peditorTB->CreateEx(....) || !m_editorTB->LoadToolBar(...))
{
TRACE("Problem creating toolbar\n");
}
....
}
void CTestDlg::OnDestroy()
{
CDialog::OnDestroy();
delete m_peditorTB;
m_peditorTB = NULL;
}
AliR.
"AliR" <AliR@online.nospam> wrote in message
news:44cfc40e$0$23764$a8266bb1@reader.corenews.com...
What does the code that opens the dialog box look like?
AliR.
"Dalton" <vicorca@yahoo.com> wrote in message
news:1154465806.062155.45940@m79g2000cwm.googlegroups.com...
Hi;
I've created a dialog in an aplication with VC6 which has a Toolbar
created in the onInitDialog as follows:
//////////////////////////////////////////////////////
if (!m_editorTB.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |
CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |
CBRS_SIZE_DYNAMIC
| CBRS_BORDER_BOTTOM | CBRS_BORDER_RIGHT) ||
!m_editorTB.LoadToolBar(IDR_EDITORTB))
{
TRACE("Problem creating toolbar\n");
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0);
////////////////////////////////////////////////////
When I enter the Dialog for first time, the toolbar is created, no
problem.
But when I exit and enter again, the toolbar isn't created. and gives
an error.
I presume the problem is that I dont destroy the toolbar when I close
de window but I dont know how to do it.
Any help?
Thanks
Dalton