Sign in to follow this  
Followers 0

Get Icon from file

5 posts in this topic

Posted

not sure this is the right forum. but is it possible to get the image/icon from a saved file (*.dwg,*.pdf ...) , I have looked through the forum and couldn't find anything. :)

Share this post


Link to post
Share on other sites



Posted

try to search for

enumicons_v2.au3

Share this post


Link to post
Share on other sites

Posted

MSDN Reference:SHGetFileInfo

Global Const $tagSHFILEINFO = "hwnd hIcon;int iIcon;dword Attr;wchar DisplayName[260];char TypeName[80]"

Global Const $SHGFI_ICON = 256
Global Const $SHGFI_DISPLAYNAME  = 512
Global Const $SHGFI_TYPENAME = 1024
Global Const $SHGFI_ATTRIBUTES = 2048
Global Const $SHGFI_ICONLOCATION = 4096
Global Const $SHGFI_EXETYPE = 8192
Global Const $SHGFI_SYSICONINDEX = 16384
Global Const $SHGFI_LINKOVERLAY = 32768
Global Const $SHGFI_SELECTED = 65536
Global Const $SHGFI_ATTR_SPECIFIED = 131072
Global Const $SHGFI_LARGEICON = 0
Global Const $SHGFI_SMALLICON = 1
Global Const $SHGFI_OPENICON = 2
Global Const $SHGFI_SHELLICONSIZE = 4
Global Const $SHGFI_PIDL = 8
Global Const $SHGFI_USEFILEATTRIBUTES = 16

Func _SHGetFileInfo(ByRef $tFileInfo,Const $File,Const $dwAttr = 0,Const $Flags = 0)
    If NOT $tFileInfo Then
        $tFileInfo = DllStructCreate($tagSHFILEINFO)
    EndIF
    If @error Then Return SetError(1,0,$tFileInfo)

    Local $Ret = DllCall("shell32.dll","int","SHGetFileInfo","str",$File,"dword",$dwAttr, _
        "ptr",DllStructGetPtr($tFileInfo),"uint",DllStructGetSize($tFileInfo),"uint",$Flags)
    If $Ret[0] = 0 Then Return SetError(2,0,False)

    Return SetError(0,$Ret[0],$tFileInfo)
EndFunc

Share this post


Link to post
Share on other sites

Posted

nobbe thank you, but enumicons_v2.au3 only shows the icons for dll's and exe's.

danielkza thank you for the code, it looks like it will do what I need to do but I am not completely sure how to make it work. :)

Share this post


Link to post
Share on other sites

Posted

nobbe thank you, but enumicons_v2.au3 only shows the icons for dll's and exe's.

danielkza thank you for the code, it looks like it will do what I need to do but I am not completely sure how to make it work. :)

Func _ShellGetAssocIcon(Const $szFile,Const $IconFlags = 0)
    Local $tFileInfo = DllStructCreate($tagSHFILEINFO)
    If @error Then
        Return SetError(1,@extended,0)
    EndIf
    
    Local $Ret = DllCall("shell32.dll","int","SHGetFileInfo","str",$szFile,"dword",0, _
        "ptr",DllStructGetPtr($tFileInfo),"uint",DllStructGetSize($tFileInfo),"uint",BitOr($SHGFI_ICON,$IconFlags))
    MsgBox(0,0,@error)
    Return DllStructGetData($tFileInfo,"hIcon")
EndFunc

Don't forget to call _WinAPI_DestroyIcon after you're done with the icon.Check the extra flags in the MSDN page in the first post.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.