简体   繁体   中英

MFC Search Edit Box

I am looking for Search box control something like this 在此输入图像描述

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

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.

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); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM