找回密码
 加入
搜索
查看: 1732|回复: 7

[AU3基础] 按钮设置背景图片,exe移动位置后图片不显示 - 已解决

[复制链接]
发表于 2017-7-1 10:27:50 | 显示全部楼层 |阅读模式
本帖最后由 JianWudao 于 2017-7-1 11:55 编辑

我用GUICtrlSetImage为按钮设置了一个背景图片。
开始是用的GUICtrlSetImage(-1, "shell32.dll", 16739, 0),这个从Win7换成XP后,里面的图标文件就不同了。
后来我做了一个AD_ShuaX.ico放编译目录下,生成exe在当前目录执行可以正常显示。
但是把exe移动到其他位置,如果exe所在目录没有AD_ShuaX.ico这个文件,那么按钮的图标就显示不了。

看了FileInstall这个函数,但是不想每次运行的时候还要释放一个文件出来。
而且我调用的路径是直接在exe目录下,这个释放出来好乱。

求大神帮助,谢谢!
发表于 2017-7-1 10:55:48 | 显示全部楼层
发表于 2017-7-1 10:58:32 | 显示全部楼层
#AutoIt3Wrapper_Res_File_Add=AD_ShuaX.ico,RT_ICON,1
把图标打包到EXE

If @Compiled Then
        GUICtrlSetImage(-1, @ScriptFullPath, -1, 0); 文件包含多个图标时的图标名称. 如为图标序号, 则可以是负数. 否则设为 -1.
Else
        GUICtrlSetImage(-1, "AD_ShuaX.ico")
EndIf
 楼主| 发表于 2017-7-1 11:17:44 | 显示全部楼层
回复 3# tubaba


    我刚才就添加过一次,但是没成功
#AccAu3Wrapper_Res_File_Add=AD_ShuaX.ico

用你的代码还是没成功,而且把后面的RT_ICON,1加上去之后,我整个exe的图标也变成这个图标了。
 楼主| 发表于 2017-7-1 11:45:50 | 显示全部楼层
回复 2# yamakawa


    这个的确是可以的,就是又多了个引用文件。

不过我的实现要求比较少,所以根据这个改了下,完成了!

其实还是和3楼的朋友说的差不多的,只是不知道为什么参数为-1不行,而必须为'201'
不知道哪有#AccAu3Wrapper_Res这些的说明文档
#AccAu3Wrapper_Res_Icon_Add=AD_ShuaX.ico

If @Compiled Then
        GUICtrlSetImage(-1, @AutoItExe, '201', 0) 
Else
        GUICtrlSetImage(-1, "AD_ShuaX.ico")
EndIf
发表于 2017-7-1 11:49:01 | 显示全部楼层
#AutoIt3Wrapper_Icon 是用来干嘛的?不行的时候自己想想为什么不行,难道只会伸手要现成的?
 楼主| 发表于 2017-7-1 11:54:37 | 显示全部楼层
本帖最后由 JianWudao 于 2017-7-1 11:55 编辑

回复 6# tubaba


终于找到帮助文档了!
关键就在于这个参数上
If no ResNumber is specified, the added icons are numbered from 201 up

至此,结帖!
谢谢两位!
#AutoIt3Wrapper_Res_Icon_Add=                   ; Filename[,ResNumber[,LanguageCode]] of ICO to be added.
; Add extra ICO files to the resources
; Use full path of the ico files to be added
; ResNumber is a numeric value used to access the icon: TraySetIcon(@ScriptFullPath, ResNumber)
; If no ResNumber is specified, the added icons are numbered from 201 up
发表于 2017-7-1 12:05:37 | 显示全部楼层
201是图标名称,-1指的是图标序号,如果-1不行,可能脚本前面就添加过图标文件.可以用安装目录下的\Examples\GUI\Advanced\enumicons.au3,看看编译好的程序图标加入情况
; ===============================================================================
;
; Description:      Show all icons in the given file
; Requirement(s):   AutoIt 3.0.103+
; Author(s):        YDY (Lazycat)
;
; ===============================================================================

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

; Setting variables
Global $g_aidIcons[30], $g_aidLabels[30]
Global $g_iStartIndex = 1
Global $g_sFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"
Global $g_iOrdinal = -1

Global $g_idPrev

_Main()

