void CTTComboBox::AlignListBoxWithCombo() { if (m_cbi.hwndList == NULL || !::IsWindow(m_cbi.hwndList)) return; CListBox* pList = (CListBox*)CWnd::FromHandle(m_cbi.hwndList); CRect l_rcCombo; GetClientRect(&l_rcCombo); CRect l_rcList; pList->GetClientRect(&l_rcList); int dropWidth = GetDroppedWidth(); int listWidth = l_rcList.Width(); int xOffset = 0; switch (m_alignStyle) { case 0: xOffset = 0; break; case 1: xOffset = dropWidth - l_rcCombo.Width(); break; case 2: xOffset = (dropWidth - l_rcCombo.Width()) / 2; break; default: xOffset = 0; break; } pList->ClientToScreen(&l_rcList); pList->SetWindowPos(NULL, l_rcList.left - xOffset, l_rcList.top, 0, 0, SWP_NOSIZE); }