使用Winapi的排序列表视图 [英] Sorting List view using Winapi

查看:77
本文介绍了使用Winapi的排序列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经为Windows Mobile创建了文件浏览器应用程序.

我使用具有列表视图样式(而不是报表或图标样式)的列表视图来列出那些文件和文件夹.我使用资源编辑器创建了列表视图.

我使用FindFirstFile()和FindNextFile()检索了文件和文件夹的名称,然后在列表视图中将其与相应的图标一起显示.

列表可以很好地工作,首先显示文件夹,然后显示文件,但是它们没有排序.

我们是否需要创建任何特殊的排序算法?排序后会保留其各自的图标吗?

谁能帮我分类列出的物品吗?我使用的是Winapi,纯粹是C,而不是MFC.

谢谢.

问候
-SparkTrick

Hi,

I''ve created an file browser application for Windows Mobile.

I made use of list view with list view style (not report or icon style) to list those files and folders.I created list view using resource editor.

I retrieved files and folders name using FindFirstFile() and FindNextFile() and then i display it along with respective icons on list view.

Listing works fine with folders displaying first and then files, but they are unsorted.

Do we need to create any special sorting algorithm? Will it keep their respective icon after sorting?

Can anyone please help me on how to sort those listed items? I''m using winapi, purely C and not MFC.

Thank You.

Regards
-SparkTrick

推荐答案

感谢您使用带有C的原始Windows API的勇气.
您需要使用所需的排序条件在C中实现排序的容器,并将在FindFirstFileFindNextFile中找到的文件一一放置.由于这些功能始终为您提供一个文件,因此,我不建议您将容器(如数组)与某种排序算法结合使用.您需要一个已排序的包含项,它会在已排序的集合中添加一个新项目,这与通用排序算法完全不同.希望您可以在C中实现它或找到实现.

-SA
I appreciate your bravery using raw Windows API with C.

You need to implement sorted container in C working with sorted criteria you need and put your files found by FindFirstFile and FindNextFile one by one. As these functions give you files one by one anyway, I do not recommend a container (like array) in combination with some sorting algorithm; you need a sorted contained which adds a new item in an already sorted collection, which is quite different from the general-purpose sorting algorithm. Hope you can implement it in C or find implementation.

—SA


通常,需要捕获 LVN_COLUMNCLICK [ ^ ]并使用 ListView_SortItems [ ^ ]或 ListView_SortItemsEx [ [
Usually one need to catch LVN_COLUMNCLICK[^] and process the sorting stuff with ListView_SortItems[^] or ListView_SortItemsEx[^].
There''re so many samples out there[^].

Please pay an extra attention with this note:
"During the sorting process, the list-view contents are unstable. If the callback function sends any messages to the list-view control aside from LVM_GETITEM (ListView_GetItem), the results are unpredictable."


我过去也遇到过类似的问题,并通过创建具有LBS_HASSTRINGS | LBS_SORT样式的新ListBox控件(未显示)解决了该问题.然后,我将每个文件或目录名称添加到控件中,但在文件名前添加"F"并在目录名前添加"D",以便对它们进行排序,所有目录都在所有文件之前.添加完所有名称后,我便可以读回它们(正确排序)并将它们添加到我的主视图中,顺序与Windows资源管理器中显示的顺序相同.
I have faced a similar issue in the past and resolved it by creating a new ListBox control (which is not displayed) that has the LBS_HASSTRINGS | LBS_SORT styles. I then add each file or directory name to the control, but prefix filenames with ''F'' and directory names with ''D'', so they are sorted, with all directories before all files. When all names have been added I can then read them back (correctly sorted) and add them to my main view in the same order as would be seen in Windows Explorer.


这篇关于使用Winapi的排序列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