将搜索功能添加到MFC组合框 [英] Adding search functionality to a MFC combo box
问题描述
我需要创建一个组合框,为用户提供自动搜索功能。它应该像我们在Windows运行对话框或Windows搜索对话框中看到的组合框一样。因此,当用户键入字符时,必须显示组合框列表中的所有匹配字符串。
我这样做的想法如下:
1>每次用户编辑组合编辑框时都会收到通知。
2>在编辑处理程序中,获取组合框中的文本。
3>然后搜索组合框列表中的所有条目,并在列表中构建匹配条目的向量。
4>创建一个填充了向量中的字符串的列表框并显示它(与组合框正确对齐)。
有没有更简单的方法可以做到这一点,还是MFC提供了更简单的方法或任何现成的功能,可以完成上述步骤中提到的所有任务?一些示例代码或链接将有所帮助。
请参阅这个 [ ^ ]文章。
文章中提供的控件涵盖了您的所有要求,并支持CEdit
和CComboBox
。 :)
参考。对于这篇文章,它可能会帮助你:
http://www.codeguru.com/cpp/controls/combobox/article.php/c4951 [ ^ ]
我自己使用了相同的技术。 MFC不提供任何现成的功能。
Hi,
I need to create a combo box which provides the auto search feature to a user. Its should behave just like the combo box which we see in the Windows 'Run' dialog or in the windows search dialog. So, as the user types in characters , all the matching strings in the combo box list must be displayed.
MY idea for doing this is as follows:
1> Get notified every time the user edits the combo edit box.
2> In the edit handler, get the text in the combobox.
3> Then search through all entries in the combo box list and build a vector of matching entries in the list.
4> Create a list box populated with the strings in the vector and display it (properly aligned with the combo box).
Is there a simpler way of doing this or does MFC provide a simpler way or any ready made functions which can accomplish all the tasks mentioned in the steps above? Some sample code or links will be helpful.
Refer to this[^] article.
The control presented in the article covers all of your requirements and supports bothCEdit
andCComboBox
. :)
Ref. to this article, it might help you out:
http://www.codeguru.com/cpp/controls/combobox/article.php/c4951[^]
I myself had used the same technique. MFC doesn't provide any ready made functions.
这篇关于将搜索功能添加到MFC组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!