 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
dashifen
Joined: 12 Jul 2007 Posts: 3
|
Posted: Thu Jul 12, 2007 4:32 pm Post subject: Recycling Bin in System Tray |
|
|
So, I've been hunting around the web for a while looking for a program that can put a recycling bin icon in my system tray. I'd like it to have both a empty and non-empty icon that would, clearly, switch when I delete something. I ran into this thread here where the early posters determined a way to get the empty/non-empty status of the bin. Also from that thread, I can cobble together a way to empty the bin when clicking on it or, perhaps preferred, a menu with an open and empty option so that I can get into the bin when I need to.
But, I'm not sure how to change the system tray icon for a AHK script. I know you can change it from the "H" icon to another one, but can you chance the state of that icon after the script is running somehow? If so, how?
If you're wondering, I have this hatred of icons on my desktop. It's always bugged me that My Computer, My Documents, etc. are all available from the start menu (or just Windows Explorer) but the Recycling Bin seems like it wasn't invited to the party. I'd love to get rid of the Recycing Bin's icon on my desktop, but I do still want to use the bin for that slim chance that I delete a file but want to recover it.
Thus, if you all can help me switch a running AHK script's system tray icon, I think I can write the rest of the system. And, if not, I'll just get more help here. I've been meaning to do more with AHK for some time now, too.
Thanks all! |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6843
|
Posted: Thu Jul 12, 2007 4:46 pm Post subject: |
|
|
| Code: | #Persistent
Menu, Tray, Icon, Shell32.DLL, 33 |
Try it  |
|
| Back to top |
|
 |
dashifen
Joined: 12 Jul 2007 Posts: 3
|
Posted: Fri Jul 13, 2007 7:21 pm Post subject: |
|
|
Awesome .. I never realized that you could run that and change the icon after you did it the first time. Now I feel dumb. Anyway, combined with code that (admittedly) I don't fully understand from the thread I linked in my original post above, here's what I've got so far.
Purpose: to create a small application that sits only in the system tray and provides the ability to manipulate the recycling bin in two ways: to open it either from a context menu or by double-clicking the icon and to empty it from the context menu. Exiting the application should also be possible from the context menu.
And, here's the solution:
| Code: |
#Persistent
Menu, Tray, NoStandard
Menu, Tray, Add, Open Bin, OpenBin
Menu, Tray, Default, Open Bin
Menu, Tray, Add, Empty Bin, EmptyBin
Menu, Tray, Add, Exit
Loop {
Objects = 0
DriveGet, DriveList, List, Fixed
Loop PARSE, DriveList
Objects += Recycled(A_LoopField . ":\")
if Objects > 0
Menu, Tray, Icon, Shell32.DLL, 33
else
Menu, Tray, Icon, Shell32.DLL, 32
tooltip = %Objects% file
if Objects != 1
tooltip = %tooltip%s
Menu, Tray, Tip, %tooltip%
Sleep 5000
}
Return
Recycled(drv="") {
IfEqual, drv,, EnvGet, drv, HomeDrive
VarSetCapacity(rec, 64)
DllCall("shell32.dll\SHQueryRecycleBinA", Str, drv, UInt, &rec)
Return ExtractInteger(rec, 12, false, 4)
}
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4) {
Loop %pSize% ; Build the integer by adding up its bytes.
result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result
return -(0xFFFFFFFF - result + 1)
}
OpenBin:
Run, ::{645FF040-5081-101B-9F08-00AA002F954E}
Return
EmptyBin:
FileRecycleEmpty
SoundPlay, %A_WinDir%\Media\recycle.wav
Menu, Tray, Icon, Shell32.DLL, 32
Menu, Tray, Tip, 0 files
Return
Exit:
ExitApp
|
I guess, if anyone has anything to add or fix in the code, feel free to let me know. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6843
|
Posted: Sat Jul 14, 2007 6:15 am Post subject: |
|
|
ExtractInteger() is redundant.. You may replace it with the built-in function NumGet().
| Code: | Recycled(drv="") {
IfEqual, drv,, EnvGet, drv, HomeDrive
VarSetCapacity( Rec, 64 )
DllCall("shell32.dll\SHQueryRecycleBinA", Str, drv, UInt, &Rec)
Return NumGet( &Rec, 12 )
} |
 |
|
| Back to top |
|
 |
dashifen
Joined: 12 Jul 2007 Posts: 3
|
Posted: Fri Jul 20, 2007 3:39 pm Post subject: |
|
|
| Good suggestion. Thanks! |
|
| Back to top |
|
 |
dandersahn
Joined: 06 Oct 2008 Posts: 10
|
Posted: Mon Oct 06, 2008 7:32 pm Post subject: |
|
|
Can anyone tell me how to modify this function to return total size of the items in the bins instead of the number of items?
| Code: | Recycled(drv="") {
IfEqual, drv,, EnvGet, drv, HomeDrive
VarSetCapacity( Rec, 64 )
DllCall("shell32.dll\SHQueryRecycleBinA", Str, drv, UInt, &Rec)
Return NumGet( &Rec, 12 )
} |
From the documentation here, it appears that it should be a small modification to that code.
Thanks. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6843
|
Posted: Mon Oct 06, 2008 7:59 pm Post subject: |
|
|
| dandersahn wrote: | | Can anyone tell me how to modify this function to return total size of the items in the bins instead of the number of items? |
| Code: | Recycled(drv="") {
IfEqual, drv,, EnvGet, drv, HomeDrive
VarSetCapacity( Rec, 64 )
DllCall("shell32.dll\SHQueryRecycleBinA", Str, drv, UInt, &Rec)
Return NumGet( Rec, 4, "Int64" )
} |
_________________ Suresh Kumar A N |
|
| Back to top |
|
 |
dandersahn
Joined: 06 Oct 2008 Posts: 10
|
Posted: Mon Oct 13, 2008 7:25 pm Post subject: |
|
|
| Thanks. That worked perfectly. |
|
| Back to top |
|
 |
Voltron43
Joined: 27 Mar 2009 Posts: 44 Location: Dublin, IE
|
Posted: Wed Jul 01, 2009 8:44 pm Post subject: |
|
|
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 |
_________________ My Scripts |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|