Sign in to follow this  
Followers 0

set icon

17 posts in this topic

Posted

Hello, to sei the gui icon i succesfully used this:

GUISetIcon("myicon.ico")

but i could not find the code to set the file icon, the icon u see in explorer

Share this post


Link to post
Share on other sites



Posted

huh? <_<

From examples:

;===============================================================================
;
; Description:      Show all icons in the given file
; Requirement(s):   Autoit 3.2.5+ and Dllcallback.au3 UDF
; Author(s):        YDY (Lazycat)
; Version:          2.0
; Date:             02.08.2007
;
;===============================================================================
#include <GUIConstants.au3>
#include "DllCallBack.au3"

; Setting variables
Global $BTN_STYLE = BitOR($BS_CHECKBOX, $BS_PUSHLIKE, $BS_FLAT)
Global $ahIcons[30], $ahLabels[30]
Global $iStartIndex = 1, $iCntRow, $iCntCol, $iCurIndex
Global $glFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"
Global $bOrdinal = true
Global $glNames[1]
Global $hSelected

; Creating GUI and controls
$hGui=GUICreate("Icon Selector by Ordinal value", 385, 435, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateGroup("", 5, 1, 375, 40)
GUICtrlCreateGroup("", 5, 50, 375, 380)
$hFile = GUICtrlCreateInput($glFilename, 12,  15, 325, 16, -1, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetTip(-1, "You can drop files from shell here...")
$hStatus = GUICtrlCreateInput("", 155, 49, 125, 16, $ES_READONLY, $WS_EX_STATICEDGE)
$hFileSel = GUICtrlCreateButton("...", 345,  14, 26, 18)
$hPrev = GUICtrlCreateButton("Previous", 10,  45, 60, 24, $BTN_STYLE)
GUICtrlSetState(-1, $GUI_DISABLE)
$hNext = GUICtrlCreateButton("Next", 75,  45, 60, 24, $BTN_STYLE)
$hToggle = GUICtrlCreateButton("by Name", 300,  45, 60, 24, $BTN_STYLE)
$hOverlay = GUICtrlCreateLabel("", -99, -99 , 60, 62, $SS_GRAYFRAME)
$hContext = GUICtrlCreateContextMenu($hOverlay)
$hCopyIndex = GUICtrlCreateMenuItem("Copy Ordinal Value", $hContext)
$hCopyName = GUICtrlCreateMenuItem("Copy Resource Name", $hContext)

; This code build two arrays of ID's of icons and labels for easily update
For $iCntRow = 0 to 4
    For $iCntCol = 0 to 5
        $iCurIndex = $iCntRow * 6 + $iCntCol
        $ahIcons[$iCurIndex]  = GUICtrlCreateIcon($glFilename, 0, 60 * $iCntCol + 25, 70 * $iCntRow + 80)
        $ahLabels[$iCurIndex] = GUICtrlCreateLabel("", 60 * $iCntCol+12, 70 * $iCntRow + 115, 58, 20, $SS_CENTER)
    Next
Next

_NewFileLoad($glFilename)
_GUIUpdate()

GUISetState()

While 1
    $aInfo = GUIGetCursorInfo()
    If IsArray($aInfo) Then
        If ($aInfo[4] >= $ahIcons[0] and $aInfo[4] <= $ahLabels[29]) Then
            If $hSelected = $aInfo[4] Then ContinueLoop
            $pos = ControlGetPos($hGUI, "", $aInfo[4])
            If $pos[2] = 58 Then ; Label
                GuiCtrlSetPos($hOverlay, $pos[0] - 1, $pos[1] + $pos[3] - 60)
            Else ; Icon
                GuiCtrlSetPos($hOverlay, $pos[0] - 14, $pos[1] - 5)
            EndIf
            $hSelected = $aInfo[4]
        EndIf
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $hCopyName, $hCopyIndex
            For $i = 0 To 29
                If ($ahIcons[$i] = $hSelected or $ahLabels[$i] = $hSelected) and ($i + $iStartIndex <= $glNames[0]) Then
                    If $nMsg = $hCopyName Then
                        ClipPut($glNames[$i + $iStartIndex])
                    Else
                        ClipPut(-($i + $iStartIndex))
                    EndIf
                EndIf
            Next
        Case $GUI_EVENT_DROPPED
            $glFileName = @GUI_DragFile
            GUICtrlSetData($hFile, $glFileName)
            _NewFileLoad($glFileName)
            _GUIUpdate()
        Case $hFileSel
            $sTmpFile = FileOpenDialog("Select file:", GUICtrlRead($hFile), "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
            If @error Then ContinueLoop
            $glFileName = $sTmpFile
            GUICtrlSetData($hFile, $glFileName)
            _NewFileLoad($glFileName)
            _GUIUpdate()
        Case $hPrev
            $iStartIndex = $iStartIndex - 30
            _GUIUpdate()
        Case $hNext
            $iStartIndex = $iStartIndex + 30
            _GUIUpdate()
        Case $hToggle
            $bOrdinal = not $bOrdinal
            _SetMode()
            _GUIUpdate()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Wend

; Updates GUI icons, labels and state of navigate buttons
Func _GUIUpdate()
    For $iCntRow = 0 to 4
        For $iCntCol = 0 to 5
            $iCurIndex = $iCntRow * 6 + $iCntCol
            If ($iCurIndex + $iStartIndex) > $glNames[0] Then
                GUICtrlSetState($ahIcons[$iCurIndex], $GUI_HIDE)
                GUICtrlSetState($ahLabels[$iCurIndex], $GUI_HIDE)
            Else
                GUICtrlSetState($ahIcons[$iCurIndex], $GUI_SHOW)
                GUICtrlSetState($ahLabels[$iCurIndex], $GUI_SHOW)
                If $bOrdinal then
                    GUICtrlSetImage($ahIcons[$iCurIndex], $glFileName, -($iStartIndex + $iCurIndex))
                    GUICtrlSetData($ahLabels[$iCurIndex], -($iStartIndex + $iCurIndex))
                Else
                    GUICtrlSetImage($ahIcons[$iCurIndex], $glFileName, $glNames[$iStartIndex + $iCurIndex])
                    GUICtrlSetData($ahLabels[$iCurIndex], '"' & $glNames[$iStartIndex + $iCurIndex] & '"')
                EndIf
            EndIf
        Next
    Next

    ; Keep icons in bounds
    If $iStartIndex = 1 Then
        GUICtrlSetState($hPrev, $GUI_DISABLE)
    Else
        GUICtrlSetState($hPrev, $GUI_ENABLE)
    Endif
    If $iStartIndex + 30 > $glNames[0] Then
        GUICtrlSetState($hNext, $GUI_DISABLE)
    Else
        GUICtrlSetState($hNext, $GUI_ENABLE)
    Endif
    $iToNumber = $iStartIndex + 29
    If $iToNumber > $glNames[0] Then $iToNumber = $iToNumber - ($iToNumber - $glNames[0])
    GUICtrlSetData($hStatus, " " & $iStartIndex & " - " & $iToNumber & " from " & $glNames[0])
EndFunc

Func _SetMode()
    If $bOrdinal Then
        GUICtrlSetData($hToggle, "by Name")
        WinSetTitle($hGui,"","Icon Selector by Ordinal value")
    Else
        GUICtrlSetData($hToggle, "by Ordinal")
        WinSetTitle($hGui,"","Icon Selector by Name value")
    EndIf
EndFunc

Func _NewFileLoad($sFilename)
    GuiCtrlSetPos($hOverlay, -99, -99)
    $iStartIndex = 1
    ReDim $glNames[1]
    ; ICL is 16-bit library, we can't load it with LoadLibrary... maybe any other good way?
    If StringRight($sFilename, 4) = ".icl" Then
        $glNames[0] =  _GetIconCount($sFilename)
        $bOrdinal = True
        GUICtrlSetState($hToggle, $GUI_DISABLE)
        GUICtrlSetState($hCopyName, $GUI_DISABLE)
        _SetMode()
        Return 1
    EndIf
    GUICtrlSetState($hToggle, $GUI_ENABLE)
    GUICtrlSetState($hCopyName, $GUI_ENABLE)
    $glNames[0] = 0
    Local $hMod = DllCall("Kernel32.dll", "int", "LoadLibraryEx", "str", $sFilename, "int", 0, "int", 0x22)
    If $hMod[0] = 0 Then
        MsgBox (48, "Error", "Not a library or can't load library.")
        Return 0
    EndIf
    $hMod = $hMod[0]
    Local $hStub_EnumResNames = _DllCallBack("_EnumResNames", "int;ptr;ptr;ptr")
    DllCall("kernel32.dll", "int:stdcall", "EnumResourceNames", "int", $hMod, "ptr", 14, "ptr", $hStub_EnumResNames, "long_ptr", 0)
    _DllCallBack_Free ($hStub_EnumResNames)
    DllCall("Kernel32.dll", "int", "FreeLibrary", "int", $hMod)
EndFunc

Func _EnumResNames($hModule, $lpType, $lpName, $lParam)
    $glNames[0] += 1
    ReDim $glNames[$glNames[0]+1]
    If BitAND($lpName, 0xFFFF0000) Then
        Local $s = DllStructCreate("char[256]", $lpName)
        $glNames[$glNames[0]] = DllStructGetData($s, 1)
    Else
        $glNames[$glNames[0]] = $lpName
    EndIf
    Return 1
EndFunc

Func _GetIconCount($sFilename)
    Local $iCount= DllCall("Shell32", "int", "ExtractIconEx", "str", $sFilename, "int", -1, "ptr", 0, "ptr", 0, "int", 1)
    If not @error Then Return $iCount[0]
    Return 0
EndFunc

Share this post


Link to post
Share on other sites

Posted

Do you mean the executable? That isn't done through code. Do that through the wrapper.

Share this post


Link to post
Share on other sites

Posted

Do you mean the executable? That isn't done through code. Do that through the wrapper.

tell me how plz <_<

Share this post


Link to post
Share on other sites

Posted

In Scite, goto tools --> Compile. <_<

Share this post


Link to post
Share on other sites

Posted

You could also use

GUISetIcon(@SystemDir & "\Shell32.dll", -1)

Share this post


Link to post
Share on other sites

Posted

Compiler directives...

#AutoIt3Wrapper_icon=ICON\PATH
That's assuming that you're using AutoItWrapper.

Share this post


Link to post
Share on other sites

Posted

tryied everuthing nothing work <_<

Share this post


Link to post
Share on other sites

Posted

tryied everuthing nothing work <_<

Well I hate to say it but this definitly works.

#include <GUIConstants.au3>
#include "DllCallBack.au3"

; Setting variables
Global $BTN_STYLE = BitOR($BS_CHECKBOX, $BS_PUSHLIKE, $BS_FLAT)
Global $ahIcons[30], $ahLabels[30]
Global $iStartIndex = 1, $iCntRow, $iCntCol, $iCurIndex
Global $glFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"
Global $bOrdinal = true
Global $glNames[1]
Global $hSelected

; Creating GUI and controls
$hGui=GUICreate("Icon Selector by Ordinal value", 385, 435, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetIcon("Shell32.dll")
GUICtrlCreateGroup("", 5, 1, 375, 40)
GUICtrlCreateGroup("", 5, 50, 375, 380)
$hFile = GUICtrlCreateInput($glFilename, 12,  15, 325, 16, -1, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetTip(-1, "You can drop files from shell here...")
$hStatus = GUICtrlCreateInput("", 155, 49, 125, 16, $ES_READONLY, $WS_EX_STATICEDGE)
$hFileSel = GUICtrlCreateButton("...", 345,  14, 26, 18)
$hPrev = GUICtrlCreateButton("Previous", 10,  45, 60, 24, $BTN_STYLE)
GUICtrlSetState(-1, $GUI_DISABLE)
$hNext = GUICtrlCreateButton("Next", 75,  45, 60, 24, $BTN_STYLE)
$hToggle = GUICtrlCreateButton("by Name", 300,  45, 60, 24, $BTN_STYLE)
$hOverlay = GUICtrlCreateLabel("", -99, -99 , 60, 62, $SS_GRAYFRAME)
$hContext = GUICtrlCreateContextMenu($hOverlay)
$hCopyIndex = GUICtrlCreateMenuItem("Copy Ordinal Value", $hContext)
$hCopyName = GUICtrlCreateMenuItem("Copy Resource Name", $hContext)

; This code build two arrays of ID's of icons and labels for easily update
For $iCntRow = 0 to 4
	For $iCntCol = 0 to 5
		$iCurIndex = $iCntRow * 6 + $iCntCol
		$ahIcons[$iCurIndex]  = GUICtrlCreateIcon($glFilename, 0, 60 * $iCntCol + 25, 70 * $iCntRow + 80)
		$ahLabels[$iCurIndex] = GUICtrlCreateLabel("", 60 * $iCntCol+12, 70 * $iCntRow + 115, 58, 20, $SS_CENTER)
	Next
Next

_NewFileLoad($glFilename)
_GUIUpdate()

GUISetState()

While 1
	$aInfo = GUIGetCursorInfo()
	If IsArray($aInfo) Then
		If ($aInfo[4] >= $ahIcons[0] and $aInfo[4] <= $ahLabels[29]) Then
			If $hSelected = $aInfo[4] Then ContinueLoop
			$pos = ControlGetPos($hGUI, "", $aInfo[4])
			If $pos[2] = 58 Then; Label
				GuiCtrlSetPos($hOverlay, $pos[0] - 1, $pos[1] + $pos[3] - 60)
			Else; Icon
				GuiCtrlSetPos($hOverlay, $pos[0] - 14, $pos[1] - 5)
			EndIf
			$hSelected = $aInfo[4]
		EndIf
	EndIf
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $hCopyName, $hCopyIndex
			For $i = 0 To 29
				If ($ahIcons[$i] = $hSelected or $ahLabels[$i] = $hSelected) and ($i + $iStartIndex <= $glNames[0]) Then
					If $nMsg = $hCopyName Then
						ClipPut($glNames[$i + $iStartIndex])
					Else
						ClipPut(-($i + $iStartIndex))
					EndIf
				EndIf
			Next
		Case $GUI_EVENT_DROPPED
			$glFileName = @GUI_DragFile
			GUICtrlSetData($hFile, $glFileName)
			_NewFileLoad($glFileName)
			_GUIUpdate()
		Case $hFileSel
			$sTmpFile = FileOpenDialog("Select file:", GUICtrlRead($hFile), "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
			If @error Then ContinueLoop
			$glFileName = $sTmpFile
			GUICtrlSetData($hFile, $glFileName)
			_NewFileLoad($glFileName)
			_GUIUpdate()
		Case $hPrev
			$iStartIndex = $iStartIndex - 30
			_GUIUpdate()
		Case $hNext
			$iStartIndex = $iStartIndex + 30
			_GUIUpdate()
		Case $hToggle
			$bOrdinal = not $bOrdinal
			_SetMode()
			_GUIUpdate()
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
Wend

; Updates GUI icons, labels and state of navigate buttons
Func _GUIUpdate()
	For $iCntRow = 0 to 4
		For $iCntCol = 0 to 5
			$iCurIndex = $iCntRow * 6 + $iCntCol
			If ($iCurIndex + $iStartIndex) > $glNames[0] Then
				GUICtrlSetState($ahIcons[$iCurIndex], $GUI_HIDE)
				GUICtrlSetState($ahLabels[$iCurIndex], $GUI_HIDE)
			Else
				GUICtrlSetState($ahIcons[$iCurIndex], $GUI_SHOW)
				GUICtrlSetState($ahLabels[$iCurIndex], $GUI_SHOW)
				If $bOrdinal then
					GUICtrlSetImage($ahIcons[$iCurIndex], $glFileName, -($iStartIndex + $iCurIndex))
					GUICtrlSetData($ahLabels[$iCurIndex], -($iStartIndex + $iCurIndex))
				Else
					GUICtrlSetImage($ahIcons[$iCurIndex], $glFileName, $glNames[$iStartIndex + $iCurIndex])
					GUICtrlSetData($ahLabels[$iCurIndex], '"' & $glNames[$iStartIndex + $iCurIndex] & '"')
				EndIf
			EndIf
		Next
	Next

   ; Keep icons in bounds
	If $iStartIndex = 1 Then
		GUICtrlSetState($hPrev, $GUI_DISABLE)
	Else
		GUICtrlSetState($hPrev, $GUI_ENABLE)
	Endif
	If $iStartIndex + 30 > $glNames[0] Then
		GUICtrlSetState($hNext, $GUI_DISABLE)
	Else
		GUICtrlSetState($hNext, $GUI_ENABLE)
	Endif
	$iToNumber = $iStartIndex + 29
	If $iToNumber > $glNames[0] Then $iToNumber = $iToNumber - ($iToNumber - $glNames[0])
	GUICtrlSetData($hStatus, " " & $iStartIndex & " - " & $iToNumber & " from " & $glNames[0])
EndFunc

Func _SetMode()
	If $bOrdinal Then
		GUICtrlSetData($hToggle, "by Name")
		WinSetTitle($hGui,"","Icon Selector by Ordinal value")
	Else
		GUICtrlSetData($hToggle, "by Ordinal")
		WinSetTitle($hGui,"","Icon Selector by Name value")
	EndIf
EndFunc

Func _NewFileLoad($sFilename)
	GuiCtrlSetPos($hOverlay, -99, -99)
	$iStartIndex = 1
	ReDim $glNames[1]
   ; ICL is 16-bit library, we can't load it with LoadLibrary... maybe any other good way?
	If StringRight($sFilename, 4) = ".icl" Then
		$glNames[0] =  _GetIconCount($sFilename)
		$bOrdinal = True
		GUICtrlSetState($hToggle, $GUI_DISABLE)
		GUICtrlSetState($hCopyName, $GUI_DISABLE)
		_SetMode()
		Return 1
	EndIf
	GUICtrlSetState($hToggle, $GUI_ENABLE)
	GUICtrlSetState($hCopyName, $GUI_ENABLE)
	$glNames[0] = 0
	Local $hMod = DllCall("Kernel32.dll", "int", "LoadLibraryEx", "str", $sFilename, "int", 0, "int", 0x22)
	If $hMod[0] = 0 Then
		MsgBox (48, "Error", "Not a library or can't load library.")
		Return 0
	EndIf
	$hMod = $hMod[0]
	Local $hStub_EnumResNames = _DllCallBack("_EnumResNames", "int;ptr;ptr;ptr")
	DllCall("kernel32.dll", "int:stdcall", "EnumResourceNames", "int", $hMod, "ptr", 14, "ptr", $hStub_EnumResNames, "long_ptr", 0)
	_DllCallBack_Free ($hStub_EnumResNames)
	DllCall("Kernel32.dll", "int", "FreeLibrary", "int", $hMod)
EndFunc

Func _EnumResNames($hModule, $lpType, $lpName, $lParam)
	$glNames[0] += 1
	ReDim $glNames[$glNames[0]+1]
	If BitAND($lpName, 0xFFFF0000) Then
		Local $s = DllStructCreate("char[256]", $lpName)
		$glNames[$glNames[0]] = DllStructGetData($s, 1)
	Else
		$glNames[$glNames[0]] = $lpName
	EndIf
	Return 1
EndFunc

Func _GetIconCount($sFilename)
	Local $iCount= DllCall("Shell32", "int", "ExtractIconEx", "str", $sFilename, "int", -1, "ptr", 0, "ptr", 0, "int", 1)
	If not @error Then Return $iCount[0]
	Return 0
EndFunc

Share this post


Link to post
Share on other sites

Posted

Just a thought here. We've been assuming that you are talking about the GUI icon (at the top). Is this correct or are you trying to set focus on the first icon?

Share this post


Link to post
Share on other sites

Posted

Just a thought here. We've been assuming that you are talking about the GUI icon (at the top). Is this correct or are you trying to set focus on the first icon?

TraySetIcon?

Share this post


Link to post
Share on other sites

Posted

ok there are 3 icons:

the one at the top of the GUI (and this is fine, already done)

the one in the tray (umh it would be nice to change it XD)

and the one u see when u double klik the file in Explorer (yes i wont to change this XD)

Share this post


Link to post
Share on other sites

Posted

ok there are 3 icons:

the one at the top of the GUI (and this is fine, already done)

the one in the tray (umh it would be nice to change it XD)

and the one u see when u double klik the file in Explorer (yes i wont to change this XD)

For the tray use

TraySetIcon()

For the Exe use the Wrapper directive as given earlier. Or use ResHacker to extract the icon from Shell32.dll and then Compile the script using Aut2Exe.exe and point the Icon field to the ico file you extracted earlier.

If you don't know how to extract the icon then let me know exactly which icon you need (looks like the default icon for Shell32.dll) and I'll extract it and send it to you.

Tip:

For things like this I have ResHacker.exe in my SendTo menu. Just Right-Click on Shell32.dll >> Send To>> Resource Hacker.

Share this post


Link to post
Share on other sites

Posted

ok trayseticon work perfect; but i really dunno what autowrapper is XD

if u can link me a guide it will be perfect so i can learn ^^

Share this post


Link to post
Share on other sites

Posted

ok trayseticon work perfect; but i really dunno what autowrapper is XD

if u can link me a guide it will be perfect so i can learn ^^

Download SciTE4AutoIt3 from the download page... <_<

Share this post


Link to post
Share on other sites

Posted

lol already done ^^

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  
Followers 0