Beispiel #1
0
            public DialogResult ShowDialog(IWin32Window owner)
            {
                IntPtr handle;
                IntPtr zero = IntPtr.Zero;

                if (owner != null)
                {
                    handle = owner.Handle;
                }
                else
                {
                    handle = System.Design.UnsafeNativeMethods.GetActiveWindow();
                }
                System.Design.UnsafeNativeMethods.Shell32.SHGetSpecialFolderLocation(handle, (int)this.startLocation, ref zero);
                if (zero == IntPtr.Zero)
                {
                    return(DialogResult.Cancel);
                }
                int num = (int)(this.publicOptions | ((FolderNameEditor.FolderBrowserStyles)((int)this.privateOptions)));

                if ((num & 0x40) != 0)
                {
                    Application.OleRequired();
                }
                IntPtr pidl = IntPtr.Zero;

                try
                {
                    System.Design.UnsafeNativeMethods.BROWSEINFO lpbi = new System.Design.UnsafeNativeMethods.BROWSEINFO();
                    IntPtr pszPath = Marshal.AllocHGlobal(MAX_PATH);
                    lpbi.pidlRoot       = zero;
                    lpbi.hwndOwner      = handle;
                    lpbi.pszDisplayName = pszPath;
                    lpbi.lpszTitle      = this.descriptionText;
                    lpbi.ulFlags        = num;
                    lpbi.lpfn           = IntPtr.Zero;
                    lpbi.lParam         = IntPtr.Zero;
                    lpbi.iImage         = 0;
                    pidl = System.Design.UnsafeNativeMethods.Shell32.SHBrowseForFolder(lpbi);
                    if (pidl == IntPtr.Zero)
                    {
                        return(DialogResult.Cancel);
                    }
                    System.Design.UnsafeNativeMethods.Shell32.SHGetPathFromIDList(pidl, pszPath);
                    this.directoryPath = Marshal.PtrToStringAuto(pszPath);
                    Marshal.FreeHGlobal(pszPath);
                }
                finally
                {
                    System.Design.UnsafeNativeMethods.IMalloc sHMalloc = GetSHMalloc();
                    sHMalloc.Free(zero);
                    if (pidl != IntPtr.Zero)
                    {
                        sHMalloc.Free(pidl);
                    }
                }
                return(DialogResult.OK);
            }
 private static System.Design.UnsafeNativeMethods.IMalloc GetSHMalloc()
 {
     System.Design.UnsafeNativeMethods.IMalloc[] ppMalloc = new System.Design.UnsafeNativeMethods.IMalloc[1];
     System.Design.UnsafeNativeMethods.Shell32.SHGetMalloc(ppMalloc);
     return ppMalloc[0];
 }
Beispiel #3
0
 private static System.Design.UnsafeNativeMethods.IMalloc GetSHMalloc()
 {
     System.Design.UnsafeNativeMethods.IMalloc[] ppMalloc = new System.Design.UnsafeNativeMethods.IMalloc[1];
     System.Design.UnsafeNativeMethods.Shell32.SHGetMalloc(ppMalloc);
     return(ppMalloc[0]);
 }