Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I' m new with MFC. I needed to create a floating toolbar (CToolBar) with no option of docking and save and restore its last pos.

The toolbar also should be active all the time, but its NOT. When I'm openning a new child window (dialog for instance) from the mainframe, the floating tool bar become not active (I can not click on its buttons, or drag it etc..).

In the past I've used CDiaolog with Overlapped style and it was floating and always active as I needed. Is it possible to do the same with my Floating Toolbar? Thanks

C++
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{     
   if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
   return -1;

   toolbarIconSize.cx = toolbarIconSize.cy = TOOLBAR_MAIN_ICON_SIZE;
   if ( !m_wndMyFloatingToolbar.Create(this,m_wndMyFloatingToolbar.GetBarStyle() |WS_EX_PALETTEWINDOW  | WS_EX_TOPMOST  |CBRS_FLOATING | WS_VISIBLE) ||
    !m_wndMyFloatingToolbar.LoadToolBar(IDR_GENERAL_TOOLBAR, toolbarIconSize))
    {
       TRACE0("Failed to create My Floating Toolbar\n");
       return -1;      // fail to create
    }

   m_wndMyFloatingToolbar.EnableDocking(0);
   EnableDocking(0);

   if (!CreateCtrlBar())
   {
       TRACE0("Failed to create ctrl toolbar\n");
       return -1;      // fail to create
   }

   // ...
   //...
   return 0; 
}

void CMainFrame::OnViewToolBar()
{
   // ...
   //...

   CPoint Pos = MyFloatingToolbarGetLastPosition(); \\Get last pos 
   FloatControlBar( &m_wndMyFloatingToolbar, Pos, CBRS_ALIGN_LEFT );
   MyFloatingToolbarSetIsVisible();
   FloatControlBar( &m_wndMyFloatingToolbar, Pos, CBRS_ALIGN_LEFT );
}
void CMainFrame::MyFloatingToolbarSetIsVisible()
{
   WINDOWPLACEMENT wp;
   m_wndMyFloatingToolbar.GetParent()->GetParent()->GetWindowPlacement(&wp);
   wp.showCmd = SW_SHOW;
   m_wndMyFloatingToolbar.GetParent()->GetParent()->SetWindowPlacement(&wp);

   m_wndMyFloatingToolbar.GetParent()->GetWindowPlacement(&wp);
   wp.showCmd = SW_SHOW;
   m_wndMyFloatingToolbar.GetParent()->SetWindowPlacement(&wp);

   m_wndMyFloatingToolbar.GetWindowPlacement(&wp);
   wp.showCmd = SW_SHOW;
   m_wndMyFloatingToolbar.SetWindowPlacement(&wp);
}
void CWJToolBar::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{ 
   CToolBar::OnWindowPosChanging(lpwndpos); 

   if ( GetBarStyle() & CBRS_FLOATING )
   {
       if((lpwndpos->flags & SWP_HIDEWINDOW) && ((this->GetParentFrame())->m_hWnd !=(this->GetTopLevelFrame())->m_hWnd)) 
       { 
           CMainFrame* mf = (CMainFrame*)(AfxGetApp()->GetMainWnd());
           mf->MyFloatingToolbarSavePosition();         
       }
   }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900