Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

associating a file extension to his description

Status
Not open for further replies.

burgdavid

Programmer
Jun 22, 2000
70
DE
Hello,<br><br>Quickly : I'm looking for a function that can associate a file extension<br>to his description as given under 'Type' on windows file browser.*<br><br>Exactly :<br>I'm currently trying to implement files sorting in my own-developped<br>file browser. I nearly completed this, but one sorting method causes<br>me trouble : 'by type' sorting.<br><br>I have an object that makes generic Quick-Sorting and Reverse<br>Quick-Sorting (I make the reverse method). Theses sorting methods<br>need, of course, the surcharge of comparison operator. I known<br>how to do these surcharges (I succefully did it for other sorts).<br><br>But, when sorting by 'Type', the windows browser doesn't sort by<br>the extension of files (the &quot;ext&quot; in &quot;filename.ext&quot;), but by the<br>description associated to the extension (such associations are<br>defined in the windows registeries (\HKEY_CLASSES_ROOT)). Does<br>it exist a MFC function or a system call that associates the<br>extension of a file to the description of the files with this<br>extension that lies on the \HKEY_CLASSES_ROOT ?<br>(I'd like to do the same as the windows explorer.)<br><br>Maybe I can do myself a function which does this, but this will<br>means I will make many access to the windows registery while<br>sorting files and this is quite ugly, no ?!<br><br>So, does you know this helpfull function ? Tell me !<br><br>May Thanks,<br><br>David Burg.<br><br>*: Ouh, I suspect a make a lot of bad english in this sentence. Sorry,<br>I'm not english, I'm french !
 
David,<br><br>I don't believe there is any magic API's to accomplish this. You might investigate the Shell interface to see if it will provide you an enumeration of the file types with their descriptions but even if it does it is probably just reading the registry.<br><br>If you decide to continue with reading the values from the registry look at using the CRegKey class in ATL.<br><br>Then you said:<br>&gt; but this will<br>means I will make many access to the windows <br>&gt; registery while sorting files and this is quite ugly, no ?!<br><br>Yes real ugly... don't do it that way! One of these two approaches would be much better.<br><br>1) Read all the descriptions in when the application loads and keep them in memory for use when sorting. This approach would be simple to implement.<br><br>2) This is slightly harder but perhaps more efficient. Use a 'lazy evaluation' technique. When you need to sort a list of file types, read only the ones you need from the registry but then store them in memory for future use. Each time the sort is called any file types in the current list that are not already loaded into memory would then be read from the registry and added to the in-memory collection.<br><br>Good luck<br>-pete<br><br><br><br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top