private bool _enum(IntPtr hMonitor, IntPtr hdcMonitor, ref W32RECT lpRect, IntPtr lParamIn) { MemPtr lParam = lParamIn; Add(new MonitorInfo(hMonitor, lParam.IntAt(0L))); //string[] ss = GetPhysicalMonitorNames(hMonitor); lParam.IntAt(0L) += 1; return(true); }
/// <summary> /// Get volume disk extents for volumes that may or may not span more than one physical drive. /// </summary> /// <param name="devicePath">The device path of the volume.</param> /// <returns>An array of DiskExtent structures.</returns> /// <remarks></remarks> public static DiskExtent[] GetDiskExtentsFor(string devicePath) { DiskExtent[] deOut = null; MemPtr inBuff = new MemPtr(); int inSize; IntPtr file; int h = 0; var de = new DISK_EXTENT(); var ve = new VOLUME_DISK_EXTENTS(); bool r; file = IO.CreateFile(devicePath, IO.GENERIC_READ, IO.FILE_SHARE_READ | IO.FILE_SHARE_WRITE, IntPtr.Zero, IO.OPEN_EXISTING, IO.FILE_ATTRIBUTE_NORMAL, IntPtr.Zero); if (file == DevProp.INVALID_HANDLE_VALUE) { return(null); } uint arb = 0; inSize = Marshal.SizeOf(de) + Marshal.SizeOf(ve); inBuff.Length = inSize; r = DeviceIoControl(file, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, IntPtr.Zero, 0, inBuff, (uint)inSize, ref arb, IntPtr.Zero); if (!r && User32.GetLastError() == ERROR_MORE_DATA) { inBuff.Length = inSize * inBuff.IntAt(0L); r = DeviceIoControl(file, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, IntPtr.Zero, 0, inBuff, (uint)inSize, ref arb, IntPtr.Zero); } if (!r) { inBuff.Free(); User32.CloseHandle(file); return(null); } User32.CloseHandle(file); ve = VOLUME_DISK_EXTENTS.FromPtr(inBuff); inBuff.Free(); h = 0; deOut = new DiskExtent[ve.Extents.Length]; foreach (var currentDe in ve.Extents) { de = currentDe; deOut[h].PhysicalDevice = de.DiskNumber; deOut[h].Space = de.Space; deOut[h].Size = de.ExtentLength; deOut[h].Offset = de.StartingOffset; h += 1; } return(deOut); }
public static VOLUME_DISK_EXTENTS FromPtr(IntPtr ptr) { VOLUME_DISK_EXTENTS FromPtrRet = default; var ve = new VOLUME_DISK_EXTENTS(); int cb = Marshal.SizeOf <DISK_EXTENT>(); MemPtr m = ptr; int i; ve.NumberOfExtents = m.IntAt(0L); ve.Space = m.IntAt(1L); ve.Extents = new DISK_EXTENT[ve.NumberOfExtents]; m = m + 8; var c = ve.NumberOfExtents; for (i = 0; i < c; i++) { ve.Extents[i] = m.ToStruct <DISK_EXTENT>(); m = m + cb; } FromPtrRet = ve; return(FromPtrRet); }
/// <summary> /// Refresh the contents of the directory. /// </summary> public void Refresh(StandardIcons?iconSize = default) { if (iconSize is null) { iconSize = _IconSize; } _Children.Clear(); _Folders.Clear(); FileObject fobj; DirectoryObject dobj; IShellItem shitem = null; IShellFolder shfld; IEnumIDList enumer; MemPtr mm; var mm2 = new MemPtr(); string fp; string pname = ParsingName; if (pname is object && pname.LastIndexOf(@"\") == pname.Length - 1) { pname = pname.Substring(0, pname.Length - 1); } var argriid = Guid.Parse(ShellIIDGuid.IShellItem); var res = NativeShell.SHCreateItemFromParsingName(ParsingName, IntPtr.Zero, ref argriid, ref shitem); _IconSize = (StandardIcons)iconSize; int?argiIndex = null; _Icon = Resources.GetFileIcon(ParsingName, FileObject.StandardToSystem(_IconSize), iIndex: ref argiIndex); _IconImage = Resources.GetFileIconWPF(ParsingName, FileObject.StandardToSystem(_IconSize)); if (res == HResult.Ok) { var argbhid = Guid.Parse(ShellBHIDGuid.ShellFolderObject); var argriid1 = Guid.Parse(ShellIIDGuid.IShellFolder2); shitem.BindToHandler(IntPtr.Zero, ref argbhid, ref argriid1, out shfld); _SysInterface = shfld; shfld.EnumObjects(IntPtr.Zero, ShellFolderEnumerationOptions.Folders | ShellFolderEnumerationOptions.IncludeHidden | ShellFolderEnumerationOptions.NonFolders | ShellFolderEnumerationOptions.InitializeOnFirstNext, out enumer); if (enumer != null) { var glist = new List <string>(); uint cf; var x = IntPtr.Zero; string pout; // mm.AllocCoTaskMem((MAX_PATH * 2) + 8) mm2.Alloc(NativeShell.MAX_PATH * 2 + 8); do { cf = 0U; mm2.ZeroMemory(0L, NativeShell.MAX_PATH * 2 + 8); res = enumer.Next(1U, out x, out cf); mm = x; if (cf == 0L) { break; } if (res != HResult.Ok) { break; } mm2.IntAt(0L) = 2; // shfld.GetAttributesOf(1, mm, attr) shfld.GetDisplayNameOf(mm, (uint)ShellItemDesignNameOptions.ParentRelativeParsing, mm2.handle); MemPtr inv; if (IntPtr.Size == 4) { inv = (IntPtr)mm2.IntAt(1L); } else { inv = (IntPtr)mm2.LongAt(1L); } if (inv.Handle != IntPtr.Zero) { if (inv.CharAt(0L) != '\0') { fp = (string)inv; var lpInfo = new SHFILEINFO(); // Dim sgfin As ShellFileGetAttributesOptions = 0, // sgfout As ShellFileGetAttributesOptions = 0 int iFlags = User32.SHGFI_PIDL | User32.SHGFI_ATTRIBUTES; lpInfo.dwAttributes = 0; x = User32.SHGetItemInfo(mm.Handle, 0, ref lpInfo, Marshal.SizeOf(lpInfo), iFlags); if (ParsingName is object) { if (pname.LastIndexOf(@"\") == pname.Length - 1) { pname = pname.Substring(0, pname.Length - 1); } pout = $@"{pname}\{fp}"; } else { pout = fp; } if (lpInfo.dwAttributes == 0) { lpInfo.dwAttributes = (int)FileTools.GetFileAttributes(pout); } FileAttributes drat = (FileAttributes)(int)(lpInfo.dwAttributes); if ((lpInfo.dwAttributes & (int)FileAttributes.Directory) == (int)FileAttributes.Directory && !File.Exists(pout)) { dobj = new DirectoryObject(pout, _IsSpecial, false); dobj.Parent = this; dobj.IconSize = _IconSize; _Children.Add(dobj); _Folders.Add(dobj); } else { fobj = new FileObject(pout, _IsSpecial, true, _IconSize); fobj.Parent = this; fobj.IconSize = _IconSize; _Children.Add(fobj); } } inv.CoTaskMemFree(); } mm.CoTaskMemFree(); }while (res == HResult.Ok); mm2.Free(); } } OnPropertyChanged(nameof(Folders)); OnPropertyChanged(nameof(Icon)); OnPropertyChanged(nameof(IconImage)); OnPropertyChanged(nameof(IconSize)); OnPropertyChanged(nameof(ParsingName)); OnPropertyChanged(nameof(DisplayName)); }