最近在研究Gui美化的东西,然后就找到了一个Gui图片按钮实现的方法。可以让每一个按钮都有属于自己的图标,可以使用这个库来重新布局你的Gui界面。
210825更新 增加里托盘菜单修改的示例和窗体透明、阴影、淡出效果
TileButton.ahk
;--------------------------------
; TileButton - 图片按钮
;--------------------------------
; TileButton(
; x --> 在Gui上显示的x坐标
; , y --> 在Gui上显示的y坐标
; , w --> 在Gui上显示的图片宽度
; , h --> 在Gui上显示的图片高度
; , gLabel --> 需要跳转的g标签名称
; , Icon --> 图标库读取按钮起始编号 例如 "icon4"
; , DefaultTile --> 图标库文件地址 或 图标默认帧文件地址
; , PreelectioTile --> 图标预选帧文件地址
; , SelectTile --> 图标选中帧文件地址
; , Interleave --> 是否开启按钮预选帧[默认关闭 留空为0],[1为用编号+1做预选帧],[2为用编号+1做预选帧 同时开启+2选中帧]
; , HwndLabel --> Gui窗口标签 例如 "New2:"。等效于 Gui, New2: 的写法
; )
; 图标库命名规则:读取数字编号第1个是默认帧,第2个是预选帧【+1】,第3个是选中帧【+2】
TileButton(x:="", y:="", w:="", h:="", gLabel:="", Icon:="", DefaultTile:="", PreelectioTile:="", SelectTile:="", Interleave=0, HwndLabel:="") { ; By dbgba
Global
if (TileButtonToggleControl="")
OnMessage(0x20, "WM_SETCURSOR"), TileButtonToggle:=1, TileButtonToggleControl:=1, TileButtonVariableName=100
x:=(x="") ? "" : "x" x, y:=(y="") ? "" : " y" y, w:=(w="") ? "" : " w" w, h:=(h="") ? "" : " h" h, TileButtonVariableName++
if (SubStr(SubStr(PreelectioTile, -3),1, 1)=".")
%Interleave%%TileButtonVariableName%%icon%:= PreelectioTile "`n" SelectTile
else
%Interleave%%TileButtonVariableName%%icon%:=""
Gui, %HwndLabel%Add, Pic, % x y w h " v" Interleave TileButtonVariableName Icon " g" gLabel " " Icon, %DefaultTile%
}
WM_SETCURSOR() {
Global
MouseGetPos,,,TileButtonID, TileButtonControl
if (SubStr(TileButtonControl, 1, 6)="Static") && (TileButtonToggle=1) {
ControlGet, TileButtonControlHwnd, Hwnd,, %TileButtonControl%, ahk_id %TileButtonID%
GuiControlGet, IconNumber, Name, %TileButtonControlHwnd%
GuiControlGet, IconFileName, , %TileButtonControlHwnd%
OnMessage(0x201, "WM_LBUTTONDOWN"), ControlToggle:=TileButtonControl, ControlToggle2:=TileButtonControlHwnd, TileButtonToggle=0
if (SubStr(IconNumber, 1, 1)=1) || (SubStr(IconNumber, 1, 1)=2)
if (%IconNumber%="")
GuiControl,, %ControlToggle%, % "*icon" SubStr(IconNumber, 9, 4)+1 " " IconFileName ; 图标库预选帧
else
GuiControl,, %ControlToggle%, % StrSplit(%IconNumber%,"`n") [1] ; 图片预选帧
} else if (TileButtonControl!=ControlToggle) && (TileButtonToggle=0) {
if (SubStr(IconNumber, 1, 1)=1) || (SubStr(IconNumber, 1, 1)=2)
GuiControl,, %ControlToggle2%, % "*icon" SubStr(IconNumber, 9, 4) " " IconFileName ; 图标库或图片恢复默认帧
OnMessage(0x201, ""), TileButtonToggle=1
}
}
WM_LBUTTONDOWN() {
Global
SendInput {MButton} ; 屏蔽g标签双击复制到剪贴板
MouseGetPos,,,TileButtonControlToggleID, TileButtonControlToggle
GuiControlGet, TileButtonIconNumber, Name, %TileButtonControlToggle%
if (SubStr(TileButtonControlToggle, 1, 6)!="Static") || (TileButtonIconNumber="")
Return
ControlGet, ControlToggleHwnd, Hwnd,, %TileButtonControlToggle%, ahk_id %TileButtonControlToggleID%
GuiControlGet, TileButtonIconFileName, , %ControlToggleHwnd%
if (InStr(TileButtonIconNumber,"n")=8) {
if (SubStr(TileButtonIconNumber, 1, 1)=1)
GuiControl,, %ControlToggleHwnd%, % "*icon" SubStr(TileButtonIconNumber, 9, 4)+1 " " TileButtonIconFileName ; 图标库选中帧+1
else if (SubStr(TileButtonIconNumber, 1, 1)=2)
GuiControl,, %ControlToggleHwnd%, % "*icon" SubStr(TileButtonIconNumber, 9, 4)+2 " " TileButtonIconFileName ; 图标库选中帧+2
} else
if (TileButtonIconNumber!="")
GuiControl,, %ControlToggleHwnd%, % StrSplit(%TileButtonIconNumber%,"`n") [2] ; 图片选中帧
KeyWait LButton
SetTimer LButtonDownAsynchronous, -100
TileButtonToggle=1
Return
LButtonDownAsynchronous:
GuiControl,, %ControlToggleHwnd%, % "*icon" SubStr(TileButtonIconNumber, 9, 4) " " TileButtonIconFileName ; 图标库或图片恢复默认帧
TileButtonToggle=1
Return
}
百度网盘完整示例
6666
复制
看起来非常棒