Get Windows file type icon.

S

Sin Jeong-hun

I already found that I have to use SHGetFileInfo to get the System's
associated icon with that file. But what about I just want to get
associated icon for some specific extensions? For example, 'avi'.

Think of a P2P program. The user searched for 'avi', and the program
should show result avi files with associated icons but there's no
actual file on the users system. Maybe a workaround is to create a dumb
(0KB) temp.avi file somewhere on the users system, and then apply
SHGetFileInfo. I know that would work but looks crappy. Please teach me
a decent method. Thank you.
 
N

Nicholas Paldino [.NET/C# MVP]

Demetri,

This won't work because it will not allow the caller to get the icon for
a particular extension without having a file which has that extension.
 
N

Nicholas Paldino [.NET/C# MVP]

Jeong-hun,

From the documentation for SHGetFileInfo:

If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag, this
parameter does not have to be a valid file name. The function will proceed
as if the file exists with the specified name and with the file attributes
passed in the dwFileAttributes parameter. This allows you to obtain
information about a file type by passing just the extension for pszPath and
passing FILE_ATTRIBUTE_NORMAL in dwFileAttributes.

So basically, pass "*.avi" to the function, along with
FILE_ATTRIBUTE_NORMAL for the dwFileAttributes parameter, and it will look
up the icon for an avi file.

Hope this helps.
 
G

Guest

My bad, I thought he was talking about a file he already has.

--
-Demetri


Nicholas Paldino said:
Demetri,

This won't work because it will not allow the caller to get the icon for
a particular extension without having a file which has that extension.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top