tags:

views:

259

answers:

1

Hi,

I wonder how to specify CDialogBar default size when it is created in MainFrame of a MFC/MDI project. Here is the code to crate dialog bar.

    // add Dialog bar window
if (m_wndDlgBar.Create(this, IDD_ADDLGBAR,
 CBRS_RIGHT|CBRS_SIZE_DYNAMIC|CBRS_FLYBY, IDD_ADDLGBAR))
{
 TRACE0("Failed to create DlgBar\n");
 return -1;      // fail to create
}

m_wndDlgBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndDlgBar);

I tried to call MoveWindow() or SetWindowPos(), but they don't work. The goal I want to achieve is when the dialogbar is created, it has fixed size(e.g. 200x300) no matter what DPI setting is. As you know, the size of dialogbar drew in resource will change as DPI setting change. So I want the dialogbar has fixed size.

Thanks in advance!

-bc

+1  A: 

You can use the CalcFixedLayout overridable method, if you subclass the CDialogBar with a custom one. For example:

class CSizingDialogBar : public CDialogBar {
    CSize m_size;
    bool m_forceSize;
public:
    CSizingDialogBar(CWnd* pParentWnd, UINT nID, CSize initialSize) 
    : CDialogBar(
        pParentWnd, nID,
        CBRS_RIGHT|CBRS_SIZE_DYNAMIC|CBRS_FLYBY, nID)
    , m_size(initialSize)
    , m_forceSize(true) {
    }
    ~CSizingDialogBar() {}

    virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz) {
        if (m_forceSize) {
            return m_size;
        }
        else {
            return CDialogBar::CalcFixedLayout( bStretch, bHorz );
        }
    }
};
Frank Krueger