As we know,Windows Common Control: ListView support virtual listView.A good sample you can downloaded here:
http://www.codeguru.com/cpp/controls/listview/advanced/article.php/c4151
Now I just noted some tips for how to use this feature in Windows Application or if you want to wrap a customize control by yourself:
Steps:
1.Make sure the ListView is owner-data style:
Virtual List-View Style
A virtual list view is a list-view control that has the LVS_OWNERDATA style. This style enables the control to handle millions of items because the owner receives the burden of managing item data. This allows you to use the virtual list-view control with large databases of information, where specific methods of data access are already in place.
A virtual list-view control maintains very little item information itself. Except for the item selection and focus information, the owner of the control must manage all item information. Other processes request item information from the owner by using LVN_GETDISPINFO notification messages.
Because this type of list control is intended for large data sets, it is recommended that you cache requested item data to improve retrieval performance. The list view provides a cache-hinting mechanism to assist in optimizing the cache. The hint is implemented in the form of an LVN_ODCACHEHINT notification message.
Creating a Virtual List-View Control
You create virtual list-view controls using the CreateWindow or CreateWindowEx function, specifying the LVS_OWNERDATA window style as part of the dwStyle function parameter.
You can use the LVS_OWNERDATA style in combination with most other window styles, except the LVS_SORTASCENDING or LVS_SORTDESCENDING style. All virtual list-view controls default to the LVS_AUTOARRANGE style.
Note Dynamically switching to and from the LVS_OWNERDATA style is not supported.
2.Response some notify msg to cache the data
Handling Virtual List-View Control Notification Messages
List-view controls with the LVS_OWNERDATA style send the same notification messages as other list-view controls and two additional ones: LVN_ODCACHEHINT and LVN_ODFINDITEM. The following are the most common notifications that the list-view control with the LVS_OWNERDATA style sends.
LVN_GETDISPINFO
A virtual list-view control maintains very little item information on its own. As a result, it often sends the LVN_GETDISPINFO notification message to request item information. This message is handled in much the same way as callback items in a standard list control. Because the number of items supported by the control can be very large, caching item data improves performance. When handling LVN_GETDISPINFO, the owner of the control first attempts to supply requested item information from the cache (for more information, see Cache Management). If the requested item is not cached, the owner must be prepared to supply the information by other means.
LVN_ODCACHEHINT
A virtual list view sends the LVN_ODCACHEHINT notification message to assist in optimizing the cache. The notification message provides inclusive index values for a range of items that it recommends be cached. Upon receiving the notification message, the owner must be prepared to load the cache with item information for the requested range so that the information will be readily available when an LVN_GETDISPINFO message is sent.
LVN_ODFINDITEM
The LVN_ODFINDITEM notification message is sent by a virtual list-view control when the control needs the owner to find a particular callback item. The notification message is sent when the list-view control receives quick key access or when it receives an LVM_FINDITEM message. Search information is sent in the form of an LVFINDINFO structure, which is a member of the NMLVFINDITEM structure. The owner must be prepared to search for an item that matches the information given by the list-view control. The owner returns the index of the item if successful, or -1 if no matching item is found.
Cache Management
A list-view control with the LVS_OWNERDATA style produces a large number of LVN_GETDISPINFO notification messages and, to assist in optimizing the cache, an LVN_ODCACHEHINT message. LVN_ODCACHEHINT messages provide information about the recommended items to include within the cache. These messages are sent as WM_NOTIFY messages, with the lParam value acting as the address of an NMLVCACHEHINT structure.
The NMLVCACHEHINT structure includes two integer members, iFrom and iTo, that represent the inclusive endpoints of a range of items that most likely will be needed. The owner must be prepared to load the cache with the item information for each of the items within the recommended range.
The list control often needs item information for the first item (offset 0). The LVN_ODCACHEHINT notification message might not always include item 0, but it must always be included in the cache.
The last items in the list are accessed often. Therefore, the owner might want to keep a second cache that includes the items at the end of the list. The requested range from LVN_ODCACHEHINT can be checked against the end cache to make it available automatically instead of reloading the same end range each time.
中文notes:
一个是style要对,这个style不能动态切换。然后就是响应几个notify消息。当Virtuallist 开始绘制的时候,它会发消息让你告诉它内容。窗口只绘制可见的那一部分。virtual list 只给你维护一些索引值。所以理论上可以支持 M(million) 条数据,这些数据你可以保存在DB里。
如果你自己想要封装一个没有窗口的控件,可以模仿这样的做饭。MSN的UI就是windowsless UI,包括qq2009 也是类似的做法。不过个人认为,如果你的application 不考虑跨平台的,还是用windows common control方便。毕竟这东西经过了这么多年的发展和n多用户的检验,其性能和稳定性已经非常的好,而且兼容性做的非常棒,并且支持多线程。如果你是完全自己做,估计得花n年时间。如果你不满足于common control那样的土颜色和风格,最好的方式是在 windows common control的基础上进行开发,这样能事半功倍!如果你还想要一些3D的窗口效果,可以考虑结合Dx或者OpenGL,那样的UI会非常棒,尤其适合一款面向个人的软件:比如IM,game UI等。