找回密码
 加入
搜索
查看: 10667|回复: 19

[GUI管理] 求助:怎样在按钮上添加自定义的图标【已解决】

 火.. [复制链接]
发表于 2010-10-7 12:29:49 | 显示全部楼层 |阅读模式
本帖最后由 d5121226 于 2010-10-7 13:51 编辑

在帮助文件中_GUIImageList_Create和_GUIImageList_AddIcon和GUICtrlButton_SetImageList函数。但是示例脚本中只有添加shell32.dll中的图标。怎样才能添加自己定义的图标文件呢?
_GUIImageList_AddIcon($hWnd, $sFile[, $iIndex=0[, $fLarge = False])
个$sFile是图标路径,后面还有个$Index索引。
问题是我这想使用自己定义的一个icon文件夹里面的图标。这些都是单个的ico文件啊。怎么读取呢?

评分

参与人数 1金钱 +10 收起 理由
afan + 10

查看全部评分

发表于 2010-10-7 12:38:08 | 显示全部楼层
试试这个,我特地加了注释!
将图标文件换成Ico文件试试吧!

#include <GuiButton.au3>
#include <GuiImageList.au3>

GUICreate("设置按钮图标", 560, 100)
$But1 = GUICtrlCreateButton("图标靠左", 10, 20, 100, 60, $BS_FLAT)
_SetIcon(-1, 'shell32.dll', 22, 0, 20, 20)

$But2 = GUICtrlCreateButton("图标靠右", 120, 20, 100, 60, $BS_FLAT)
_SetIcon(-1, 'shell32.dll', 23, 1)

$But3 = GUICtrlCreateButton("图标靠上", 230, 20, 100, 60, $BS_FLAT)
_SetIcon(-1, 'shell32.dll', 24, 2, 30, 30)

$But4 = GUICtrlCreateButton("图标靠下", 340, 20, 100, 60, $BS_FLAT)
_SetIcon(-1, 'shell32.dll', 25, 3, 35, 35)

$But5 = GUICtrlCreateButton("图标居中", 450, 20, 100, 60, $BS_FLAT)
_SetIcon(-1, 'shell32.dll', 26, 4, 40, 40)
GUISetState()

Do
Until GUIGetMsg() = -3

Func _SetIcon($hWnd, $sFile, $iIndex = 0, $nAlign = 0, $iWidth = 25, $iHeight = 25) ;控件句柄, 图标图像的路径, 图标索引, 图标在控件中的位置, 图标宽度, 图标高度
        $hImage1 = _GUIImageList_Create($iWidth, $iHeight, 5, 1, 0) ;创建图像列表控件
        _GUIImageList_AddIcon($hImage1, $sFile, $iIndex, True) ;向图像列表添加图标
        _GUICtrlButton_SetImageList($hWnd, $hImage1, $nAlign) ;分配一个图像列表到按钮控件,$nAlign 是图标位置参数

评分

参与人数 2威望 +2 金钱 +30 贡献 +5 收起 理由
专业的门外汉 + 30 + 5
afan + 2

查看全部评分

 楼主| 发表于 2010-10-7 12:45:24 | 显示全部楼层
回复 2# 水木子


这个例子,我上午看过了,他的每一个$but上添加的图标都是shell32.dll中的。
我想要的是使用自己的ico文件,不使用shell32.dll中的图标。
发表于 2010-10-7 12:50:21 | 显示全部楼层
我不是说了吗!你换成Ico试试啊!
 楼主| 发表于 2010-10-7 13:03:36 | 显示全部楼层
回复 4# 水木子


明白了。终于成功了。多谢啊
发表于 2010-10-7 13:37:36 | 显示全部楼层
没事!如果问题解决了,就请在标题后面添加[已解决]字样吧!
发表于 2010-10-7 15:03:32 | 显示全部楼层
哇哈哈  我也学习了  偷师……
发表于 2010-10-7 20:51:55 | 显示全部楼层
这个不错,我也来留脚印学习
发表于 2010-10-20 16:49:53 | 显示全部楼层
学习到了,刚加图片出错了,原来是#include<GuiBottun.au3>没加
发表于 2010-11-2 14:12:31 | 显示全部楼层
发表于 2010-12-1 09:25:25 | 显示全部楼层
试了,不错,可以运行。
发表于 2010-12-11 22:33:12 | 显示全部楼层

谢谢,很全的例子,学习了
发表于 2011-6-19 06:23:25 | 显示全部楼层
不 错,我也学习了
发表于 2011-6-19 09:54:57 | 显示全部楼层
收藏一下,
发表于 2011-7-17 11:38:23 | 显示全部楼层
C:\Users\Administrator\Desktop\1.au3(27,63) : 错误: 表达式错误
        _GUICtrlButton_SetImageList($hWnd, $hImage1, $nAlign) ;分配一个图像列表到按钮控件,$nAlign 是图标位置参数
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
我的程序出现这个错误,怎么回事
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 16:57 , Processed in 0.089237 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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