Advertisement
Guest User

Untitled

a guest
May 10th, 2014
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getDeskIconsPos() {
  2.     Critical
  3.     static MEM_COMMIT := 0x1000, PAGE_READWRITE := 0x04, MEM_RELEASE := 0x8000
  4.     static LVM_GETITEMPOSITION := 0x00001010, LVM_SETITEMPOSITION := 0x0000100F, WM_SETREDRAW := 0x000B
  5.  
  6.     ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
  7.     if !hwWindow ; #D mode
  8.         ControlGet, hwWindow, HWND,, SysListView321, A
  9.     IfWinExist ahk_id %hwWindow% ; last-found window set
  10.         WinGet, iProcessID, PID
  11.     hProcess := DllCall("OpenProcess"   , "UInt",   0x438           ; PROCESS-OPERATION|READ|WRITE|QUERY_INFORMATION
  12.                                         , "Int",    FALSE           ; inherit = false
  13.                                         , "ptr",    iProcessID)
  14.     ret := {}
  15.     if hwWindow and hProcess
  16.     {  
  17.         ControlGet, list, list,Col1
  18.         VarSetCapacity(iCoord, 8)
  19.         pItemCoord := DllCall("VirtualAllocEx", "ptr", hProcess, "ptr", 0, "UInt", 8, "UInt", MEM_COMMIT, "UInt", PAGE_READWRITE)
  20.         Loop, Parse, list, `n ;Loop through items in list and get the information from the POINT structures
  21.         {
  22.             SendMessage, %LVM_GETITEMPOSITION%, % A_Index-1, %pItemCoord%
  23.             DllCall("ReadProcessMemory", "ptr", hProcess, "ptr", pItemCoord, "UInt", &iCoord, "UInt", 8, "UIntP", cbReadWritten)
  24.  
  25.             ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
  26.             THE_ITEMNAME := A_LoopField
  27.             THE_X_COORD := NumGet(iCoord,"Int")
  28.             THE_Y_COORD := Numget(iCoord, 4,"Int")
  29.             ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
  30.             if(!ret.HasKey(THE_ITEMNAME))
  31.             {
  32.                 ret[THE_ITEMNAME] := []
  33.             }
  34.             ret[THE_ITEMNAME].Insert({x: THE_X_COORD, y: THE_Y_COORD})
  35.         }
  36.         DllCall("VirtualFreeEx", "ptr", hProcess, "ptr", pItemCoord, "ptr", 0, "UInt", MEM_RELEASE)
  37.     }
  38.     DllCall("CloseHandle", "ptr", hProcess)
  39.     return ret
  40. }
  41.  
  42. ; Example usage
  43.  
  44. icons := getDeskIconsPos()
  45. chromePos := icons["Google Chrome"]
  46. for k, pos in chromePos
  47. {
  48.     msgbox % "Google Chrome.lnk is at X: " pos.x " Y: " pos.y
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement