Javik

Reading icons correctly from shortcuts / docs / programs?

6 posts in this topic

#1 ·  Posted (edited)

Is there a particular way to look for the appropriate icon to display in shortcuts, documents, and programs?

I see that shortcuts can contain icons and an icon index number, but the few shortcuts I have been examining have neither.

Is it possible for a shortcut to have an index number only, and no internal icon? If yes then I would assume the index number would refer to the icon list in the executable rather than in the shortcut.

I am trying to determine the proper way to order the code for icon hunting.

Pseudocode:

$Index = null
$Icon = null
$Exepath = null
Get $target file path
;
If $target ends in ".lnk" then  ;it's a shortcut
  Get $Exepath to executable
  ;
  Get $Index from $target  ;(if any)
  If $Index = null then get $Index from $Exepath  ;(if any)
  If $Index = null then $Index = 1
  ;
  Get $Icon at $index in $target  ;(if any) 
  If $Icon = null then get $Icon from $Exepath  ;(if any)
  If $Icon = null then get $Icon from ?  ;(moreicon.dll ?)
  ;
Else if $target ends in ".exe" then  ;it's an executable
    Get $Index from $target  ;(if any)
    If $Index = null then $Index = 1
    ;
    Get $Icon at $index from $target  ;(if any)
    If $Icon = null then get $Icon from ?  ;(moreicon.dll ?)
  Else  ;(not .lnk or .exe so it's a document)
    ;Do something here for docs, dunno what yet
  Endif
Endif
Edited by Javik

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is there a particular way to look for the appropriate icon to display in shortcuts, documents, and programs?

I see that shortcuts can contain icons and an icon index number, but the few shortcuts I have been examining have neither.

Is it possible for a shortcut to have an index number only, and no internal icon? If yes then I would assume the index number would refer to the icon list in the executable rather than in the shortcut.

I am trying to determine the proper way to order the code for icon hunting.

Pseudocode:

$Index = null
$Icon = null
$Exepath = null
Get $target file path
;
If $target ends in ".lnk" then  ;it's a shortcut
  Get $Exepath to executable
  ;
  Get $Index from $target  ;(if any)
  If $Index = null then get $Index from $Exepath  ;(if any)
  If $Index = null then $Index = 1
  ;
  Get $Icon at $index in $target  ;(if any) 
  If $Icon = null then get $Icon from $Exepath  ;(if any)
  If $Icon = null then get $Icon from ?  ;(moreicon.dll ?)
  ;
Else if $target ends in ".exe" then  ;it's an executable
    Get $Index from $target  ;(if any)
    If $Index = null then $Index = 1
    ;
    Get $Icon at $index from $target  ;(if any)
    If $Icon = null then get $Icon from ?  ;(moreicon.dll ?)
  Else  ;(not .lnk or .exe so it's a document)
    ;Do something here for docs, dunno what yet
  Endif
Endif

What?

I don't exactly get what you're trying to do.

Are you trying to extract an Icon? or display it in a gui control?

Or do you just want to enumerate to files resource data?

Is the resource data you want information on of type "groupicon"?

Edited by System238

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

What?

I don't exactly get what you're trying to do.

Are you trying to extract an Icon? or display it in a gui control?

Aren't these two tasks related? I am new at dealing with icons.

I "just" want to get a list of files/folders from a target path, and display the appropriate icons for each file in a custom app launcher GUI, as they would appear in Windows Explorer, with small/large icon views being possible.

Looks pretty hard to do this though. I'm still poking around at the help files.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Aren't these two tasks related? I am new at dealing with icons.

I "just" want to get a list of files/folders from a target path, and display the appropriate icons for each file in a custom app launcher GUI, as they would appear in Windows Explorer, with small/large icon views being possible.

Looks pretty hard to do this though. I'm still poking around at the help files.

I see what you mean, and yeah, they are sort of related.

If its something as simple as a gui that launches runs an application etc, you should look in example scripts.

Search for something like "App launcher". I've come across some pretty cool gui's that accept drag n drops and when you drop a file to the gui, you get the files icons.

I just searched my script vault and I seem to have misplaced a script that sounds exactly like what you wanted.. bummer...

Edit: here seem's to be an alternative, you should scroll through the script in this and take what you need from there.

Edited by System238

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Look into GUICtrlSetImage and FileGetShortcut.

#include<File.au3>

Opt('GUIOnEventMode', 1)

Global $aFileArray, $sFolder = @DesktopDir & '\' ;Folder to browse.
Global $hGui, $hList, $hListItems[1] = [1], $sDocsIcon

;Find WinWord.exe, should work for 2003 and 2007 on x32 or x64.
$aOfficeVersion = StringSplit('C:\Program Files\Microsoft Office\Office11\WinWord.exe|C:\Program Files (x86)\Microsoft Office\Office11\WinWord.exe|C:\Program Files\Microsoft Office\Office12\WinWord.exe|C:\Program Files (x86)\Microsoft Office\Office12\WinWord.exe', '|')
For $i = 1 To $aOfficeVersion[0]
    If FileExists($aOfficeVersion[$i]) Then
        $sDocsIcon = $aOfficeVersion[$i]
        ConsoleWrite('Found Word - ' & $sDocsIcon & @CRLF)
        ExitLoop
    EndIf
Next

If $sDocsIcon = '' Then MsgBox(48, 'Error', 'Failed to find Word.')

$hGui = GUICreate('Custom Explorer', 420, 420)
GUISetOnEvent(-3, '_Exit')
GUISetBkColor(0x515151)

$hList = GUICtrlCreateListView('Files', 10, 10, 400, 400, 0x0000)

$hContextMenu = GUICtrlCreateContextMenu($hList)

GUICtrlCreateMenuItem('Open', $hContextMenu)
GUICtrlSetOnEvent(-3, '_Open')

GUICtrlCreateMenuItem('Open with Notepad', $hContextMenu)
GUICtrlSetOnEvent(-3, '_OpenWithNotepad')


$aFileArray = _FileListToArray($sFolder)
For $i = 1 To $aFileArray[0]
    $hListItems[0] += 1
    ReDim $hListItems[$hListItems[0]]
    $hListItems[$hListItems[0] - 1] = GUICtrlCreateListViewItem($aFileArray[$i], $hList)
    If StringInStr($aFileArray[$i], '.lnk', 2) Then ;If shortcut.
        $Icon = FileGetShortcut($sFolder & $aFileArray[$i])
        If Not @error Then GUICtrlSetImage($hListItems[$hListItems[0] - 1], $Icon[0], $Icon[5])
    ElseIf StringInStr($aFileArray[$i], '.doc', 2) Or StringInStr($aFileArray[$i], '.txt', 2) Then ;If .doc or .txt.
        GUICtrlSetImage($hListItems[$hListItems[0] - 1], $sDocsIcon)
    Else ;If .exe or other file type.
        ;If failed to get an icon then delete.
        If GUICtrlSetImage($hListItems[$hListItems[0] - 1], $sFolder & $aFileArray[$i]) = 0 Then GUICtrlDelete($hListItems[$hListItems[0] - 1])
    EndIf
Next

GUISetState()

ControlClick('Custom Explorer', '', 'SysHeader321', 'Primary', 2, 45, 10) ;Resize List.

While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Open()
    $Active = StringTrimRight(GUICtrlRead(GUICtrlRead($hList)), 1)
    ShellExecute($sFolder & $Active)
EndFunc   ;==>_Open

Func _OpenWithNotepad()
    $Active = StringTrimRight(GUICtrlRead(GUICtrlRead($hList)), 1)
    ShellExecute(@SystemDir & '\notepad.exe', $sFolder & $Active)
EndFunc   ;==>_OpenWithNotepad
Edited by BitByteBit

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Translated by Google. Sorry for any mistakes.
I made here a post showing a new application for when I find files of type lnk that slavou my life and I hope it helps others

 

Edited by odaylton

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