mIRC Home    About    Download    Register    News    Help

Print Thread
#101005 19/10/04 12:13 PM
Joined: Oct 2003
Posts: 42
V
Ameglian cow
OP Offline
Ameglian cow
V
Joined: Oct 2003
Posts: 42
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

#101006 19/10/04 12:56 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#101007 19/10/04 01:58 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Sweet i was actually wondering if this was possible just yesterday laugh


$maybe
#101008 19/10/04 04:43 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.

Last edited by qwerty; 19/10/04 04:54 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#101009 19/10/04 05:11 PM
Joined: Oct 2003
Posts: 42
V
Ameglian cow
OP Offline
Ameglian cow
V
Joined: Oct 2003
Posts: 42
Thanks starbucks_mafia and qwerty! Now I have something to work with. smile

#101010 19/10/04 11:19 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yeah that's what it is. I never knew about that, thanks.


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard