Home > Software engineering >  Great god help CComboBox genuflect is begged how can select the drop-down menu to input the content
Great god help CComboBox genuflect is begged how can select the drop-down menu to input the content

Time:10-08

I want to write a CComboBox can automatically retrieve, found a problem now,

Is I insert the 10 pieces of information, for example, at the beginning of AAA five of them, the back is not the same, then I entered AAA can appear 5 information from the drop-down menu, and then the first is at the bottom of the default for the selected, marked in blue,

But the problem comes

Input box also became the first record,


I just want to realize, although below the first record is marked as blue, but I input the contents of the input box or, how to do this???????








# include "stdafx. H"
/* # include "hrinetnsm_con. H */"
# include "ComboCompletion. H"

# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif

/////////////////////////////////////////////////////////////////////////////
//CComboCompletion

CComboCompletion: : CComboCompletion ()
{
}

CComboCompletion: : ~ CComboCompletion ()
{
}


BEGIN_MESSAGE_MAP (CComboCompletion CComboBox)
//{{AFX_MSG_MAP (CComboCompletion)
ON_CONTROL_REFLECT (CBN_DROPDOWN OnDropdown)
ON_CONTROL_REFLECT (CBN_EDITUPDATE OnEditupdate)
//}} AFX_MSG_MAP
ON_MESSAGE (WM_SHOWDROP OnShowDropDown)
ON_CONTROL_REFLECT (CBN_SELCHANGE, & amp; CComboCompletion: : OnCbnSelchange)
END_MESSAGE_MAP ()

/////////////////////////////////////////////////////////////////////////////
//CComboCompletion message handlers


Int CComboCompletion: : AddString (LPCTSTR lpszString)
{
M_strArr. Add (lpszString);
Return CComboBox: : AddString (lpszString);
}
Int CComboCompletion: : DeleteString (UINT nIndex)
{
M_strArr. RemoveAt (nIndex);
Return CComboBox: : DeleteString (nIndex);
}
Int CComboCompletion: : InsertString (int nIndex, LPCTSTR lpszString)
{
M_strArr. InsertAt (nIndex lpszString);
Return CComboBox: : InsertString (nIndex lpszString);
}
Void CComboCompletion: : ResetContent ()
{
M_strArr. RemoveAll ();
CComboBox: : ResetContent ();
}

BOOL CComboCompletion: : PreTranslateMessage (MSG * pMsg)
{
//TODO: Add your specialized code here and/or call the base class
If (pMsg - & gt; Message==WM_CHAR)
{
M_bAutoComplete=TRUE;

Int nVirKey=pMsg - & gt; WParam.

The switch (nVirKey)
{
Case VK_RETURN:
{
//close the drop-down box
ShowDropDown (FALSE);

Cstrings strLine;
GetWindowText (strLine);

//return the selected highlight item
SelectString (1, strLine);

//message sent to the parent window options change
WPARAM WPARAM=MAKELPARAM (GetDlgCtrlID (), CBN_SELCHANGE);
The GetParent () - & gt; PostMessage (WM_COMMAND wParam, (LPARAM) m_hWnd);

break;
}

Case VK_DELETE:
Case VK_BACK:

M_bAutoComplete=FALSE;
break;

Default:
break;
}

}

Return CComboBox: : PreTranslateMessage (pMsg);
}

Void CComboCompletion: : OnDropdown ()
{
//TODO: Add your the control notification handler code here
SetCursor (LoadCursor (NULL, IDC_ARROW));
}

Void CComboCompletion: : OnEditupdate ()
{
//TODO: Add your the control notification handler code here
Cstrings strLine;
GetWindowText (strLine);
Cstrings szInputTemp=strLine;
SzInputTemp. MakeUpper ();

Int iHiLightStart=strLine. GetLength ();
If (strLine GetLength ()==0)
{
ShowDropDown (FALSE);
SetWindowText (_T (" "));
M_bAutoComplete=TRUE;
return;
}

//delete processing
//if (! M_bAutoComplete)
//{
//m_bAutoComplete=TRUE;
//return;
//}
CComboBox: : ResetContent ();
Cstrings szTemp;

Int nTemp=0;
if (! StrLine. IsEmpty ())
{
For (int nIndex=0; NIndex{
SzTemp=m_strArr [nIndex];
SzTemp. MakeUpper ();
Int nFrom=szTemp. Find (szInputTemp);
NFrom=m_strArr [nIndex] Find (szInputTemp);
If (nFrom!=1)/can/matching
{
CComboBox: : AddString (m_strArr [nIndex]);
NTemp++;
}
}//for
}


//match user input
Int iSelectedRow=FindString (1, strLine);
If (iSelectedRow & gt;=0)
{
PostMessage (WM_SHOWDROP, 0, 0);
//match the options selected
If (m_bAutoComplete)
{
PostMessage (CB_SETCURSEL, iSelectedRow, 0);
} the else
{
SetWindowText (strLine);
}
//to the parent window options change messages sent, so that when the input complete matching department, need not return change also triggers the department
WPARAM WPARAM=MAKELPARAM (GetDlgCtrlID (), CBN_SELCHANGE);
The GetParent () - & gt; PostMessage (WM_COMMAND wParam, (LPARAM) m_hWnd);

}
The else
{
ShowDropDown (FALSE);
SetWindowText (strLine);
}
//highlighting automatically part of the
PostMessage (CB_SETEDITSEL, 0, MAKELPARAM (iHiLightStart, 1));

}

HRESULT CComboCompletion: : OnShowDropDown (WPARAM WPARAM, LPARAM LPARAM)
{

ShowDropDown (TRUE);

return 0;
}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related