Hi all from a newbie (almost).
As I got tired to see what was the effect of the icon resources contained in the shell32.dll on my GUIs I wrote this piece of code.
It shows the related numId of each icon as well as the icon itself.
Double clicking on any icon gives the possibility either to see the effect of the Icon in the tray or that as a new icon in the GUI. The latter task is attained destroying the GUI and rebuilding as I haven't find any other way to change my GUI's Icon
Code:
#SingleInstance Ignore
; get icon filepath
; assigning to the var _IconFile different values the
; script can act on different icon resources
; here I use shell32.dll
If ( A_OSType = "WIN32_WINDOWS" )
_IconFile = %A_WinDir%\system\shell32.dll
Else
_IconFile = %A_WinDir%\system32\shell32.dll
;adjust for screen height
If (A_ScreenHeight = 600)
_MaxColItems := 12
Else If (A_ScreenHeight = 768)
_MaxColItems := 14
Else If ((A_ScreenHeight = 864) Or (A_ScreenHeight = 900))
_MaxColItems := 16
Else If (A_ScreenHeight = 960)
_MaxColItems := 10
Else If (A_ScreenHeight = 1024)
_MaxColItems := 20
Else If (A_ScreenHeight = 1050)
_MaxColItems := 22
Else
_MaxColItems := 14
_Icon := 1 ; start from icon n 1
InputBox, _IconsNum, %_IconFile%, Enter the Number of icons contained in the resource file`n(Must be an Integer):,,,140,,,,,238
If (ErrorLevel Or _IconsNum = 0)
ExitApp
If _IconsNum Is Not Integer
ExitApp
;build GUI
Gosub BuildGUI
;wait for Ldoubleclick
OnMessage(0x203, "WM_LBUTTONDBLCLK")
Return
WM_LBUTTONDBLCLK(){
global _Icon
global _IconFile
_Icon := ""
MouseGetPos, , , , WotsIt
ChangeIcon(WotsIt)
MsgBox, 8227, Choose action, Icon # %_Icon%`nResource file: %_IconFile%`n==========================================`nDo you want to change just the tray icon or re-build the whole Gui?`n(Yes to change the tray`, No to rebuild the Gui`, Cancel to do nothing)
IfMsgBox Yes
{
Menu, Tray, Icon, %_IconFile%, %_Icon%
}
Else IfMsgBox No
{
Gui, Destroy
Gosub BuildGUI
}
Return
}
ChangeIcon(WotsIt)
{
global _Icon
Loop
{
_Icon := SubStr(WotsIt, StrLen(WotsIt), 1) . _Icon
WotsIt := SubStr(WotsIt, 1, StrLen(WotsIt) - 1)
If !InStr("0123456789",SubStr(WotsIt, StrLen(WotsIt), 1))
Break
}
If InStr("13579",SubStr(_Icon, StrLen(_Icon), 1)) ;if it's odd....
_Icon := Floor((_Icon + 1) / 2)
Else
_Icon := Floor(_Icon / 2)
Return
}
BuildGUI:
{
Ypos := 5
Xoffset := 5
Menu, Tray, Icon, %_IconFile%, %_Icon%
Loop
{
If (A_Index > _IconsNum)
Break
If (Mod(A_Index, _MaxColItems) = 1 And A_Index > _MaxColItems)
{
Xoffset := Xoffset + 60
Ypos := 5
}
Gui, Add, Text, x%Xoffset% y%Ypos%, %A_Index%
Gui, Add, Pic, xp+20 yp Icon%A_Index%, %_IconFile%
Ypos := Ypos + 40
}
Gui, Show, +AutoSize, %_IconFile% Icons
Return
}
GuiClose:
ExitApp
by setting here a different path+filename one can explore and test the effect of any open Icon resource.
Just change the top lines after the #SingleInstance directive:
Code:
If ( A_OSType = "WIN32_WINDOWS" )
_IconFile = %A_WinDir%\system\shell32.dll
Else
_IconFile = %A_WinDir%\system32\shell32.dll
like this:
Code:
_IconFile = somedir\somepath\somefile.dll ;or .EXE or whatever
_______________________________________________________________________________________
Edit:
- forgot to set the adjustment to screen size in the BuildGui loop. Now it's OK
- Changed MsgBox string. Now displays choosed Icon # and current resource file