Jump to content

Find default icon and application for filetype


Recommended Posts

My projekt is an simply WinPE enviroment with some copy processes.

The assigment between file and application do not work like Windows Explorer.

I have read all ideas to resolve the problem such as SH**, **Extract** but no one resolved my problem.

Can anybody help me to show the right icon for file?

In most of all cases it works but not in all.

XXCopy is an xcopy with Gui. Override is an include. Start it from DOS shell.

AutoIt Version v3.3.4.0

XXCopy.au3

Override.au3

Link to comment
Share on other sites

The assigment between file and application do not work like Windows Explorer.

I have read all ideas to resolve the problem such as SH**, **Extract** but no one resolved my problem.

Can anybody help me to show the right icon for file?

At first glance I didn't find the spot in your code, where you try to show file icons (and honestly, I don't have the time to look more intensively). However, the easiest way to achieve this would be:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Global Const $SS_REALSIZEIMAGE    = 0x00000800
Global Const $SS_ENDELLIPSIS      = 0x00004000
Global Const $SS_PATHELLIPSIS     = 0x00008000
Global Const $SS_WORDELLIPSIS     = 0x0000C000
Global Const $SS_ELLIPSISMASK     = 0x0000C000

Global Const $STM_SETIMAGE  = 0x0172
Global Const $STM_GETIMAGE  = 0x0173
Global Const $SHGFI_ICON              = 0x00000100     ; get icon
Global Const $SHGFI_DISPLAYNAME       = 0x00000200     ; get display name
Global Const $SHGFI_TYPENAME          = 0x00000400     ; get type name
Global Const $SHGFI_ATTRIBUTES        = 0x00000800     ; get attributes
Global Const $SHGFI_ICONLOCATION      = 0x00001000     ; get icon location
Global Const $SHGFI_EXETYPE           = 0x00002000     ; return exe type
Global Const $SHGFI_SYSICONINDEX      = 0x00004000     ; get system icon index
Global Const $SHGFI_LINKOVERLAY       = 0x00008000     ; put a link overlay on icon
Global Const $SHGFI_SELECTED          = 0x00010000     ; show icon in selected state
Global Const $SHGFI_ATTR_SPECIFIED    = 0x00020000     ; get only specified attributes
Global Const $SHGFI_LARGEICON         = 0x00000000     ; get large icon
Global Const $SHGFI_SMALLICON         = 0x00000001     ; get small icon
Global Const $SHGFI_OPENICON          = 0x00000002     ; get open icon
Global Const $SHGFI_SHELLICONSIZE     = 0x00000004     ; get shell size icon
Global Const $SHGFI_PIDL              = 0x00000008     ; pszPath is a pidl
Global Const $SHGFI_USEFILEATTRIBUTES = 0x00000010     ; use passed dwFileAttribute
Global Const $SHGFI_ADDOVERLAYS       = 0x00000020     ; apply the appropriate overlays
Global Const $SHGFI_OVERLAYINDEX      = 0x00000040     ; Get the index of the overlay in the upper 8 bits of the iIcon

Global Const $_SFI_HICON            = 0
Global Const $_SFI_IICON            = 1
Global Const $_SFI_DWATTRIBUTES     = 2
Global Const $_SFI_SZDISPLAYNAME    = 3
Global Const $_SFI_SZTYPENAME       = 4
Global Const $_SFI_MAX              = 5

Global Const $tagSHFILEINFO     = 'ptr hIcon;' & _
                                  'int iIcon;' & _
                                  'dword dwAttributes;' & _
                                  'wchar szDisplayName[260];' & _
                                  'wchar szTypeName[80]'

GUICreate("Icon", 100, 100, (@DesktopWidth - 100) / 2, (@DesktopHeight - 100) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CAPTION))
Global $ico = GUICtrlCreateIcon("", -1, 34, 34, 32, 32, BitOR($SS_ICON,$SS_NOTIFY,$SS_REALSIZEIMAGE,$WS_GROUP,$WS_VISIBLE,$WS_CHILD))

ShowIcon("C:\WINDOWS\explorer.exe")

GUISetState()       ;Show GUI
While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    
WEnd

GUIDelete()

Func ShowIcon($path)
    Local $f = BitOr($SHGFI_TYPENAME, $SHGFI_DISPLAYNAME, $SHGFI_ICON, $SHGFI_LARGEICON)
    If Not FileExists($path) Then $f = BitOR($f, $SHGFI_USEFILEATTRIBUTES)
    Local $sfi[5] = [0, 0, 0, "", ""]
    Local $hIml = _ShellAPI_SHGetFileInfo($path, $sfi, $f)
    If $hIml And $sfi[$_SFI_HICON] Then
        GUICtrlSendMsg($ico, $STM_SETIMAGE, $IMAGE_ICON, $sfi[$_SFI_HICON])
    EndIf
EndFunc


Func _ShellAPI_SHGetFileInfo($pszPath, ByRef $infoArray, $uFlags, $dwFileAttributes = $FILE_ATTRIBUTE_NORMAL)
    Local $sfi = DllStructCreate($tagSHFILEINFO)
    Local $result = DllCall( "shell32.dll", "ulong_ptr", "SHGetFileInfoW", _
                             "wstr", $pszPath, "dword", $dwFileAttributes, _
                             "ptr", DllStructGetPtr($sfi), "uint", DllStructGetSize($sfi), _ 
                             "uint", $uFlags )
    If @error Then
        SetError(@error, 0, 0)
    Else
        If $_SFI_MAX > UBound($infoArray) Then ReDim $infoArray[$_SFI_MAX]
        $infoArray[$_SFI_HICON] = DllStructGetData($sfi, "hIcon")
        $infoArray[$_SFI_IICON] = DllStructGetData($sfi, "iIcon")
        $infoArray[$_SFI_DWATTRIBUTES] = DllStructGetData($sfi, "dwAttributes")
        $infoArray[$_SFI_SZDISPLAYNAME] = DllStructGetData($sfi, "szDisplayName")
        $infoArray[$_SFI_SZTYPENAME] = DllStructGetData($sfi, "szTypeName")
    EndIf
    $sfi = 0
    Return $result[0]
EndFunc

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
Share on other sites

Thanks very much Spammer.

You are welcome. Call me doudou. :blink:

Very funny Newbie.

He is, truly. But it is funny, dear "The summer-heat is melting me brains".

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...