Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

non-wrapping toolbars like DevStudio (urgent)

I need an answer to the following question urgently and so pls answer me ASAP. (Thanks for ur hlp :))

I want my application to have non-wrapping toolbars (like DeveStudio has).

In DOCKTOOL sample supplied by Microsoft if you resize mainframe window toolbars get aligned into seperate lines (ie get stacked).
But if you resize the mainframe window of all Microsoft packaged Apps (like Word, DevStudio) toolbars do not get wrapped down.

How to acheive this?

Regards,
devenkat@cyberspace.org
D.Venkatesan Pillai
Software engineer, AUTODESK Inc., SanFransisco, CA -94903
0
dvenkat
Asked:
dvenkat
  • 2
1 Solution
 
galkinCommented:
When frame is resized or control bars visibility is toggled on/off frame window calls its virtuall function RecalcLayout which in turn calls RepositionBars. This CWnd member function brodcasts MFC private messge WM_SIZEPARENT define in afxpriv.h passing pointer to AFX_SIZEPARENTPARAMS MFC structure as LPARAM. This structure contains frame expected size and allows control bars to adjuxt this size and reposition themselves. If you want to overwrite standard behaviour you should handle this message and implement your own adjustment.
0
 
dvenkatAuthor Commented:
I tried your (galkin's) IDEA on DOCKTOOL samples(suppled by MicroSoft), but apart from startup time later on FRAME RESIZING event the MsgHandler for my specialised CTOOLBAR class (CTOOLBARSPEC) was never getting called.

stp-by-step what I did follows :

//////////////////Step 0 ///////////////////////////
///////////////////////////////////////////////////

modify CMainFrame class ToolBar varibales to my own TOOLBAR varible (it is called "CToolBarSpec")

(lines in "mainframe.h" Class CMainFrame)
      CToolBarSpec    m_wndMainBar;  
      CToolBarSpec    m_wndResourceBar;
      CToolBarSpec      m_wndDebugBar;
      CToolBarSpec    m_wndBrowseBar;



//////////////////Step 1 ///////////////////////////
///////////////////////////////////////////////////

Specialise CTOOLBAR class to proved WM_PARENTSIZE handler by introducing a specialied class called CTOOLBARSPEC in "mainframe.h"

#include "afxpriv.h"

class CToolBarSpec : public CToolBar
{
      DECLARE_DYNAMIC(CToolBarSpec);

public :
      BOOL      mDynamicHide; //A falg to indicate if the toolbar                               //was  hidden dynamically to                               //acheive DevStudio style DockBar
      CToolBarSpec()
      {
            mDynamicHide = FALSE;
      };

public :
      virtual ~CToolBarSpec()
      {

      };

protected:
      //{{AFX_MSG(CTollBarSpec)
      afx_msg LRESULT OnParentSize(WPARAM w, LPARAM l);
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};



//////////////////Step 2 ///////////////////////////
///////////////////////////////////////////////////

Write an implementation for OnParentSize which actually compares its own framesize (Controlbars') with parent's FrameSize, and if it is about to go out of parent frame it hides dynamiccalyy.
In the same way if it is about to be visible to shows up again.

I added the following line in "mainframe.cpp"
(for specializing WM_PARENTSIZE msg handler.. of CControlBar )


IMPLEMENT_DYNAMIC(CToolBarSpec, CToolBar)

BEGIN_MESSAGE_MAP(CToolBarSpec, CToolBar)
      ON_MESSAGE(WM_SIZEPARENT, OnParentSize)
END_MESSAGE_MAP()



LRESULT CToolBarSpec::OnParentSize(WPARAM wParam, LPARAM lParam)
{
      TRACE("......................OnParent SIZE called \n");

      /****
      // special struct for WM_SIZEPARENT
      struct AFX_SIZEPARENTPARAMS
      {
            HDWP hDWP;       // handle for DeferWindowPos
            RECT rect;       // parent client rectangle (trim as appropriate)
            SIZE sizeTotal;  // total size on each side as layout proceeds
            BOOL bStretch;   // should stretch to fill all space
      };
      ***/
      AFX_SIZEPARENTPARAMS * psSizeParent = (AFX_SIZEPARENTPARAMS *) lParam;

      RECT frameRect = psSizeParent->rect;
      RECT ToolbarRect;

      //(left,top)******************
      //                  *                *
      //                  *                *
      //                  ******************(right, bottom)

      GetWindowRect(&ToolbarRect);

      //Horizantally docked toolbars (hiding)
      if ( ToolbarRect.left + 10 >=  frameRect.right ) //Horizantal Toolbar about to hide
      {
            if (IsWindowVisible() && !mDynamicHide) //by default visible && not dynamically hidden
            {
                  TRACE("......................Horizantal toolbar hidden \n");
                  psSizeParent->hDWP = NULL;
                  mDynamicHide = TRUE;
                  ShowWindow(SW_HIDE);
            }
      }

      //Vertically docked toolbars (hiding)
      if ( ToolbarRect.top + 10 >=  frameRect.bottom ) //Horizantal Toolbar about to hide
      {
            if (IsWindowVisible() && !mDynamicHide) //by default visible && not dynamically hidden
            {
                  TRACE("......................VERTICAL toolbar hidden \n");

                  psSizeParent->hDWP = NULL;
                  mDynamicHide = TRUE;
                  ShowWindow(SW_HIDE);
            }
      }


      //Horizantally docked toolbars (showing)
      if ( ToolbarRect.left + 10 >=  frameRect.right ) //Horizantal Toolbar about to Show itself up
      {
            if (!IsWindowVisible() && mDynamicHide) //not visible && dynamically hidden
            {
                  mDynamicHide = FALSE;
                  ShowWindow(SW_SHOW);
            }
      }

      //Vertically docked toolbars (Showing)
      if ( ToolbarRect.top + 10 >=  frameRect.bottom ) //Horizantal Toolbar about to Show itself
      {
            if (!IsWindowVisible() && mDynamicHide) //not visible && dynamically hidden
            {
                  mDynamicHide = FALSE;
                  ShowWindow(SW_SHOW);
            }
      }

      return 0;
};



//////////////////Step 3 ///////////////////////////
///////////////////////////////////////////////////
Compile.  Set a break point in CTOOLBARSPEC::OnParentSize()
function.

And start the program in debugger :

Only during startup (the first time of showing ) of MainFrame window this function is getting called. (ie MSG reaches CTOOLBARSPEC class msg handler).

LATER ON WHEN YOU RESIZE THE PARENT WINDOW IT is NNNNNNOOOOOOOOOOOOOOOOOOOOTTTTTTTTTTTTTTTT getting Called...

Pls help.................


0
 
galkinCommented:
First of all it is very strange that WM_SIZEPARENT message handler in your toll bar class is never called. your code seems correct. Try to set breakpoint in your parent frame derived class WM_SIZE message handler and step into CFrameWnd::OnSize. You will see that this function simply calls RecalcLayout() if frame is not minimized. RecalcLayout virtual function after some preprocessing calls CWnd::RepositionBars. This function in turn also after some preprocessing sends WM_SIZEPARENT message to all toolbars and view to be filled frame's client area. The reason tool bar doesn't receive this message may be in the fact your toolbar IDs do not lie between AFX_IDW_CONTROLBAR_FIRST and AFX_IDW_CONTROLBAR_LAST. In this case this message is not sent to control bar.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now