jeeswg wrote: ↑10 Jul 2018, 00:21
- In response to this:
[x64 & x32 fix] DeskIcons - Get/Set Desktop Icon Positions - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=3529&p=227874#p227874
- Here's a way to get the name of the file under the cursor via Acc:
Code: Select all
;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
;tested on Windows 7
q:: ;Explorer window/Desktop - get name of file under cursor
oAcc := Acc_ObjectFromPoint(vChildID)
MouseGetPos,,, hWnd, vCtlClassNN
WinGetClass, vWinClass, % "ahk_id " hWnd
vText := ""
if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
try vText := oAcc.accValue(vChildID)
else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
try vText := oAcc.accName(vChildID)
MsgBox, % vText
oAcc := ""
return
Hi
jeeswg,
Thank you for your post. Below is a version that returns the name of the icon regardless of where the mouse is positioned over it. This is especially important in configuratitons where
CurrentViewMode > 1 [
Ref], i.e. any configuration other than Medium, Large, and Extra Large Icons. Note that the value returned is not necessarily the name of the file as the post heading indicates. Consider, for example, shortcuts, which can be renamed, and the case where the "Hide extensions for known file types" setting is enabled.
Code: Select all
GetNameOfIconUnderMouse() {
MouseGetPos, , , hwnd, CtrlClass
WinGetClass, WinClass, ahk_id %hwnd%
try if (WinClass = "CabinetWClass" && CtrlClass = "DirectUIHWND3") {
oAcc := Acc_ObjectFromPoint()
Name := Acc_Parent(oAcc).accValue(0)
Name := Name ? Name : oAcc.accValue(0)
} else if (WinClass = "Progman" || WinClass = "WorkerW") {
oAcc := Acc_ObjectFromPoint(ChildID)
Name := ChildID ? oAcc.accName(ChildID) : ""
}
Return Name
}
Here is a self-contained example (including only the required
Acc functions):
Code: Select all
#NoEnv
SetTimer, Timer
Return
Timer:
ToolTip % GetNameOfIconUnderMouse()
Return
Esc::ExitApp
GetNameOfIconUnderMouse() {
MouseGetPos, , , hwnd, CtrlClass
WinGetClass, WinClass, ahk_id %hwnd%
try if (WinClass = "CabinetWClass" && CtrlClass = "DirectUIHWND3") {
oAcc := Acc_ObjectFromPoint()
Name := Acc_Parent(oAcc).accValue(0)
Name := Name ? Name : oAcc.accValue(0)
} else if (WinClass = "Progman" || WinClass = "WorkerW") {
oAcc := Acc_ObjectFromPoint(ChildID)
Name := ChildID ? oAcc.accName(ChildID) : ""
}
Return Name
}
; https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
Acc_Init() {
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "") {
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_Parent(Acc) {
try parent:=Acc.accParent
return parent?Acc_Query(parent):
}
Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
I hope this helps.
- iPhilip