Question : toolbar on a child window

Hi all,
I would like to create a dialog which is a child window. On the window there is a toolbar.
BOOL CPlayerForm::Create(CString title, CWnd* pParentWnd) {
......
m_toolBar.Create( this ) ||            m_toolBar.LoadToolBar(IDR_TOOLBAR_PLAYER))
m_toolBar.SetBarStyle(CBRS_ALIGN_ANY | CBRS_TOOLTIPS | CBRS_FLYBY);
}

When I show the dialog the toolbar is disabled. If I change the window style to overlapped or popup, toolbar appears properly. What might be the reason?
Thanks
Kerem

Answer : toolbar on a child window

Hi keremcaglar,

I think I solved your problem. Main difficulty results from this:

There's a function LRESULT CControlBar::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM) which
manages the calling of all the OnUpdateXXX handlers. In this function you can find following:

....
CFrameWnd* pTarget = (CFrameWnd*)GetOwner();
if (pTarget == NULL || !pTarget->IsFrameWnd())
      pTarget = GetParentFrame();
if (pTarget != NULL)
      OnUpdateCmdUI(pTarget, (BOOL)wParam);
....

so, if pTarget->IsFrameWnd() returns FALSE (which it does for dialogs), the
parent-frame is used.
Now, my first idea was to simply override CWnd::IsFrameWnd for the dialog's class and there return TRUE, but this causes a failure somewhere in CControlBar::OnCreate() in this code:

....
if (pFrameWnd->IsFrameWnd())
{
      m_pDockSite = pFrameWnd;
      m_pDockSite->AddControlBar(this); // this crashes
}
....

so, I tried following and it works for me:

// in your dialog add following:
BOOL m_bInit;
virtual BOOL IsFrameWnd() const { return m_bInit; }
....

then set m_bInit in ctor to FALSE and at the end of OnInitDialog (or at least after creation of toolbar) set it to TRUE.

hope it helps,

ZOPPO
Random Solutions  
 
programming4us programming4us