如何尽可能快地将大量字符串加载到 MFC 组合框控件中?

How to load a large array of strings in to an MFC combobox control fast as possible?(如何尽可能快地将大量字符串加载到 MFC 组合框控件中?)

本文介绍了如何尽可能快地将大量字符串加载到 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 结构.基本上,您可以使用 InitStorageInsertString(如 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.

这篇关于如何尽可能快地将大量字符串加载到 MFC 组合框控件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何尽可能快地将大量字符串加载到 MFC 组合框控件中?

基础教程推荐