Results 1 to 12 of 12

Thread: retreiving icon associated with a file type without using SHGetFileInfo?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    retreiving icon associated with a file type without using SHGetFileInfo?

    I only know how to do it useing the SHGetFileInfo() API. But that function needs an actual file to exist. I'm wondering if there is a way to get the icon associated with a file without using SHGetFileInfo()???
    I know I could create a dummy file and then use it to call SHGetFileInfo() but I rather not do that if there's another way
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    Have a look at HKEY_CLASSES_ROOT hive, and notice that each extension is listed there. If you open up a key, look at the (default) value for it.

    I'm looking at ".bmp" and the default value for it is "Paint.Picture"

    Now in the same hive (HKEY_CLASSES_ROOT) look up "Paint.Picture"

    There is a subfolder called "DefaultIcon." The (default) value of this folder will tell you the module name, and icon index, separated by a comma. From here, just call ExtractIcon() on that module, specifying that specfic index.

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    aaaaaaah many thanks sounds cool. Umm would you recommend this method though? just curious
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    You're welcome

    And, I see no harm in using it. Beats creating a temp file, anyway.

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    If you use SHGetFileInfo you can use the SHGFI_USEFILEATTRIBUTES attribute if the file doesn't exist.
    This way you can extract an icon just be using "*.jpg" as filename.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    aah even more interesting I'll take a look at that....
    I'm guessnig that's a constant I need to pass as the dwFileAttribute parameter?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    True.

    VB Code:
    1. Private Const SHGFI_USEFILEATTRIBUTES As Integer = &H10
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  8. #8
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    There is a complete class for this in the codebank. Pretty cool.

    http://vbforums.com/showthread.php?t=330983
    Last edited by wossname; Jun 2nd, 2005 at 03:35 AM.
    I don't live here any more.

  9. #9
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    Quote Originally Posted by MrPolite
    aah even more interesting I'll take a look at that....
    I'm guessnig that's a constant I need to pass as the dwFileAttribute parameter?
    Since I'm feeling generous today, I'll give you the source code for an ActiveX dll I'm using in a program to populate a image list control with file extension icons. It's made in VB6.
    Attached Files Attached Files

  10. #10
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    Quote Originally Posted by kaffenils
    It's made in VB6.
    This is the VB.Net forum though. Thanks all the same I'm sure its lovely.
    I don't live here any more.

  11. #11
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    Quote Originally Posted by wossname
    This is the VB.Net forum though. Thanks all the same I'm sure its lovely.
    Yes I know it's vb.net, but it should be easy to convert from vb6 to .net

  12. #12

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: retreiving icon associated with a file type without using SHGetFileInfo?

    naah I dont want vb6 stuff not even vb.net.... I'm writing in C#. I just ask here cuz I get more responses
    I still havent started workign on this part of my app, but will do soon. I like what pax said, and if that didnt work then I'll look at megatran's, and then maybe wossname's

    Kaffenils thanks for the reply though, I'll give you a positive feedback as soon as VBF lets me rate people again
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width