Esempio n. 1
0
        protected override bool RunDialog(IntPtr hWndOwner)
        {
            IntPtr zero = IntPtr.Zero;
            bool   flag = false;

            NativeMethods.SHGetSpecialFolderLocation(hWndOwner, (int)this.rootFolder, ref zero);
            if (zero == IntPtr.Zero)
            {
                NativeMethods.SHGetSpecialFolderLocation(hWndOwner, 0, ref zero);
                if (zero == IntPtr.Zero)
                {
                    throw new InvalidOperationException("FolderBrowserDialogNoRootFolder");
                }
            }
            int num = 0x40;

            if (!this.showNewFolderButton)
            {
                num += 0x200;
            }

            IntPtr pidl    = IntPtr.Zero;
            IntPtr hglobal = IntPtr.Zero;
            IntPtr pszPath = IntPtr.Zero;

            try
            {
                NativeMethods.BROWSEINFO lpbi = new NativeMethods.BROWSEINFO();
                hglobal             = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize));
                pszPath             = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize));
                this.callback       = new BrowseCallbackProc(this.FolderBrowserDialog_BrowseCallbackProc);
                lpbi.pidlRoot       = zero;
                lpbi.hwndOwner      = hWndOwner;
                lpbi.pszDisplayName = hglobal;
                lpbi.lpszTitle      = this.descriptionText;
                lpbi.ulFlags        = num;
                lpbi.lpfn           = this.callback;
                lpbi.lParam         = IntPtr.Zero;
                lpbi.iImage         = 0;
                pidl = NativeMethods.SHBrowseForFolder(lpbi);
                if (pidl != IntPtr.Zero)
                {
                    NativeMethods.SHGetPathFromIDList(pidl, pszPath);
                    this.selectedPathNeedsCheck = true;
                    this.selectedPath           = Marshal.PtrToStringAuto(pszPath);
                    flag = true;
                }
            }
            finally
            {
                NativeMethods.IMalloc sHMalloc = GetSHMalloc();
                sHMalloc.Free(zero);
                if (pidl != IntPtr.Zero)
                {
                    sHMalloc.Free(pidl);
                }
                if (pszPath != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pszPath);
                }
                if (hglobal != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(hglobal);
                }
                this.callback = null;
            }
            return(flag);
        }
Esempio n. 2
0
 public static extern IntPtr SHBrowseForFolder(ref NativeMethods.BROWSEINFO lpbi);