Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 78 additions & 84 deletions DeskHider.ahk
Original file line number Diff line number Diff line change
@@ -1,107 +1,101 @@
#SingleInstance, Force ; Optional: Prevent multiple instances
#Persistent ; Optional: Keep the script running


; System tray menu setup
; System tray menu setup
Menu, Tray, NoStandard
Menu, Tray, Add, Exit , QuitScript


; Set a custom tooltip for the system tray icon
Menu, Tray, Tip , DeskHider

; Specify the main script filename for compilation:
#Include C:\Users\Ian Divinagracia\Documents\AutoHotkey\Portable\DeskHider.ahk



; --- Double-click trigger on desktop ---
#If IsDesktopUnderMouse()
~LButton::
LButton_presses++
if (LButton_presses=2)
if (!IsObject(GetDesktopIconUnderMouse()) or DesktopIconsIsShow=0)
DesktopIconsIsShow:=HideOrShowDesktopIcons()
SetTimer, KeyLButton, -300
LButton_presses++
if (LButton_presses=2) {
if (!IsObject(GetDesktopIconUnderMouse())) {
ToggleDesktopIcons()
}
}
SetTimer, KeyLButton, -300
return

KeyLButton:
LButton_presses := 0
LButton_presses := 0
return
#If

IsDesktopUnderMouse()
{
MouseGetPos, , , OutputVarWin
WinGetClass, OutputVarClass, % "ahk_id" OutputVarWin
if (OutputVarClass="WorkerW" or OutputVarClass="Progman")
return, 1
else
return, 0
}

