У меня есть класс, производный от CDialogBar, который указан ниже. Коллега сказал мне, что MFC не предлагает управление компоновкой потока aligment (что я считаю чем-то невероятным в 2012 году!). Я должен был сделать это с функцией OnSize, как я показываю:
//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;
}
Даже увидев эту работу, я не очень ей доверяю. Поэтому мой вопрос: есть ли лучший способ правильного выравнивания элементов управления?
Заранее спасибо,
Сержио