如何尽可能快地将大量字符串加载到 MFC 组合框控件中?
我有一个包含 1000 个字符串的数组要加载到组合框中.将字符串数组加载到组合框中的最快方法是什么?
I have an array of 1000 strings to load into a combo box. What is the fastest way to load the array of strings into the combo box?
除了遍历字符串列表,将每个字符串一次一个地放入组合框之外,还有其他方法吗?
Is there some way other than iterating over the list of strings, putting each string into the combo box one at a time?
以及如何将加载后的组合框数据复制到其他 10 个组合框?
And how to copy the combo box data once loaded to some 10 other combo boxes?
推荐答案
如果您在 10 个组合框中重复了 1,000 个字符串,您可能需要考虑使用所有者绘制的组合框,它根据索引动态地将字符串绘制到您的数组,而不是将它们存储在组合框中.速度更快,内存效率更高.查看在线帮助中的 DrawItem 方法和 DRAWITEMSTRUCT 结构.基本上,您可以使用 InitStorage 和 InsertString(如 NuSonic 所述)在组合框中创建 1000 个空白项目,并覆盖 DrawItem 根据需要绘制的索引提取并绘制所需的字符串.
If you have 1,000 strings repeated in 10 comboboxes, you may want to consider using an owner drawn combobox, which draws the strings on the fly based on indices into your array, rather than storing them in the combobox at all. Way faster, way more memory efficient. Check out the DrawItem method and DRAWITEMSTRUCT structure in the on-line help. Basically, you would do something like using InitStorage and InsertString (as mentioned by NuSonic) to create your 1000 blank items in your combobx, and override DrawItem to extract and draw the required string, based on index, as it needs to be drawn.
相关文章