Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. File type icons

File type icons

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminjsonquestion
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #1

    Is there an API function to retrieve the icon of a particular document, or do I have to acquire it myself by scanning the registry? -- This space for rent.

    C G M 3 Replies Last reply
    0
    • J Jorgen Sigvardsson

      Is there an API function to retrieve the icon of a particular document, or do I have to acquire it myself by scanning the registry? -- This space for rent.

      C Offline
      C Offline
      ColinDavies
      wrote on last edited by
      #2

      I've looked for this in several projects I've done, and have always resorted to the registry. :-( A simple class for this would be useful to have on hand. Regardz Colin J Davies

      Sonork ID 100.9197:Colin

      You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

      J 2 Replies Last reply
      0
      • C ColinDavies

        I've looked for this in several projects I've done, and have always resorted to the registry. :-( A simple class for this would be useful to have on hand. Regardz Colin J Davies

        Sonork ID 100.9197:Colin

        You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        Colin Davies wrote: A simple class for this would be useful to have on hand. I'll submit an article about such a class, if I figure out a nice way to do it. Wish me luck! :) -- This space for rent.

        1 Reply Last reply
        0
        • C ColinDavies

          I've looked for this in several projects I've done, and have always resorted to the registry. :-( A simple class for this would be useful to have on hand. Regardz Colin J Davies

          Sonork ID 100.9197:Colin

          You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          The class will be finished by dawn, sir. ;) -- This space for rent.

          M 1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            The class will be finished by dawn, sir. ;) -- This space for rent.

            M Offline
            M Offline
            Magius96
            wrote on last edited by
            #5

            It's already dawn where I'm at, Sir. "Don't tell me I'm smart, I might actually believe you!"

            1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              Is there an API function to retrieve the icon of a particular document, or do I have to acquire it myself by scanning the registry? -- This space for rent.

              G Offline
              G Offline
              Gary R Wheeler
              wrote on last edited by
              #6

              Try using ShGetFileInfo. It works for all Win32 versions of Windows.


              Software Zen: delete this;

              J 1 Reply Last reply
              0
              • J Jorgen Sigvardsson

                Is there an API function to retrieve the icon of a particular document, or do I have to acquire it myself by scanning the registry? -- This space for rent.

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                I do it with SHGetFileInfo(), however AFAIK it doesn't restrieve the 48x48 icon, only 16x16 and 32x32. Here's how to get the icon for DLL files:

                SHFILEINFO sfi = {0};

                SHGetFileInfo ( _T("foo.dll"), FILE_ATTRIBUTE_NORMAL,
                &sfi, sizeof(SHFILEINFO),
                SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |
                SHGFI_LARGEICON );

                // now sfi.hIcon holds the 32x32 icon

                Replace SHGFI_LARGEICON with SHFGI_SMALLICON to get the 16x16 one. Note that foo.dll doesn't need to exist, the SHGFI_USEFILEATTRIBUTES flag tells the API to just look at the extension of the name you pass. --Mike-- Friday's GoogleFight results: Britney Spears 2,190,000 - Erica Weichers 23 :( 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

                J 1 Reply Last reply
                0
                • G Gary R Wheeler

                  Try using ShGetFileInfo. It works for all Win32 versions of Windows.


                  Software Zen: delete this;

                  J Offline
                  J Offline
                  Jorgen Sigvardsson
                  wrote on last edited by
                  #8

                  Argh... I just wrote an article on how to grab the data from the registry. Thanks for the info though! -- This space for rent.

                  G 1 Reply Last reply
                  0
                  • M Michael Dunn

                    I do it with SHGetFileInfo(), however AFAIK it doesn't restrieve the 48x48 icon, only 16x16 and 32x32. Here's how to get the icon for DLL files:

                    SHFILEINFO sfi = {0};

                    SHGetFileInfo ( _T("foo.dll"), FILE_ATTRIBUTE_NORMAL,
                    &sfi, sizeof(SHFILEINFO),
                    SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |
                    SHGFI_LARGEICON );

                    // now sfi.hIcon holds the 32x32 icon

                    Replace SHGFI_LARGEICON with SHFGI_SMALLICON to get the 16x16 one. Note that foo.dll doesn't need to exist, the SHGFI_USEFILEATTRIBUTES flag tells the API to just look at the extension of the name you pass. --Mike-- Friday's GoogleFight results: Britney Spears 2,190,000 - Erica Weichers 23 :( 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

                    J Offline
                    J Offline
                    Jorgen Sigvardsson
                    wrote on last edited by
                    #9

                    Argh... I just wrote an article on how to grab the data from the registry. Thanks for the info though! -- This space for rent.

                    1 Reply Last reply
                    0
                    • J Jorgen Sigvardsson

                      Argh... I just wrote an article on how to grab the data from the registry. Thanks for the info though! -- This space for rent.

                      G Offline
                      G Offline
                      Gary R Wheeler
                      wrote on last edited by
                      #10

                      Hey - Submit the article anyway. I'd like to read it. Any information on how Windows uses the registry is useful!


                      Software Zen: delete this;

                      J 1 Reply Last reply
                      0
                      • G Gary R Wheeler

                        Hey - Submit the article anyway. I'd like to read it. Any information on how Windows uses the registry is useful!


                        Software Zen: delete this;

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #11

                        Doh! I deleted it. :) I didn't want to use CP as a storage when there's already an API function for it! Here's however a simple rundown of the implementation if you're interested:

                        1. For a file extension "doc", open HKEY_CLASSES_ROOT\.doc Look at the default value. It's a part key name, for instance Word.Document.8. Also, HKEY_CLASSES_ROOT\.doc may contain information such as content type (mime) worth collecting
                        2. Assuming the key name was Word.Document.8, open HKEY_CLASSES_ROOT\Word.Document.8
                        3. Collect the data you want from here (default icon, file type descriptions, etc.)

                        I have the code lying around still if you want it. -- Only in a world this shitty could you even try to say these were innocent people and keep a straight face.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups