0

我发现的在 GUI 表单上显示程序图标的示例似乎都使用文本控件来指示图标的显示位置,然后发送 STM_SETICON 消息以实际显示图像。但是,当我单击显示的图标时,永远不会调用处理鼠标单击的文本控件的事件子例程。我考虑过使用自己的事件子例程在图标上显示透明图形区域,但似乎我应该能够将事件处理程序直接附加到图标的显示区域或将图标加载到具有自己事件处理程序的图形控件中。

任何人都知道如何做这两个?

我在 Windows 7 Pro 上使用 AutoHotKey L (v 1.1.09.04) 64 位。

这是我在寻找显示图标的方法时找到的代码,我现在正在使用它。

FileName := "C:\XXXX\XXXX.exe" ; Get the icon from a program file.

Ignored := 0

;
; CopyImage into memory and scale it to size.
;
IMAGE_ICON          := 1
LR_COPYFROMRESOURCE := 4
LR_COPYDELETEORG    := 8

IconSize      := 16 ; Icon size: X by X
ptr           := ( ( A_PtrSize = 8 ) ? "ptr" : "uint" )
sfi_size      := A_PtrSize + 8 + ( ( A_IsUnicode ) ? 680 : 340 )
VarSetCapacity( sfi, sfi_size )
DllCall( "Shell32\SHGetFileInfo" . ( ( A_IsUnicode ) ? "W" : "A" )
            , "str",  FileName
            , "uint", Ignored
            , ptr,    &sfi
            , "uint", sfi_size
            , "uint", SHGFI_ICON )
hIcon         := NumGet( sfi, 0 )
hicon_resized := DllCall( "CopyImage"
                          , ptr,    hicon
                          , "uint", IMAGE_ICON
                          , "int",  IconSize
                          , "int",  IconSize
                          , "uint", LR_COPYFROMRESOURCE | LR_COPYDELETEORG
                          , ptr )
DllCall( "DestroyIcon", ptr, hicon )

STM_SETICON := 0x0170
Gui, Add, Text, x5 y8 w%IconSize% h%IconSize% hwndMyPic %SS_ICON% gClicked
SendMessage, STM_SETICON, hicon_resized, 0,, Ahk_ID %MyPic%

我想更改要嵌入到我的脚本中的图标,并且还使用任务栏和托盘图标,我希望这一切都可以工作,而无需编译脚本。

4

1 回答 1

1

您是否正在寻找更改任何正在运行的脚本的托盘图标的方法?这是我从 Shell32.dll 借用图标的示例:

Menu, Tray, Tip, My Application
Menu, Tray, Icon , Shell32.dll, 28, 1

通过使用:

menu, tray, add

您还可以添加(或替换)托盘菜单

很久以前,SKAN 展示了如何在脚本中包含图标。 http://www.autohotkey.com/board/topic/31044-crazy-scripting-include-an-icon-in-your-script/

这是我尝试过的:

