//Zero based public RECT GetItemRECT(int index) { if (index < 0 || index >= Count) throw new SUIException("Index is out of range!"); RECT rec = new RECT(); IntPtr ptr = IntPtr.Zero; try { ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(RECT))); SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETITEMRECT, index, ptr); rec = (RECT)Marshal.PtrToStructure(ptr, typeof(RECT)); } catch (Exception e) { throw new SUIException("Error getting item rectangle!", e); } finally { Marshal.FreeCoTaskMem(ptr); } return rec; }
//Zero based index public RECT GetItemRect(int index) { RECT rect = new RECT(); int processId = 0; SUIWinAPIs.GetWindowThreadProcessId(WindowHandle, ref processId); IntPtr processHandle = SUIWinAPIs.OpenProcess(SUIMessage.PROCESS_ALL_ACCESS, false, processId); IntPtr data = SUIWinAPIs.VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(rect), SUIMessage.MEM_COMMIT, SUIMessage.PAGE_READWRITE); IntPtr ptrLvi = IntPtr.Zero; try { ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(rect)); Marshal.StructureToPtr(rect, ptrLvi, false); IntPtr numReaded = new IntPtr(); SUIWinAPIs.WriteProcessMemory(processHandle, data, ptrLvi, Marshal.SizeOf(rect), out numReaded); SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.HDM_GETITEMRECT, new IntPtr(index), data); SUIWinAPIs.ReadProcessMemory(processHandle, data, ptrLvi, Marshal.SizeOf(rect), out numReaded); rect = (RECT)Marshal.PtrToStructure(ptrLvi, rect.GetType()); } catch (Exception e) { throw new SUIException("Error getting rectangle of header item!", e); } finally { SUIWinAPIs.VirtualFreeEx(processHandle, data, Marshal.SizeOf(rect), SUIMessage.MEM_RESERVE); Marshal.FreeHGlobal(ptrLvi); SUIWinAPIs.CloseHandle(processHandle); } return rect; }
public static extern void CopyMemoryRECT(ref RECT destRect, IntPtr sourceAddr, int numberOfBytes);
public static extern bool ClientToScreen(IntPtr win,out RECT rect);