myDialogBar的动态大小

来源:互联网 发布:女程序员容易老吗 编辑:程序博客网 时间:2024/05/21 04:16

 /* Compile options needed: Default
   */

   // ResizableDlgBar.h : header file
   //

   class CResizableDlgBar : public CDialogBar
   {
   // Construction
   public:
        BOOL Create( CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle,
                     UINT nID, BOOL = TRUE);
        BOOL Create( CWnd* pParentWnd, LPCTSTR lpszTemplateName,
                     UINT nStyle, UINT nID, BOOL = TRUE);

   // Attributes
   public:
        CSize m_sizeDocked;
        CSize m_sizeFloating;
        BOOL m_bChangeDockedSize;   // Indicates whether to keep
                                    // a default size for docking

   // Operations
   public:

   // Overrides
       // ClassWizard generated virtual function overrides
       //{{AFX_VIRTUAL(CResizableDlgBar)
       //}}AFX_VIRTUAL
       virtual CSize CalcDynamicLayout( int nLength, DWORD dwMode );

   // Implementation
   public:

   // Generated message map functions
   protected:
       //{{AFX_MSG(CResizableDlgBar)
       // NOTE - the ClassWizard will add and remove member functions here.
       //}}AFX_MSG
       DECLARE_MESSAGE_MAP()
   };

   /////////////////////////////////////////////////////////////////////


   // ResizableDlgBar.cpp : implementation file
   //

   #include "stdafx.h"
   #include "ResizableDlgBar.h"

   ////////////////////////////////////////////////////////////////////
   // CResizableDlgBar Construction/Destruction

   BOOL CResizableDlgBar::Create( CWnd* pParentWnd, UINT nIDTemplate,
                                  UINT nStyle, UINT nID, BOOL bChange)
   {
        if(!CDialogBar::Create(pParentWnd,nIDTemplate,nStyle,nID))
             return FALSE;

        m_bChangeDockedSize = bChange;
        m_sizeFloating = m_sizeDocked = m_sizeDefault;
        return TRUE;
   }

   BOOL CResizableDlgBar::Create( CWnd* pParentWnd,
                                  LPCTSTR lpszTemplateName, UINT nStyle,
                                  UINT nID, BOOL bChange)
   {
       if (!CDialogBar::Create( pParentWnd, lpszTemplateName,
                                                 nStyle, nID))
           return FALSE;

       m_bChangeDockedSize = bChange;
       m_sizeFloating = m_sizeDocked = m_sizeDefault;
       return TRUE;
   }

   ////////////////////////////////////////////////////////////////////
   // Overloaded functions

   CSize CResizableDlgBar::CalcDynamicLayout(int nLength, DWORD dwMode)
   {
       // Return default if it is being docked or floated
       if ((dwMode & LM_VERTDOCK) || (dwMode & LM_HORZDOCK))
       {
           if (dwMode & LM_STRETCH) // if not docked stretch to fit
               return CSize((dwMode & LM_HORZ) ? 32767 : m_sizeDocked.cx,
                            (dwMode & LM_HORZ) ? m_sizeDocked.cy : 32767);
             else
               return m_sizeDocked;
       }
       if (dwMode & LM_MRUWIDTH)
           return m_sizeFloating;
       // In all other cases, accept the dynamic length
       if (dwMode & LM_LENGTHY)
           return CSize(m_sizeFloating.cx, (m_bChangeDockedSize) ?
                        m_sizeFloating.cy = m_sizeDocked.cy = nLength :
                        m_sizeFloating.cy = nLength);
        else
           return CSize((m_bChangeDockedSize) ?
                        m_sizeFloating.cx = m_sizeDocked.cx = nLength :
                        m_sizeFloating.cx = nLength, m_sizeFloating.cy);
   }

   BEGIN_MESSAGE_MAP(CResizableDlgBar, CDialogBar)
       //{{AFX_MSG_MAP(CResizableDlgBar)
           // NOTE - the ClassWizard will add and remove mapping macros
here.
       //}}AFX_MSG_MAP
   END_MESSAGE_MAP()

   /////////////////////////////////////////////////////////////////////
   // CResizableDlgBar message handlers
   ///////////////////////////////////////////////////////////////////// 
   

原创粉丝点击