高手请如——谁知道如何提高CListBox的效率?

andygood 2000-09-10 10:15:00
在下最近在研究一个类似于Visaul C++、Visual Basic中的智能弹出式提示窗,即一个窗口+ListBox。实验发现,当向这个列表框加入超过1000项时,竟要花费将近2秒钟!(我实验的是装入CWnd类的成员函数及变量)。当然,因为这是一个OwnerDraw的列表框,除了加入字符外还加入了图标,所以时间要比普通的列表框稍长。试想一下,即便我们是在程序刚开始运行时加入几千条提示,仍然需要7、8秒——用户会砸了我的软件的。在此拜托各位高手,谁知道如何提高CListBox的效率——除了自己重新写一个? fuck windows controls!
...全文
318 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
rampig 2000-09-13
  • 打赏
  • 举报
回复
看了一下CListBox的MFC源码,它是通过SendMessage()交到Windows消息处理,由消息处理程序执行。这里就有一个消息处理的限制。
还有就是要看存储item的数据结构,针对链表还是数组,分别直接操作。
实在没空,自己看看吧。
playpcgame 2000-09-11
  • 打赏
  • 举报
回复
试试下面的方法:
CListBox.SetRedraw(FALSE);
//插入项
CListBox.SetRedraw();
我试过,插入2000项非常的快
andygood 2000-09-11
  • 打赏
  • 举报
回复
我想大家没有明白我的意思。不管开不开线程,向一个列表框中加入几千项都需要近2秒钟。而这些项显然只能在程序开始时加入。如果象vc那样载入几十个类的提示的话,需要近半分钟!即使是开多线程,每个线程分别载入一个类的话,也会超过一般的Flash Screen的时间。程序运行时动态加载更是不行的。
andygood 2000-09-11
  • 打赏
  • 举报
回复
Thanx all!

First I'll explain my program. U should have used vc or vb or delphi, etc, shouldn't u? 智能弹出式提示窗就是那种在你键入一个对象后按".",就弹出一个窗口,提示你这个对象有哪些可用的函数及变量。

I don't know how vc realized this. To me, I write a Owner-draw ListBox(which is called CSmallIconTextListBox), which give u the ability to add a string and a icon to an item. Then, I write a window class( base class is CWnd ) that has no caption and have a member of CSmallIconTextListBox class. Then, when I test it, it seems very slow.

There is an article on CodeGuru, which is "QListCtrl - a popup list box like that in Visual C++ 6.0", u can find it at ActiveX section. The author has the same opnion with me: "The list cannot be filled with all the items at runtime, because it takes long time. "

What he made is an listctrl ActiveX control. I tried, but it does not fit me. And, it'll also takes long time.

Now I'm writing an IDE software similar to vc, and such kind of popup list box is necessary. Please help me out!

When I finished, I'll open this control's source code!
Areslee 2000-09-11
  • 打赏
  • 举报
回复
只取能显示出来的那几项,当用户选择其他项时再显示其他项。
RedFire 2000-09-11
  • 打赏
  • 举报
回复
你为什么要往里面加入那么多的项呢?如果你真的想这么做的话,刚开始的时候也没有必要一直等着,真的很慢的话,另外开一个线程试试。
wsoft 2000-09-11
  • 打赏
  • 举报
回复
I think the time can't be spent at the loading items!There are other reasons.
playpcgame 2000-09-11
  • 打赏
  • 举报
回复
说说你的智能弹出式提示窗是怎么实现的
andygood 2000-09-11
  • 打赏
  • 举报
回复
To playpcgame:
First thank u very much for your help. I tried your method, but it does not work better, I think it's beacuse that I added the items before showing the tip window, so the AddString() call will not calls it to redraw. I'm very surprised that by my test, the loading takes very very little time, but it still takes near 1.5 seconds to show the tip window. Why? Cann't I use owner-draw listbox other than standard listbox? Who can help me?
Areslee 2000-09-11
  • 打赏
  • 举报
回复
在软件开始时作为字符串列表资料载入内存,在要显示时只把目前列表框中可见的几项装入列表框。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