Http://support.microsoft.com/default.aspx?scid=kb;n-us; 143255 Description: The method used in the previous version of MFC4.0 is ignored during translation.
[Problem Narrative]: The cdialogbar implemented by the MFC is not allowed to change the size when the floating state is. If the Dialog Bar contains controls that need to dynamically change the size, we can use the methods described below to change the size of the Dialog Bar.
[Method]: After MFC4.0, Control Bar has built-in support for variable size. However, Dialog Bar cannot get this support through the default behavior. In order to make Dialog Bar change the size, we need: 1. Add a CBRS_SIZE_DYNAMIC style when creating Dialog Bar. 2. Add code to overload the CalcDynamicLayout () function. In the MFC4.0 and subsequent high version of the MFC, the Control Bar supports the new CBRS_SIZE_DYNAMIC style, and the CBRS_SIZE_DYNAMIC style allows a floating Control BAR to dynamically change the size when the user is dragged. The virtual function ccontrolbar :: calc DynamicLayout () is also added to control the size of the Control Bar. Regardless of whether the Control Bar is docked or floating, when a floating Control Bar is dragged, the CONTROL BAR with the CBRS_SIZE_DYNAMIC style will call the CalcDynamicLayout () function. CControlBar calls CalcFixedLayout () by default, and this function prevents the Control bar object from changing the size unless we overreload the CalcDynamicLayout () function. CDialogbar is not overloaded Calc DynamicLayout (), so it cannot change the size by default. Therefore, create a variable size Dialog bar We need 1 to inherit a class from CDialogBar to overload the CalcDynamicLayout () function, which can add a member variable to this class according to the behavior we need. 2 Create an instance with CBRS_SIZE_DYNAMIC style, the most common approach is to CMainFrame :: OnCreate () function in creation: (! M_wndDialogBar.Create (this, IDD_DIALOGBAR, CBRS_TOP | CBRS_SIZE_DYNAMIC, 777)) if {TRACE0 ( "Failed to create dialogbar / N "); RETURN-1;} m_wnddialogbar.enabledocking (cbrs_align_any); DockControlbar;
Note: The IDD_Dialogbar dialog resource must have a WS_CHILD style and cannot have any other style.
Here is sample code: / * 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; // indeicates WHETHER TO Keep // a default size for docking
// Operations public:
// Overrides // ClassWizard Generated Virtual function overrides // {{AFX_VIRTUAL (CRESIZABEDLGBAR) //}} AFX_VIRTUAL Virtual Csize CalcdynamiT (int NLENGTH, DWORD DWMODE);
//Mplementation public:
// generated message map functions protected: // {{AFX_MSG (CRESIZABEDLGBAR) // Note - The Classwizard Will Add and Remove Member Functions Here. //}} AFX_MSG DECLARE_MESSAGE_MAP ()};
/ // resizabledlgbar.cpp: importation 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; returntrue;}
// 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_sized.cx = NLENGTH: M_SIZEFLOATING.CX = NLENGTH, M_SIZ Efloating.cy);