#NoTrayIcon
IconDataHex =
( LTrim Join
0000010001002020080000000000A8080000160000002800000020000000400000000100080000000000000400
000000000000000000000000000000000000000000000080000080000000808000800000008000800080800000
C0C0C000C0DCC000F0CAA6000020400000206000002080000020A0000020C0000020E000004000000040200000
40400000406000004080000040A0000040C0000040E00000600000006020000060400000606000006080000060
A0000060C0000060E00000800000008020000080400000806000008080000080A0000080C0000080E00000A000
0000A0200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0200000C0400000C06000
00C0800000C0A00000C0C00000C0E00000E0000000E0200000E0400000E0600000E0800000E0A00000E0C00000
E0E00040000000400020004000400040006000400080004000A0004000C0004000E00040200000402020004020
400040206000402080004020A0004020C0004020E00040400000404020004040400040406000404080004040A0
004040C0004040E00040600000406020004060400040606000406080004060A0004060C0004060E00040800000
408020004080400040806000408080004080A0004080C0004080E00040A0000040A0200040A0400040A0600040
A0800040A0A00040A0C00040A0E00040C0000040C0200040C0400040C0600040C0800040C0A00040C0C00040C0
E00040E0000040E0200040E0400040E0600040E0800040E0A00040E0C00040E0E0008000000080002000800040
0080006000800080008000A0008000C0008000E00080200000802020008020400080206000802080008020A000
8020C0008020E00080400000804020008040400080406000804080008040A0008040C0008040E0008060000080
6020008060400080606000806080008060A0008060C0008060E000808000008080200080804000808060008080
80008080A0008080C0008080E00080A0000080A0200080A0400080A0600080A0800080A0A00080A0C00080A0E0
0080C0000080C0200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0000080E0200080E04000
80E0600080E0800080E0A00080E0C00080E0E000C0000000C0002000C0004000C0006000C0008000C000A000C0
00C000C000E000C0200000C0202000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C040
2000C0404000C0406000C0408000C040A000C040C000C040E000C0600000C0602000C0604000C0606000C06080
00C060A000C060C000C060E000C0800000C0802000C0804000C0806000C0808000C080A000C080C000C080E000
C0A00000C0A02000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C02000C0C04000C0
C06000C0C08000C0C0A000F0FBFF00A4A0A000808080000000FF0000FF000000FFFF00FF000000FF00FF00FFFF
0000FFFFFF00FFFFFFFFFFFFFFF607F707F6F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6
E49A525BA40708F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBE0D8D89991525BA407F6F6FFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2E8D8D8D8D8D899925B9BF707F6F6FFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFE2E8D8D8D8D0D0D8D8D899525B9BF707F6F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFE2E9D0D0D0D0D0D0
D0D0D8D8D899525BA4F708FFFFFFFFFFFFFFFFFFFFFFFFFFE2E9D092DB929191D8D0D0D0D0D8D8D8999AA4F6FF
FFFFFFFFFFFFFFFFFFFFFFE2E990DBE4E4E4DB929191D8D090D0D8D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E9
90DBE4E4E408BFE4DB929191D8D8D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E9909BE4E4E4B7BF07070807E492
91D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E99092DBDBE4F777E5BFBFBFBFBFE491D9A4F6FFFFFFFFFFFFFFFF
FFFFFFFFE2EA9092DBDBDBDBE4E4AEAEF7B67FED92D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2EA9092DBDBDBDBDB
DBDBE4E4E4F7E492D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2EA9092D2DBDBDBDBDBDBDBDBDBE4DB92D9A4F6FFFF
FFFFFFFFFFFFFFFFFFFFE2F29092D2D2DBDBDBDBDBDBDBDBDBDB9299A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2F290
92D2D2D2D2DBDBDBDBDBDBDBDB9299A4F6FFFFFFFFFFFFFFFFFFFFFFFFE3FFD192D2D2D2D2D2D2D2D2D2D2D2D2
9291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D992D2D2D2D2D2D2D2D2D2D2D2D29291A4F6FFFFFFFFFFFFFFFFFF
FFFFFF09F3D989D2D2D2D2D2D2D2D2D2D2D2D29291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D98992D2D2D2D2D2
D2D2D2D2D2929291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D9899292929292929292929292929291A4F6FFFFFF
FFFFFFFFFFFFFFFFFF0909D9499192929292929292929292929291A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB9149
4949494949494949494949499291A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB904949494949494949494949494992
91F7FFFFFFFFFFFFFFFFFFFFFFFFFFECEB90494949494949494949494949499292F7F6FFFFFFFFFFFFFFFFFFFF
FFFFECEB90494949494949494949494949498991A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB904949404040404949
49494949498991A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB90914949494949494040494949494991A4F6FFFFFFFF
FFFFFFFFFFFFFFFFECEB90909090909191919149494949499191A4F6FFFFFFFFFFFFFFFFFFFFFFFF09FFE2DAD9
D1909090909090909091919091A4F6FFFFFFFFFFFFFFFFFFFFFFFF0909EBECE2EBE2EAE2E2D9D9D0D0D0909091
F7F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0909ECECEBE3E2D9D8D9ECF6FFFFFFFFFFFFFF0000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000
)

VarSetCapacity( IconData,( nSize:=StrLen(IconDataHex)//2) )
Loop %nSize% ; MCode by Laszlo Hars: http://www.autohotkey.com/forum/viewtopic.php?t=21172
  NumPut( "0x" . SubStr(IconDataHex,2*A_Index-1,2), IconData, A_Index-1, "Char" )
IconDataHex := ""            ; contents needed no more
hICon := DllCall( "CreateIconFromResourceEx", UInt,&IconData+22 
, UInt,NumGet(IconData,14), Int,1, UInt,0x30000, Int,32, Int,32, UInt,0 ) 
Gui +LastFound               ; Set our GUI as LastFound window ( affects next two lines )
SendMessage, ( WM_SETICON:=0x80 ), 0, hIcon  ; Set the Titlebar Icon
SendMessage, ( WM_SETICON:=0x80 ), 1, hIcon  ; Set the Alt-Tab icon
PID := DllCall("GetCurrentProcessId"), VarSetCapacity( NID,444,0 ), NumPut( 444,NID )
DetectHiddenWindows, On
NumPut( WinExist( A_ScriptFullPath " ahk_class AutoHotkey ahk_pid " PID),NID,4 )
DetectHiddenWindows, Off
NumPut( 1028,NID,8 ), NumPut( 2,NID,12 ), NumPut( hIcon,NID,20 )
Menu, Tray, Icon                                           ;   Shows the default Tray icon
DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ; and we immediately modify it.
Gui, Show, w640 h480               
Return

GuiClose:
 ExitApp

它会打开一个空的 GUI,但它已经更改了托盘图标、GUI 图标和 Alt+Tab 图标。

于 2013-06-20T15:34:37.027 回答