; 检测鼠标在何时拖动电脑图标的示例
; 来源:https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62224
#NoEnv

SysGet, SM_CXDRAG, 68
SysGet, SM_CYDRAG, 69
Return

Esc::ExitApp

~LButton::
  MouseGetPos, X0, Y0, hwnd, CtrlClass
  WinGetClass, WinClass, ahk_id %hwnd%
  if IsMouseOverIcon(WinClass, CtrlClass) {
    Items := CreateList(GetSelectedItems(hwnd, WinClass))
    while GetKeyState("LButton", "P") {
      MouseGetPos, X, Y
      if (Abs(X-X0) > SM_CXDRAG || Abs(Y-Y0) > SM_CYDRAG)
        while GetKeyState("LButton", "P")
          ToolTip, % "Dragging " Items
    }
    ToolTip
  }
Return

IsMouseOverIcon(WinClass, CtrlClass) {
  try if (WinClass = "CabinetWClass" && CtrlClass = "DirectUIHWND3") {
    oAcc := Acc_ObjectFromPoint()
    Name := Acc_Parent(oAcc).accValue(0)
    Name := Name ? Name : oAcc.accValue(0)
    Return  Name ? true : false
  } else if (WinClass = "Progman" || WinClass = "WorkerW") {
    oAcc := Acc_ObjectFromPoint(ChildID)
    Return  ChildID ? true : false
  }
}

CreateList(Items) {
  N := Items.MaxIndex()
  if (N = 1)
    List := Items[1]
  else if (N > 1) {
    List := N " items:`n"
    for each, item in Items
      List .= each ". " item "`n"
  }
  Return List
}

GetSelectedItems(hwnd, WinClass) {
  Items := []
  if (WinClass = "CabinetWClass") {
    for window in ComObjCreate("Shell.Application").Windows
      if (window.hwnd = hwnd)
        for item in window.Document.SelectedItems
          Items.Push(item.Name)
  } else if (WinClass = "Progman" || WinClass = "WorkerW") {
    ControlGet, hwnd, HWND, , SysListView321, ahk_id %hwnd%
    ControlGet, Files, List, Selected Col1, , ahk_id %hwnd%
    Loop, Parse, Files, `n
      Items.Push(A_LoopField)
  }
  Return Items
}

; 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)
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。