Jump to content

How to find the default icon of a (non exe) file


Recommended Posts

Hi,

Does anyone know how to get the default icon of a file?

I mean of a file with no embedded icon of course, more precisely for the files for which GUICtrlSetImage() returns 0

I couldn't find a function for this. Or am I wrong?

Check following topic to understand what i mean if my question is not clear enough:

http://www.autoitscript.com/forum/index.ph...st&p=623891

Thanks

GreenCan

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Link to comment
Share on other sites

hello i came across the same problem, and did it like this.

$tst=_WinAPI_ExtractIconEx($file,0,0,0,0)
                        ConsoleWrite("tst  -->"&$tst&@lf)
                        if $tst<> 0 Then 
                        $index = _GUIImageList_AddIcon($hImage, $file, 0, True)
                        _GUICtrlListView_AddItem($hListView, $str, $index)
                        Else
                        $index = _GUIImageList_AddIcon($hImage, @ScriptDir & "\icons\093_imageres.ico", 0, True)
                        _GUICtrlListView_AddItem($hListView, "No Icon! - " & $str, $index)
                        EndIf

This will not work as a script on its own, but you can get the idea from this.

Bascically test to see if icon can be extracted, if not, add your own icon.

Edited by Aceguy
Link to comment
Share on other sites

@GreenCan

Example:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$cMenu_File = GUICtrlCreateMenu("&File")

$cMenuItem_Open = GUICtrlCreateMenuItem("Open", $cMenu_File)

$cListView = GUICtrlCreateListView("Items", 10, 10, 280, 160)

$hImage = _GUIImageList_Create(16, 16, 5, 3, 1)
_GUICtrlListView_SetImageList($cListView, $hImage, 1)

GUICtrlSendMsg($cListView, $LVM_SETCOLUMNWIDTH, 0, 200)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cMenuItem_Open
            $sFile = FileOpenDialog("Select file", "", "All files (*.*)", 1, "", $hGUI)
            If Not @error Then
                $hIcon = _ExtractAssociatedIcon($hGUI, $sFile)
                $Index = _ImageList_AddIcon($hImage, $hIcon)
                _DestroyIcon($hIcon)
                _GUICtrlListView_InsertItem($cListView, $sFile, -1, $Index)
            EndIf
    EndSwitch
WEnd

Func _ExtractAssociatedIcon($hWnd, $sFile)
    Local $aRet = DllCall("shell32.dll", "hwnd", "ExtractAssociatedIcon", _
                                                 "hwnd", $hWnd, _
                                                 "str", $sFile, _
                                                 "short*", 0)
    Return $aRet[0]
EndFunc   ;==>_ExtractAssociatedIcon

Func _ImageList_AddIcon($hImage, $hIcon)
    Local $aRet = DllCall("comctl32.dll", "int", "ImageList_AddIcon", _
                                                 "hwnd", $hImage, _
                                                 "hwnd", $hIcon)
    Return $aRet[0]
EndFunc   ;==>_ImageList_AddIcon

Func _DestroyIcon($hIcon)
    Local $aRet = DllCall("user32.dll", "int", "DestroyIcon", _
                                               "hwnd", $hIcon)
    Return $aRet[0]
EndFunc   ;==>_DestroyIcon

:)

Link to comment
Share on other sites

He thanks guys,

I'll dig into the examples.

Cheers

GreenCan

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Link to comment
Share on other sites

Very nice example rasim!

Btw, perhaps you should post a Feature Request for _WinAPI_ExtractAssociatedIcon() + change the _GUIImageList_AddIcon() function so it could accept $hIcon, not only a file path, like this for example:

Func _GUIImageList_AddIcon($hWnd, $sFile, $iIndex = 0, $fLarge = False)
    Local $tIcon, $iResult, $hIcon

    $tIcon = DllStructCreate("int Handle")
    
    If FileExists($sFile) Then
        If $fLarge Then
            $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, DllStructGetPtr($tIcon), 0, 1)
        Else
            $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, 0, DllStructGetPtr($tIcon), 1)
        EndIf
        
        _WinAPI_Check("_GUIImageList_AddIcon", ($iResult <= 0), -1)
        $hIcon = DllStructGetData($tIcon, "Handle")
    Else
        $hIcon = $sFile ;Handle?
    EndIf
    
    $iResult = _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
    _WinAPI_Check("_GUIImageList_AddIcon", ($iResult = -1), -2)
    _WinAPI_DestroyIcon($hIcon)
    Return $iResult
EndFuncoÝ÷ ØêÞ½éÚuÖºw-ÛB¨.+-×HrÄÇöÚºÚ"µÍ[ÈÑÕRR[XYÙSÝÐYXÛÛ^
    ÌÍÚÛ    ÌÍÜÑ[K  ÌÍÚR[^H
BRY[Q^ÝÊ  ÌÍÜÑ[JH[BIÌÍÚTÝ[HØ[
    ][ÝÜÚ[Ì ][ÝË  ][ÝÚÛ    ][ÝË  ][ÝÑ^XÝÜÛØÚX]YXÛÛ][ÝË    ][ÝÚÛ    ][ÝË  ÌÍÚÛ    ][ÝÜÝ][ÝË  ÌÍÜÑ[K  ][ÝÜÚÜ
][ÝË
BBIÌÍÚXÛÛH ÌÍÚTÝ[ÌBQ[ÙBBIÌÍÚXÛÛH    ÌÍÜÑ[HÒ[OÂQ[YBSØØ[  ÌÍÚTÝ[HÑÕRR[XYÙSÝÔXÙRXÛÛ    ÌÍÚÛLK  ÌÍÚXÛÛBWÕÚ[TWÐÚXÚÊ   ][Ý×ÑÕRR[XYÙSÝÐYXÛÛ][ÝË
    ÌÍÚTÝ[HLJKLJBWÕÚ[TWÑÝÞRXÛÛ   ÌÍÚXÛÛBBT] ÌÍÚTÝ[[[

 

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

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...