Author Topic: Geting Icon index or handle from file extention!  (Read 5617 times)

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Geting Icon index or handle from file extention!
« on: May 30, 2012, 08:53:46 AM »
    i'm making a rar extractor and while the content of the file is still compacted i need to extract either the index or handle of the icon that corresponds to the extention. I'm not aware of any function that could do so. I tried ExtracAssociatedIconEx and ExtractIcon with 0 for module Instance but didn't work. Can it be done via registry. Does anybody have any idea? Thanks in advance.
    Laters
    X

Gunner

  • Regular Member
  • *
  • Posts: 48
    • Gunners Software
Re: Geting Icon index or handle from file extention!
« Reply #1 on: May 30, 2012, 09:17:16 AM »
Stay OUT of the Registry.  Use SHGetFileInfo

Something like this should work:
Code: [Select]
    invoke  SHGetFileInfo, offset szExtension, NULL, offset sfi, sizeof SHFILEINFO, SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON
    invoke  ImageList_AddIcon, himlTabs, sfi.hIcon
    invoke  DestroyIcon, sfi.hIcon
this will fill in the icon index in the system imagelist sfi.iIcon and the handle of the icon sfi.hIcon
~Rob

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #2 on: May 30, 2012, 09:20:02 AM »
   yea? but does it work with just the extention? what's the format?
Code: [Select]
*.rar...cause i tried that and didnt work.
   thanks gunner i appreciate the help. I'm waittin.
   soon

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #3 on: May 30, 2012, 09:23:32 AM »
  oh yeah gunner. after reading the sdk i understood. thanks gunna.
  later and regards
  x

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #4 on: May 30, 2012, 11:19:03 PM »
   Couldn't get it to work... does anyone know what's the extention fomat? Is it '*.ext',0 or what?

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Geting Icon index or handle from file extention!
« Reply #5 on: May 31, 2012, 12:01:29 AM »
try passing a "fictional" filename. like 'x.rar',0

also - set the SHFILEINFO dwAttributes member to FILE_ATTRIBUTE_NORMAL before the call

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #6 on: May 31, 2012, 12:14:49 AM »
    thanks dave. will do so... i'll let you know how it went.

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #7 on: May 31, 2012, 12:29:56 AM »
   Not working.... even tried FILE_ATTR_COMPRESSED and both and none.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Geting Icon index or handle from file extention!
« Reply #8 on: May 31, 2012, 12:31:55 AM »
alright - let me play with it...

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #9 on: May 31, 2012, 12:41:50 AM »
   wait....it works.... it was an listview problem.... forgot to xor imask,LVIF_IMAGE+PARAM that's all. Sorry.... i always miss something stupid. Thanks dave and gunner

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Geting Icon index or handle from file extention!
« Reply #10 on: May 31, 2012, 12:45:09 AM »
yah - my mistake, too
you set the file attribute in the parm - not in the struct...
Code: [Select]
        INVOKE  SHGetFileInfo,offset szExtension,FILE_ATTRIBUTE_NORMAL,offset shfi,sizeof SHFILEINFO,
                SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON

also - it appears that '.rar',0 will work for an extension format

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #11 on: May 31, 2012, 12:53:07 AM »
    oks.... althought i read here...http://blogs.msdn.com/b/oldnewthing/archive/2004/06/01/145428.aspx
    thx dave. i appreciate it.... i'm coming close to about 2000 lines of code devided be several source files. I feel tired. I'll prolly drop once i get bored as i do with everything else....lol. bb

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Geting Icon index or handle from file extention!
« Reply #12 on: May 31, 2012, 02:08:00 AM »
yah - i saw that article
but - you may also want to read the community content at the bottom...
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179%28v=vs.85%29.aspx

xandaz

  • Member
  • **
  • Posts: 91
  • I luv you babe
Re: Geting Icon index or handle from file extention!
« Reply #13 on: May 31, 2012, 02:27:04 AM »
   thx. dave. will do.