Reputation: 83
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
Upvotes: 2
Views: 3128
Reputation: 2911
CalcFixedLayout works just fine, but if you cannot override the method:
Change the CDialogBar m_sizeDefault member to the size you need before calling MoveWindow() or SetWindowPos(), after that it should resize correctly. Actually you will also need to add the borders to the size (they must fit in the window as well) so what I used is something like this:
int nEdgeThickness = GetSystemMetrics(SM_CXSIZEFRAME);
pContrBar->m_sizeDefault = CSize(rc->right+nEdgeThickness*2, rc->bottom+nEdgeThickness);
I needed this to dynamically change the CDialogBar's size, so I knew when it would resize.
Upvotes: 0
Reputation: 71063
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 );
}
}
};
Upvotes: 2