Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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
 
Share this answer
 
Comments
sparktrick 20-Jul-11 5:04am    
Thank You SAKryukov,
I'm displaying folders first followed by files. The same piece of code compiled for desktop works fine as expected. It lists sorted folders, followed by sorted files.

But on Windows mobile emulator it does not sort, but displays files and folders clearly.

FindFirstFile() and FindNextFile() gets file and folder name as it is stored. In windows mobile, files and folders aren't stored in sorted manner, I guess. But in desktop, Files and folders are stored in sorted manner.

Is my guess right Kryukov?

-Spark.
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."
 
Share this answer
 
Comments
sparktrick 20-Jul-11 4:57am    
Thank You Stephen,
When we are using more than 1 column (report style) with column header, we can go for LVN_COLUMNCLICK and use some kind of sorting. But in 'list view style' you wont have separate column header to click on.

I'm able to display folders followed by files. But not in sorted manner. With same code compiled for desktop performs as expected in sorted, but not on windows mobile emulator 6.5.3. I'm not able to guess it why.
Plz help!

-Spark
Stephen Wiria 20-Jul-11 5:38am    
Sorry, I missed that part.

Is it possible to create the listview in report style and then make it 2 columns.
Set first column's cx to 0 and fill the second column with the real data.
That way you still have 1 visible column and able to sort by clicking it's header.
sparktrick 23-Jul-11 7:15am    
Hi Stephen,
I'm back. I tried making my list view to report style. Sorting works well in desktop but when i move code to windows mobile, its not sorting.
When i click column header, items are rearranged but not sorted.
Help!
-spark
sparktrick 20-Jul-11 6:09am    
Ya this sounds good Stephen. 'll try it and let you know.
Thank You.

-Spark
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.
 
Share this answer
 
Comments
sparktrick 20-Jul-11 4:52am    
Thank You Richard.
Even I've tried listing using List box. But drawback is we can't show icons for folders and files.
That is the reason why I chose List View.

-Spark
Richard MacCutchan 20-Jul-11 6:15am    
I am not suggesting you use a ListBox instead of the View, just to use it as a temporary control to get your directory and filenames in the proper sorted order.
sparktrick 20-Jul-11 6:27am    
Ya I understood your suggestion Richard. But this listing itself taking acceptable time delay to display. If I use List Box for temp storage, then delay 'll get increased twice or thrice.
'll try it and let you know Richard.
Thank You

-Spark.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900