我有一個如下所述的CDialogBar派生類。一位同事對我說,MFC不提供對齊流程佈局控制(我發現在2012年有些令人難以置信的事情!)。我不得不做的事與篩上部分功能爲我顯示:MFC對齊CDialogBar上的控件
//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;
}
即使看到這方面的工作後,我不相信它非常。所以我的問題是:是否有更好的方法來對齊控件?
由於提前,
塞爾吉奧
它在Visual C++ 2015中進行了更改,現在它們具有稱爲「動態佈局」的功能,可以完全解決此問題。 – sergiol 2016-06-07 22:55:36