sp; }
break;
// case SB_THUMBPOSITION://Scroll to the absolute position. The current position is provided in nPos.
case SB_THUMBTRACK://Drag scroll box to specified position. The current position is provided in nPos.
{
SetScrollPos(SB_VERT,nPos);
Invalidate();
}
break;
// case SB_TOP://Scroll to top
}
CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CACComboBox::HandleCompletion()
{
// Make sure we can ''talk'' to the edit control
if( m_pEdit == NULL )
{
m_pEdit = new CEdit();
m_pEdit->SubclassWindow(GetDlgItem(1001)->GetSafeHwnd());
}
// Save the state of the edit control
CString text,bestText;
CInfoForACComboBox info;
int n = GetCount();
m_wndList.RemoveAll();
m_pEdit->GetWindowText(text);
CPoint ptCaret = m_pEdit->GetCaretPos();
// int start,end;
// m_pEdit->GetSel(start,end);
// Perform actual completion
int bestindex = -1;
int bestfrom = INT_MAX;
int from;
for ( int x = 0; x < n; x++ )
{
GetLBText(x,info.strDepict);
info.nid = x;
from = info.strDepict.Find(text);
if(from != -1)
{
m_wndList.Add(info);
if( from != -1 && from < bestfrom )
{
bestindex = x;
bestText = info.strDepict;
bestfrom = from;
}
}
}
if ( bestindex != -1)
{
// Restore the edit control
m_pEdit->SetWindowText(bestText);
m_pEdit->SetSel(text.GetLength(),bestText.GetLength());
m_pEdit->SetCaretPos(ptCaret);
}
if(m_wndList.GetSize() != 0)
{
m_wndList.ShowList();
m_wndList.Invalidate();
}
else
{
m_wndList.ShowWindow(SW_HIDE);
}
}
BOOL CACComboBox::OnCommand(WPARAM wParam, LPARAM lParam)
{
if(HIWORD(wParam) == EN_CHANGE)
{
HandleCompletion();
return TRUE;
}
return CComboBox::OnCommand(wParam, lParam);
}
void CACComboBox::PreSubclassWindow()
{
CComboBox::PreSubclassWindow();
m_wndList.Create(this);
}
void CACComboBox::OnKillfocus()
{
m_wndList.OnKillFocus(GetFocus());
}
void CACComboBox::OnSelchange()
{
m_wndList.ShowWindow(SW_HIDE);
}