Jump to content

getting icon form file


Recommended Posts

What I need to do is, after you select the file, make an icon controll. I need it to be the icon of the selected file, or the program that opens the select file. What is the best way to do this?

GUICreate("123",100,100)
$file = FileOpenDialog("select file","","all files (*.*)")
GUICtrlCreateIcon()

while 1
    sleep(100)
wend

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Rough example of one way to do it. :D I seem to remember another way though... :D

#include <GUIConstantsEx.au3>
;Create GUI
GUICreate(" My GUI Icons", 250, 250)

;Get File
$file = FileOpenDialog("", "", "All Files (*.*)")

;Find Ext
$Ext = StringRegExpReplace($file, "^.*\.", ".$1")

;Read the icon place
$iconplace = RegRead("HKCR\" & $Ext, "")

;Test if icon place exists
If $iconplace Then
;Get icon string format is PATH,ORD
    $icon = RegRead("HKCR\" & $iconplace & "\DefaultIcon", "")
Else
;Get icon string format is PATH,ORD
    $icon = RegRead("HKCR\" & $Ext & "\DefaultIcon", "")
EndIf

MsgBox (0, "", $icon)

;Split string
$split = StringSplit($icon, ",")

;Icon path, replace "
$icon_file = StringReplace ($split[1], '"', '')

;If string contains %SYSTEMROOT% Then we must tell AutoIt to handle it.
If StringInStr ($icon_file, "%") Then
;Save the value so we can set it back
    $old_ExpandEnvStrings = Opt ("ExpandEnvStrings", 1)
EndIf

;Icon
$icon_ord = $split[2]

;Set Icon
$icon = GUICtrlCreateIcon($icon_file, 0 - $icon_ord, 20, 20)

;Set it back
Opt ("ExpandEnvStrings", $old_ExpandEnvStrings)

;Show GUI
GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd
Link to comment
Share on other sites

Rough example of one way to do it. :D I seem to remember another way though... :D

#include <GUIConstantsEx.au3>
;Create GUI
GUICreate(" My GUI Icons", 250, 250)

;Get File
$file = FileOpenDialog("", "", "All Files (*.*)")

;Find Ext
$Ext = StringRegExpReplace($file, "^.*\.", ".$1")

;Read the icon place
$iconplace = RegRead("HKCR\" & $Ext, "")

;Test if icon place exists
If $iconplace Then
;Get icon string format is PATH,ORD
    $icon = RegRead("HKCR\" & $iconplace & "\DefaultIcon", "")
Else
;Get icon string format is PATH,ORD
    $icon = RegRead("HKCR\" & $Ext & "\DefaultIcon", "")
EndIf

MsgBox (0, "", $icon)

;Split string
$split = StringSplit($icon, ",")

;Icon path, replace "
$icon_file = StringReplace ($split[1], '"', '')

;If string contains %SYSTEMROOT% Then we must tell AutoIt to handle it.
If StringInStr ($icon_file, "%") Then
;Save the value so we can set it back
    $old_ExpandEnvStrings = Opt ("ExpandEnvStrings", 1)
EndIf

;Icon
$icon_ord = $split[2]

;Set Icon
$icon = GUICtrlCreateIcon($icon_file, 0 - $icon_ord, 20, 20)

;Set it back
Opt ("ExpandEnvStrings", $old_ExpandEnvStrings)

;Show GUI
GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd
;Find Ext

$Ext = StringRegExpReplace($file, "^.*\.", ".$1")

??????

;Find Ext
$Ext = StringRegExpReplace($file, "^.*(\..+)$", "$1")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I also get %1 useing this:

Func _GetIcon($file, $ReturnType = 0)
    $FileType = StringSplit($file, ".")
    $FileType = $FileType[UBound($FileType) - 1]
    $FileParam = RegRead("HKEY_CLASSES_ROOT\." & $FileType, "")
    $DefaultIcon = RegRead("HKEY_CLASSES_ROOT\" & $FileParam & "\DefaultIcon", "")
    
    If Not @error Then
        $IconSplit = StringSplit($DefaultIcon, ",")
        ReDim $IconSplit[3]
        $Iconfile = $IconSplit[1]
        $IconID = $IconSplit[2]
    Else
        $Iconfile = @SystemDir & "\shell32.dll"
        $IconID = -219
    EndIf
    
    If $ReturnType = 0 Then
        Return $Iconfile
    Else
        Return $IconID
    EndIf
EndFunc  ;==>_GetIcon

how do i fix this so the returned value can be used with guictrlcreateicon()?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

It should be:

$AutoItIconIndex = -($IconID+1)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I haven't examined this script yet, but it works. Take a look at how this script works.

My previous script was from there. try opening exe's or other files (like .RAR archives). I need one that will always work.

WOW. This will work perfectly. All I need now is getting the icon of an exe. Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Sorry. I didn't look into the script, I just had the program so I posted it. I did find out that .exe files wont work.

Thats the odd thing about that script. Sometimes they do, sometimes they don't.

Could you take the part out that gets the icon and put it in a standalone example? I couldnt find what part it was. Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Maybe...

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

GUICreate("My GUI") ; will create a dialog box that when displayed is centered
GUICtrlCreateButton("my picture button", 10, 20, 40, 40, $BS_ICON)
GUICtrlSetImage(-1, @WindowsDir & "\notepad.exe", "", 1)
GUISetState()

While GUIGetMsg() <> -3
WEnd

8)

Found problem. I am useing guictrlcreateicon()

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

GUICreate("My GUI"); will create a dialog box that when displayed is centered
;$icon = GUICtrlCreateButton("my picture button", 10, 20, 40, 40, $BS_ICON)
$icon = GUICtrlCreateIcon("","", 1, 2)
$file = FileOpenDialog("123",@DesktopDir,"all files(*.*)")
GUICtrlSetImage($icon, $file , "", 1)
GUISetState()

While GUIGetMsg() <> -3
WEnd

Works fine with button, but doesnt work with icon

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Did you look at the example in help??

I just added notepad...... thats all!!

GUICreate(" My GUI Icons", 250, 250)

$icon = GUICtrlCreateIcon("shell32.dll", 10, 20, 20)
$n1 = GUICtrlCreateIcon(@WindowsDir & "\cursors\horse.ani", -1, 20, 40, 32, 32)
$n2 = GUICtrlCreateIcon("shell32.dll", 7, 20, 75, 32, 32)
$n2 = GUICtrlCreateIcon(@WindowsDir & "\notepad.exe", -1, 20, 115, 32, 32)
GUISetState()

While GUIGetMsg() <> -3
WEnd

8)

NEWHeader1.png

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