ComputerBrowser.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; public class ComputerBrowser { private FolderBrowserFolder _startLocation = FolderBrowserFolder.NetworkNeighborhood; private BrowseInfos _options = BrowseInfos.BrowseForComputer; private static readonly int MAX_PATH; private string _title; private string _displayName; private string _path; static ComputerBrowser() { MAX_PATH = 260; } public bool ShowDialog() { return ShowDialog(null); } public bool ShowDialog(IWin32Window owner) { _path = string.Empty; IntPtr handle; IntPtr zero = IntPtr.Zero; if (owner != null) handle = owner.Handle; else handle = UnmanagedMethods.GetActiveWindow(); UnmanagedMethods.SHGetSpecialFolderLocation(handle, (int)_startLocation, ref zero); if (zero == IntPtr.Zero) return false; int num = (int)_options; if ((num & 0x40) != 0) Application.OleRequired(); IntPtr pidl = IntPtr.Zero; try { BrowseInfo lpbi = new BrowseInfo();
Unmanaged.cs:
using System; using System.Runtime.InteropServices; namespace ActivityMonitor.Monitor.Utils { internal delegate int BrowseCallBackProc(IntPtr hwnd, int msg, IntPtr lp, IntPtr wp); [StructLayout(LayoutKind.Sequential)] internal struct BrowseInfo { public IntPtr hwndOwner; public IntPtr pidlRoot; [MarshalAs(UnmanagedType.LPTStr)] public string displayName; [MarshalAs(UnmanagedType.LPTStr)] public string title; public int flags; [MarshalAs(UnmanagedType.FunctionPtr)] public BrowseCallBackProc callback; public IntPtr lparam; } [ComImport] [Guid("00000002-0000-0000-C000-000000000046")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IMalloc { [PreserveSig] IntPtr Alloc(IntPtr cb); [PreserveSig] IntPtr Realloc(IntPtr pv, IntPtr cb); [PreserveSig] void Free(IntPtr pv); [PreserveSig] IntPtr GetSize(IntPtr pv); [PreserveSig] int DidAlloc(IntPtr pv); [PreserveSig] void HeapMinimize(); }
source share