How to load a large array of strings in to an MFC combobox control fast as possible?(如何尽可能快地将大量字符串加载到 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.
这篇关于如何尽可能快地将大量字符串加载到 MFC 组合框控件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何尽可能快地将大量字符串加载到 MFC 组合框控件中?
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
