mIRC Homepage
Posted By: Voice_of_Power MIME type icons - 19/10/04 12:13 PM
I'm not an expert when it comes to COM objects or reading from the registry, so I'll just ask it here. How can I retrieve the icons used for MIME types in Windows? And would that work for all Windows versions the latest mIRC works on?

For example, when I have the .zip extension, I want to see where Windows draws the icon from.

Any help, guidence, or a snippet of code, would be apreciated. Thanks! smile
Posted By: starbucks_mafia Re: MIME type icons - 19/10/04 12:56 PM
Here's a quick alias I threw together using qwerty's $regread(). It's by no means perfect, but it's somewhere to start from. For example it doesn't work with .txt on my current system, however looking at the registry manually I can't see any link between the .txt registry entry and the icon it uses in Explorer, so I haven't a clue how how to fix it.

$get_ft_icon(<file extension>) will return EXTENSION_NOT_FOUND if the file extension isn't found in the registry, and CLASS_NOT_FOUND if it finds the extension but can't find the 'class' that the extension is supposed to belong to which contains the icon location. Be aware that most icons are stored in DLLs and so will have a format like c:\blah.dll,10 where c:\blah.dll is the filename and 10 is an index.

Code:
alias get_ft_icon {
  ; Usage: $get_ft_icon(&lt;file extension&gt;)
  if (OK* !iswm $regread($+(HKEY_CLASSES_ROOT\, ., $remove($$1,.), \))) return EXTENSION_NOT_FOUND
  elseif (OK* !iswm $regread($+(HKEY_CLASSES_ROOT\, $gettok($v2,2-,32), \DefaultIcon\))) return CLASS_NOT_FOUND
  else return $gettok($v2,2-,32)
}

alias regread {
  var %a = regread $+ $ticks
  .comopen %a WScript.Shell
  if $comerr { return ERROR }
  if !$com(%a,RegRead,3,bstr,$1) {
    .comclose %a
    return ERROR
  }
  var %b = $com(%a).result
  .comclose %a
  return OK %b
}
Posted By: Mpdreamz Re: MIME type icons - 19/10/04 01:58 PM
Sweet i was actually wondering if this was possible just yesterday laugh
Posted By: qwerty Re: MIME type icons - 19/10/04 04:43 PM
The issue with .txts on your system may be because the txt extension isn't fully registered. Meaning that it's set to open with a certain program but isn't assigned an icon (and usually a meaningful description), ie the DefaultIcon key is missing but the shell\open\command one exists. In this case, Windows assing its own icon to the file type; that icon is a white piece of paper with the main icon of the application used to open this type "printed" on its center (in smaller size). Does the displayed icon for .txts on your system look like this?

Ufortunately, since this type of icon is generated by Windows and does not reside anywhere, scripts cannot use it (at least without a dll written specifically for that).

On a sidenote, and this is for the OP, certain file types (like .exe, .ico, .cur etc) use their own icon. In these cases, the DefaultIcon entry in the registry is "%1". %1 is a sort of variable, returning the full path of the file with the extension in question. So, if $get_ft_icon(ext) returns "%1", the script should use the path of a file with that extension (for example, using $findfile(\,*.ext,1)).


Edit: Actually, in case of txts, the app-icon-on-white-page icon isn't used because there already is an icon that looks like a text page in shell32.dll. Apparently, Windows has a (short, I suppose) internal list of default icons for certain extensions.
Posted By: Voice_of_Power Re: MIME type icons - 19/10/04 05:11 PM
Thanks starbucks_mafia and qwerty! Now I have something to work with. smile
Posted By: starbucks_mafia Re: MIME type icons - 19/10/04 11:19 PM
Yeah that's what it is. I never knew about that, thanks.
© mIRC Discussion Forums