HideOrShowDesktopIcons()
{
ControlGet, OutputVarHwnd, Hwnd,, SysListView321, ahk_class WorkerW
if (OutputVarHwnd="")
ControlGet, OutputVarHwnd, Hwnd,, SysListView321, ahk_class Progman
; --- Functions ---

if (DllCall("IsWindowVisible", UInt, OutputVarHwnd))
{
WinHide, ahk_id %OutputVarHwnd%
return, 0
}
else
{
WinShow, ahk_id %OutputVarHwnd%
return, 1
}
IsDesktopUnderMouse() {
MouseGetPos, , , hwnd
WinGetClass, class, % "ahk_id" hwnd
return (class="WorkerW" or class="Progman")
}
#If

; New function: toggles via WM_COMMAND 0x7402
ToggleDesktopIcons() {
hwnd := GetDesktopListView()
if hwnd {
PostMessage, 0x111, 0x7402, 0, , ahk_id %hwnd%
}
}

GetDesktopIconUnderMouse() {
static MEM_COMMIT := 0x1000, MEM_RELEASE := 0x8000, PAGE_ReadWRITE := 0x04
, PROCESS_VM_OPERATION := 0x0008, PROCESS_VM_READ := 0x0010
, LVM_GETITEMCOUNT := 0x1004, LVM_GETITEMRECT := 0x100E
GetDesktopListView() {
progman := WinExist("ahk_class Progman")
ControlGet, hwnd, Hwnd,, SHELLDLL_DefView1, ahk_id %progman%
if hwnd
return hwnd

winList := []
WinGet, winList, List, ahk_class WorkerW
Loop % winList {
thisHwnd := winList%A_Index%
ControlGet, hwnd, Hwnd,, SHELLDLL_DefView1, ahk_id %thisHwnd%
if hwnd
return hwnd
}
return 0
}

Icon := ""
MouseGetPos, x, y, hwnd
if not (hwnd = WinExist("ahk_class Progman") || hwnd = WinExist("ahk_class WorkerW"))
return
ControlGet, hwnd, HWND, , SysListView321
if not WinExist("ahk_id" hwnd)
return
WinGet, pid, PID
if (hProcess := DllCall("OpenProcess" , "UInt", Process_VM_OPERATION|Process_VM_Read, "Int", false, "UInt", pid)) {
VarSetCapacity(iCoord, 16)
SendMessage, %LVM_GETITEMCOUNT%, 0, 0
loop, %ErrorLevel% {
pItemCoord := DllCall("VirtualAllocEx", "Ptr", hProcess, "Ptr", 0, "UInt", 16, "UInt", MEM_COMMIT, "UInt", PAGE_ReadWRITE)
SendMessage, %LVM_GETITEMRECT%, % A_Index-1, %pItemCoord%
DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", pItemCoord, "Ptr", &iCoord, "UInt", 16, "UInt", 0)
DllCall("VirtualFreeEx", "Ptr", hProcess, "Ptr", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE)
left := NumGet(iCoord, 0, "Int")
top := NumGet(iCoord, 4, "Int")
Right := NumGet(iCoord, 8, "Int")
bottom := NumGet(iCoord, 12, "Int")
if (left < x and x < Right and top < y and y < bottom) {
ControlGet, list, List
RegExMatch(StrSplit(list, "`n")[A_Index], "O)(.*)\t(.*)\t(.*)\t(.*)", Match)
Icon := {left:left, top:top, Right:Right, bottom:bottom
, name:Match[1], size:Match[2], type:Match[3]
; Delete extraneous date characters (https://goo.gl/pMw6AM):
; - Unicode LTR (Left-to-Right) mark (0x200E = 8206)
; - Unicode RTL (Right-to-Left) mark (0x200F = 8207)
, date:RegExReplace(Match[4], A_IsUnicode ? "[\x{200E}-\x{200F}]" : "\?")}
break
}
}
DllCall("CloseHandle", "Ptr", hProcess)
}
return Icon
GetDesktopIconUnderMouse() {
; (kept as-is from your script)
static MEM_COMMIT := 0x1000, MEM_RELEASE := 0x8000, PAGE_ReadWRITE := 0x04
, PROCESS_VM_OPERATION := 0x0008, PROCESS_VM_READ := 0x0010
, LVM_GETITEMCOUNT := 0x1004, LVM_GETITEMRECT := 0x100E

Icon := ""
MouseGetPos, x, y, hwnd
if not (hwnd = WinExist("ahk_class Progman") || hwnd = WinExist("ahk_class WorkerW"))
return
ControlGet, hwnd, HWND, , SysListView321
if not WinExist("ahk_id" hwnd)
return
WinGet, pid, PID
if (hProcess := DllCall("OpenProcess" , "UInt", Process_VM_OPERATION|Process_VM_Read, "Int", false, "UInt", pid)) {
VarSetCapacity(iCoord, 16)
SendMessage, %LVM_GETITEMCOUNT%, 0, 0
loop, %ErrorLevel% {
pItemCoord := DllCall("VirtualAllocEx", "Ptr", hProcess, "Ptr", 0, "UInt", 16, "UInt", MEM_COMMIT, "UInt", PAGE_ReadWRITE)
SendMessage, %LVM_GETITEMRECT%, % A_Index-1, %pItemCoord%
DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", pItemCoord, "Ptr", &iCoord, "UInt", 16, "UInt", 0)
DllCall("VirtualFreeEx", "Ptr", hProcess, "Ptr", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE)
left := NumGet(iCoord, 0, "Int")
top := NumGet(iCoord, 4, "Int")
right := NumGet(iCoord, 8, "Int")
bottom := NumGet(iCoord, 12, "Int")
if (left < x and x < right and top < y and y < bottom) {
ControlGet, list, List
RegExMatch(StrSplit(list, "`n")[A_Index], "O)(.*)\t(.*)\t(.*)\t(.*)", Match)
Icon := {left:left, top:top, right:right, bottom:bottom
, name:Match[1], size:Match[2], type:Match[3]
, date:RegExReplace(Match[4], A_IsUnicode ? "[\x{200E}-\x{200F}]" : "\?")}
break
}
}
DllCall("CloseHandle", "Ptr", hProcess)
}
return Icon
}


; QuitScript subroutine
QuitScript:
ExitApp
Return
Return
Binary file modified DeskHider.exe
Binary file not shown.