Jump to content
Sign in to follow this  
Noobster24

Get icon from every filetype

Recommended Posts

Noobster24

Hi,

when you explore your computer with Windows Explorer, you'll notice that almost every file (with a certain filetype) has is icon.

Now my problem:

I have a $listview, I use a combination of For and _FileListToArray() to ouput the files and directories in a certain directory / on a certain drive. I use GuiCtrlSetImage() to put an image in the listview, but this doesn't show me an image file of that file:

GUICtrlSetImage (-1, $location & $filearray[$i]) ;for instance d:\games\myblablafile.php

How can I put the icon of every filetype in the listview? (If it's a .doc-file show the M$ Word icon, if it's Adobe Photoshop 2, show that icon etc.)

Anyone got an idea?

I added a screen to clear things up..

post-11488-1189451173_thumb.jpg

Edited by Noobster24

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.

Share this post


Link to post
Share on other sites
Noobster24

This is better:

GUICtrlSetImage (-1, "D:\games\call of duty 2\cod2_mp.exe", 1)
Hi thanks for the reply, but my explanation sucked. Take a lot at the screenshot in my first post.

It shows the icons of certain files (like bmp & exe), but no icons of .cfg or .php etc. (But in Windows Explorer it does..)

Something like this:

http://www.pocketpcdn.com/articles/systemimages.html

but then so than I can use it in Autoit.

Edited by Noobster24

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.

Share this post


Link to post
Share on other sites
JRSmile

is there any update on that thread, need this functionality too.


$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites
DirtDBaK

ha i would like to know how to do this as well i want to implement it into a media player i'm working on....

i know you wonder why/how but i know what my plans r...


[center][/center]

Share this post


Link to post
Share on other sites
MrCreatoR

Hi,

Check this example (the functions _FileGetType() and _FileGetIcon isn't mine (sorry, but i can't remember ho's), i just change them a litle):

#include <GUIConstants.au3>

$FileFolderFullPath = @ScriptFullPath

GUICreate("Get File/Folder Type & Icon", 300, 150)

$GetIcoArr = _FileGetIcon($FileFolderFullPath)

GUICtrlCreateButton("", 130, 50, 32, 32, $BS_ICON)
GUICtrlSetImage(-1, $GetIcoArr[1], $GetIcoArr[2], 0)

GUICtrlCreateLabel(_FileGetType($FileFolderFullPath), 75, 90, 140, 20, $SS_CENTER)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then Exit
WEnd

Func _FileGetType($FilePathOrExt)
    Local $Old_Opt_EES = Opt("ExpandEnvStrings", 1)
    Local $RegDefault, $RegType="", $Ext
    If _IsFolder($FilePathOrExt) Then
        $RegDefault = RegRead("HKCR\Folder", "")
        If $RegDefault <> "" Then $RegType = $RegDefault
    Else
        $Ext = StringRegExpReplace($FilePathOrExt, '^.*\.', '.')
        If $Ext = $FilePathOrExt Then
            $ExtSaerch = FileFindFirstFile($FilePathOrExt & ".*")
            $Ext = StringRegExpReplace(FileFindNextFile($ExtSaerch), '^.*\.', '.')
            $FilePathOrExt &= $Ext
        EndIf
        $RegDefault = RegRead("HKCR\" & $Ext, "")
        If $RegDefault <> "" Then $RegType = RegRead("HKCR\" & $RegDefault, "")
        If $RegType = "" Then $RegType = $Ext & "-File"
    EndIf
    Opt("ExpandEnvStrings", $Old_Opt_EES)
    Return $RegType
EndFunc

Func _FileGetIcon($szFile)
    Local $Old_Opt_EES = Opt("ExpandEnvStrings", 1)
    Local $szRegDefault = "", $szDefIcon = "", $szExt, $szIconFile, $nIcon=0
    Local $RetArr[3]
    
    If _IsFolder($szFile) Then
        $szRegDefault = RegRead("HKCR\Folder", "")
        If $szRegDefault <> "" Then $szDefIcon = RegRead("HKCR\Folder\DefaultIcon", "")
    Else
        $szExt = StringRegExpReplace($szFile, '^.*\.', '.')
        
        If $szExt = ".lnk" Then
            Local $LnkInfoArr = FileGetShortcut($szFile)
            If Not @error Then
                Local $RetArr[3] = [2, $LnkInfoArr[4], $LnkInfoArr[5]]
                Return $RetArr
            EndIf
        EndIf
        
        If $szExt = $szFile Then
            $szExt = FileFindFirstFile($szFile & ".*")
            $szExt = StringRegExpReplace(FileFindNextFile($szExt), '^.*\.', '.')
            $szFile &= $szExt
        EndIf
        $szRegDefault = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $szExt, "ProgID")
        If $szRegDefault = "" Then $szRegDefault = RegRead("HKCR\" & $szExt, "")
        If $szRegDefault <> "" Then $szDefIcon = RegRead("HKCR\" & $szRegDefault & "\DefaultIcon", "")
    EndIf
    If $szDefIcon = "" Then
        $szIconFile = "shell32.dll"
    ElseIf $szDefIcon <> "%1" Then
        If StringRegExpReplace($szFile, "^.*\\", "") = "shell32.dll" Then
            $szIconFile = $szFile
            $nIcon = 0
        Else
            $arSplit = StringSplit($szDefIcon, ",")
            If IsArray($arSplit) Then
                $szIconFile = $arSplit[1]
                If $arSplit[0] > 1 Then $nIcon = $arSplit[2]
            Else
                Opt("ExpandEnvStrings", $Old_Opt_EES)
                Return SetError(1, 0, $RetArr)
            EndIf
        EndIf
    ElseIf $szDefIcon = "%1" Then
        $szIconFile = $szFile
        $nIcon = 0
    EndIf
    Opt("ExpandEnvStrings", $Old_Opt_EES)
    Local $RetArr[3] = [2, $szIconFile, $nIcon]
    Return $RetArr
EndFunc

Func _IsFolder($name)
    Return StringInStr(FileGetAttrib($name), "D")
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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  

×