Here's my version of the script. The empty bin tray menu is now grayed out when the bin is empty, the tooltip now has both size and number of files, and the desktop icon can be removed.
A
link to the help thread.
Code:
; ------------------------------------------------------------------------------
; http://www.autohotkey.com/forum/topic21057.html
; ------------------------------------------------------------------------------
#Persistent
#SingleInstance, Force
SplitPath, A_ScriptDir, ScriptName
PostMessage, 0x111, 28931,,, ahk_class Progman ; Refresh desktop
Menu, Tray, NoStandard
Menu, Tray, Add, Open Bin, OpenBin
Menu, Tray, Default, Open Bin
Menu, Tray, Add, Desktop Icon, ShowIcon
Menu, Tray, Add, Empty Bin, EmptyBin
Menu, Tray, Add, Exit
; ---Thanks TLM - http://www.autohotkey.com/forum/viewtopic.php?p=278288#278288
; 1 = Hide Icon
; 0 = Show Icon
RegRead, rbStatClas, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu, {645FF040-5081-101B-9F08-00AA002F954E}
RegRead, rbStatNew, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel, {645FF040-5081-101B-9F08-00AA002F954E}
If ((rbStatClas = 1) || (rbStatNew = 1))
{
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu, {645FF040-5081-101B-9F08-00AA002F954E}, 1
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel, {645FF040-5081-101B-9F08-00AA002F954E}, 1
}
Else If ((rbStatClas = 0) || (rbStatNew = 0))
{
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu, {645FF040-5081-101B-9F08-00AA002F954E}, 0
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel, {645FF040-5081-101B-9F08-00AA002F954E}, 0
}
Else
{
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu, {645FF040-5081-101B-9F08-00AA002F954E}, 0
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel, {645FF040-5081-101B-9F08-00AA002F954E}, 0
rbStatClas = 0
rbStatNew = 0
}
; ---Check or UnCheck Desktop Icon menu item
Menu, Tray, % (((rbStatClas = 0) || (rbStatNew = 0)) ? "Check" : "UnCheck"), Desktop Icon
Menu, Tray, % (((rbStatClas = 1) || (rbStatNew = 1)) ? "UnCheck" : "Check"), Desktop Icon
SetTimer, Recycle, 5000
Recycle:
Objects =
i =
DriveGet, DriveList, List, Fixed
Loop, Parse, DriveList
Objects += Recycled(A_LoopField . ":\")
Menu, Tray, Icon, Shell32.DLL, % (Objects > 0 ? 33 : 32)
Menu, Tray, Tip, % (Objects = 0
? "Empty"
: (Objects != 1
? Objects " files `n" (i>1000
? Round(i/1000,2) " MB"
: Round(i,2) " kB")
: Objects " file`n" (i>1000
? Round(i/1000,2) " MB"
: Round(i,2) " kB")))
Menu, Tray, % (Objects = 0 ? "Disable" : "Enable"), Empty Bin
Return
OpenBin:
Run, ::{645FF040-5081-101B-9F08-00AA002F954E}
Return
EmptyBin:
FileRecycleEmpty
; SoundPlay, %A_WinDir%\Media\recycle.wav
Return
ShowIcon:
Menu, Tray, ToggleCheck, Desktop Icon
If ((rbStatClas = 0) || (rbStatNew = 0))
GoSub, GetPos
GoSub, GetPos
rbStatNew := (rbStatNew = 1) ? 0 : 1
rbStatClas := (rbStatClas = 1) ? 0 : 1
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu, {645FF040-5081-101B-9F08-00AA002F954E}, %rbStatClas%
RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel, {645FF040-5081-101B-9F08-00AA002F954E}, %rbStatNew%
PostMessage, 0x111, 28931,,, ahk_class Progman
If ((rbStatClas = 0) || (rbStatNew = 0))
{
If ((!a) && (!b))
{
GoSub, GetPos
IniRead, a, %A_Temp%\%ScriptName%.ini, Settings, x
IniRead, b, %A_Temp%\%ScriptName%.ini, Settings, y
}
SetPos(i,a,b)
}
Return
Exit:
If ((a) && (b))
{
IniWrite, %a%, %A_Temp%\%ScriptName%.ini, Settings, x
IniWrite, %b%, %A_Temp%\%ScriptName%.ini, Settings, y
}
ExitApp
Return
Recycled(drv="") {
IfEqual, drv,, EnvGet, drv, HomeDrive
VarSetCapacity( Rec, 64 )
DllCall("shell32.dll\SHQueryRecycleBinA", Str, drv, UInt, &Rec)
Global i += Abs(NumGet( Rec, 4, "Int64" )/1000)
Return, NumGet( &Rec, 12 )
}
; http://www.autohotkey.com/forum/viewtopic.php?t=8376
SetPos(i,x,y) {
SendMessage, 0x1000+15, i, (y << 16 ) | x, SysListView321
, Program Manager ahk_class Progman
}
; http://www.autohotkey.com/forum/viewtopic.php?t=10721
GetPos:
RegRead, rbName,HKCR, CLSID\{645FF040-5081-101B-9F08-00AA002F954E} ;Recycle bin name
ControlGet, IconList, List, , SysListView321, Program Manager ahk_class Progman
Loop, Parse, IconList, `n
{
WinGet, pid_target, PID, Program Manager ahk_class Progman
hp_explorer := DllCall( "OpenProcess"
, "uint", 0x18 ; PROCESS_VM_OPERATION|PROCESS_VM_READ
, "int", false
, "uint", pid_target )
remote_buffer := DllCall( "VirtualAllocEx"
, "uint", hp_explorer
, "uint", 0
, "uint", 0x1000
, "uint", 0x1000 ; MEM_COMMIT
, "uint", 0x4 ) ; PAGE_READWRITE
; LVM_GETITEMRECT
; LVIR_BOUNDS
SendMessage, 0x1000+16,% A_Index -1, remote_buffer, SysListView321, Program Manager ahk_class Progman
VarSetCapacity( rect, 16, 0 )
result := DllCall( "ReadProcessMemory"
, "uint", hp_explorer
, "uint", remote_buffer
, "uint", &rect
, "uint", 16
, "uint", 0 )
x := NumGet(rect,0,4)
y := NumGet(rect,4,4)
result := DllCall( "VirtualFreeEx"
, "uint", hp_explorer
, "uint", remote_buffer
, "uint", 0
, "uint", 0x8000 )
result := DllCall( "CloseHandle", "uint", hp_explorer )
; Get location of recycle bin
n := SubStr(A_LoopField, 1, InStr(A_LoopField, A_Tab)-1)
If n = %rbName%
{
a := x
b := y
i := A_Index-1
}
}
Return