I have a CDialogBar derived class stated as below. A colleague said to me that MFC doesn't offer aligment flow layout control (which I find something unbelievable in the year 2012!). I had to do the thing with the OnSize function as I show:
//declaration of member variable
class CMyDialogBar : public CDialogBar
{
private:
int m_old_cx;
//...
}
//the message map
BEGIN_MESSAGE_MAP(CMyDialogBar, CDialogBar)
//...
ON_WM_SIZE()
END_MESSAGE_MAP()
//the implementation
void CMyDialogBar::OnSize(UINT nType, int cx, int cy)
{
CDialogBar::OnSize(nType, cx, cy);
if (!::IsWindow(this->GetSafeHwnd()))
return;
// align right Combo1 and its label
CRect rc;
CWnd *pWnd= this->GetDlgItem(IDC_COMBO1);
if(pWnd)
{
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc);
pWnd->MoveWindow(rc.left + cx - m_old_cx, rc.top ,rc.Width(), rc.Height());
}
pWnd= this->GetDlgItem(IDC_STATIC_COMBO_LABEL);
if(pWnd)
{
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc);
pWnd->MoveWindow(rc.left + cx - m_old_cx, rc.top ,rc.Width(), rc.Height());
}
m_old_cx= cx;
}
Even after seeing this working, I do not trust it very much. So my question is: Is there a better way of right -aligning controls?
Thanks in advance,
Sérgio