Amitg2k12
Amitg2k12

Reputation: 3805

MFC Search Edit Box

I am looking for Search box control something like this enter image description here

Are there any controls available in the MFC or we need to create our own,

any example / refrence code is there that we can refer, I tried googling, but i am more getting CEditComboBox example rather then this type of control.

Thanks in Advance

Upvotes: 0

Views: 2893

Answers (2)

Denis.C
Denis.C

Reputation: 25

I also needed a feature such as this one, except for searching in a CListBox. Here is what I managed to do using the EN_CHANGE notification when the user types in the editbox :

  • m_sSearch is the CString associated with the CEdit control
  • m_lbRequest is the CListBox associated with the same control
void CRequestDlg::OnEnChangeEditSearch()
{   
    UpdateData(TRUE);
    string sEdit = m_sSearch.GetBuffer(m_sSearch.GetLength());
    string sTmp;
    for ( int n_pos = 0; n_pos < m_lbRequest.GetCount(); n_pos++ )
    {
        CString temp;
        m_lbRequest.GetText(n_pos, temp);
        sTmp = string(temp);
        if ( sTmp.find(m_sSearch) != string::npos )
        {
            m_lbRequest.SetCurSel(n_pos);
            break;
        }
    } 
    UpdateData(FALSE);
}

Upvotes: 0

MikMik
MikMik

Reputation: 3466

If you are using VS2008 SP1 or above, you have CMFCEditBrowseCtrl.

It's an edit control with a button. It has built-in "browse for file" or "browse for folder" actions when you press the button, but you can create your own custom action (search), and also customize the button image.

Check the documentation on EnableBrowseButton and OnBrowse to see how to customize the action, and SetBrowseButtonImage to customize the image.

Upvotes: 2

Related Questions