Article ID | : | 143255 |
Last Review | : | November 21, 2006 |
Revision | : | 5.1 |
1. | Change the style of the mini frame window enclosing the floating dialog bar so that it is resizable. |
2. | Override CDialogBar to provide a CalcFixedLayout, which allows the dialog bar and its controls to be resized. |
1. | Use the new CBRS_SIZE_DYNAMIC style when creating the dialog bar. |
2. | Add code to an override of the new CalcDynamicLayout() function. |
Back to the top
Back to the top
1. | The CMiniDockFrameWnd surrounding the floating dialog bar must have its window styles changed so that it is resizable. |
2. | A member variable must be added to a class derived from CDialogBar to represent the appropriate floating size. |
3. | CalcFixedLayout() must be overridden in this class to set and return the floating size of the dialog bar when the dialog bar is being resized. |
Back to the top
1. | Create a new class derived from CDialogBar and override the CalcDynamicLayout() function. Depending on the behavior you want, it may be necessary to add a member variable to the class. |
2. | Create an instance of this class using the CBRS_SIZE_DYNAMIC style bit. Dialog bars are typically created in CMainFrame::OnCreate():
if (!m_wndDialogBar.Create(this, IDD_DIALOGBAR, |
Back to the top
/* Compile options needed: Default
*/
// RSZDLGBR.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
virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
// Implementation
public:
};
/////////////////////////////////////////////////////////////////////
// RSZDLGBR.CPP : implementation file
//
#include "stdafx.h"
#include <afxpriv.h>
#include "ResizableDlgBar.h"
#include "resource.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::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
if (IsFloating())
{
// Get the parent mini frame wnd
CMiniDockFrameWnd* pFrame =
((CMiniDockFrameWnd*)m_pDockBar->GetParent());
CRect rcFrame;
pFrame->GetClientRect(&rcFrame);
// Is its size (0,0)? If so, it was just floated
CSize sizerc(rcFrame.right - rcFrame.left,
rcFrame.bottom - rcFrame.top);
if (!((sizerc.cx <= 0) && (sizerc.cy <= 0)))
return ((m_bChangeDockedSize) ?
m_sizeDocked = m_sizeFloating = sizerc :
m_sizeFloating = sizerc);
else
{
// Modify Style when dialog bar is first floated
pFrame->ModifyStyle(MFS_MOVEFRAME, WS_THICKFRAME, 0);
m_dwStyle |= MFS_THICKFRAME;
m_dwStyle |= WS_THICKFRAME;
m_dwStyle &= ~MFS_MOVEFRAME;
// Return last floated size
return m_sizeFloating;
}
}
if (bStretch) // if not docked stretch to fit
return CSize(bHorz ? 32767 : m_sizeDocked.cx,
bHorz ? m_sizeDocked.cy : 32767);
else
return m_sizeDocked;
}
/* 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
/////////////////////////////////////////////////////////////////////
Back to the top
Back to the top
• | Microsoft Foundation Class Library 4.2, when used with: | |||||||||||||||||||||||||||||||||
|
Back to the top
Keywords: |
kbhowto kbuidesign kbfaq kbmfcctrlbar kbcode KB143255 |
Back to the top