Func _Main()
        Local $iMsg, $sCurFilename, $sTmpFile

        ; Creating GUI and controls
        Local $hGui = GUICreate("Icon Selector by Ordinal value", 385, 435, @DesktopWidth / 2 - 192, _
                        @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES)
        GUICtrlCreateGroup("", 5, 1, 375, 40)
        GUICtrlCreateGroup("", 5, 50, 375, 380)
        Local $idFile = GUICtrlCreateInput($g_sFilename, 12, 15, 325, 16, -1, $WS_EX_STATICEDGE)
        GUICtrlSetState(-1, $GUI_DROPACCEPTED)
        GUICtrlSetTip(-1, "You can drop files from shell here...")
        Local $idFileSel = GUICtrlCreateButton("...", 345, 14, 26, 18)
        $g_idPrev = GUICtrlCreateButton("Previous", 10, 45, 60, 24, $BS_FLAT)
        GUICtrlSetState(-1, $GUI_DISABLE)
        Local $idNext = GUICtrlCreateButton("Next", 75, 45, 60, 24, $BS_FLAT)
        Local $idToggle = GUICtrlCreateButton("by Name", 300, 45, 60, 24, $BS_FLAT)

        ; This code build two arrays of ID's of icons and labels for easily update
        Local $iCurIndex
        For $iCntRow = 0 To 4
                For $iCntCol = 0 To 5
                        $iCurIndex = $iCntRow * 6 + $iCntCol
                        $g_aidIcons[$iCurIndex] = GUICtrlCreateIcon($g_sFilename, $g_iOrdinal * ($iCurIndex + 1), _
                                        60 * $iCntCol + 25, 70 * $iCntRow + 80)
                        $g_aidLabels[$iCurIndex] = GUICtrlCreateLabel($g_iOrdinal * ($iCurIndex + 1), _
                                        60 * $iCntCol + 11, 70 * $iCntRow + 115, 60, 20, $SS_CENTER)
                Next
        Next

        GUISetState()

        While 1
                $iMsg = GUIGetMsg()
                ; Code below will check if the file is dropped (or selected)
                $sCurFilename = GUICtrlRead($idFile)
                If $sCurFilename <> $g_sFilename Then
                        $g_iStartIndex = 1
                        $g_sFilename = $sCurFilename
                        _GUIUpdate()
                EndIf
                ; Main "Select" statement that handles other events
                Select
                        Case $iMsg = $idFileSel
                                $sTmpFile = FileOpenDialog("Select file:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
                                If @error Then ContinueLoop
                                GUICtrlSetData($idFile, $sTmpFile); GUI will be updated at next iteration
                        Case $iMsg = $g_idPrev
                                $g_iStartIndex = $g_iStartIndex - 30
                                _GUIUpdate()
                        Case $iMsg = $idNext
                                $g_iStartIndex = $g_iStartIndex + 30
                                _GUIUpdate()
                        Case $iMsg = $idToggle
                                If $g_iOrdinal = -1 Then
                                        $g_iOrdinal = 1
                                        GUICtrlSetData($idToggle, "by Ordinal")
                                        WinSetTitle($hGui, "", "Icon Selector by Name value")
                                Else
                                        $g_iOrdinal = -1
                                        GUICtrlSetData($idToggle, "by Name")
                                        WinSetTitle($hGui, "", "Icon Selector by Ordinal value")
                                EndIf
                                _GUIUpdate()
                        Case $iMsg = $GUI_EVENT_CLOSE
                                Exit
                EndSelect
        WEnd
EndFunc   ;==>_Main

; Just updates GUI icons, labels and set state of "Previous" button
Func _GUIUpdate()
        Local $iCurIndex
        For $iCntRow = 0 To 4
                For $iCntCol = 0 To 5
                        $iCurIndex = $iCntRow * 6 + $iCntCol
                        GUICtrlSetImage($g_aidIcons[$iCurIndex], $g_sFilename, $g_iOrdinal * ($iCurIndex + $g_iStartIndex))
                        If $g_iOrdinal = -1 Then
                                GUICtrlSetData($g_aidLabels[$iCurIndex], -($iCurIndex + $g_iStartIndex))
                        Else
                                GUICtrlSetData($g_aidLabels[$iCurIndex], '"' & ($iCurIndex + $g_iStartIndex) & '"')
                        EndIf
                Next
        Next
        ; This is because we don't want negative values
        If $g_iStartIndex = 1 Then
                GUICtrlSetState($g_idPrev, $GUI_DISABLE)
        Else
                GUICtrlSetState($g_idPrev, $GUI_ENABLE)
        EndIf
EndFunc   ;==>_GUIUpdate
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-3-29 07:31 , Processed in 0.074936 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表