Exemple #1
0
 public static extern IntPtr SHBrowseForFolder(
     ref BROWSEINFO lbpi);
        protected override bool RunDialog( System.IntPtr hwndOwner )
        {
            string m_DisplayName = "";
              string sDisplay;
              IntPtr ptrRet;

              // Get IMalloc interface
              WindowsAPI.SHGetMalloc( out ptrRet );

              Type    mallocType = System.Type.GetType( "IMalloc" );
              IMalloc pMalloc = ( IMalloc )Marshal.GetTypedObjectForIUnknown( ptrRet, mallocType );
              IntPtr  pidlRoot = IntPtr.Zero;

              BROWSEINFO bi = new BROWSEINFO();

              bi.hwndOwner  = hwndOwner;
              bi.pidlRoot   = pidlRoot;     //TODO: Root`s selection
              bi.pszDisplayName = new string( ' ', 256 );
              bi.lpszTitle  = Title;
              bi.ulFlags    = GetFlagsValue();
              bi.lParam     = 0;
              bi.lpfn       = new WindowsAPI.BrowseCallbackProc( this.HookProc );

              IntPtr pidlSelected;
              pidlSelected = WindowsAPI.SHBrowseForFolder( ref bi );
              m_DisplayName = bi.pszDisplayName.ToString();

              // if display name is whitespace then return FAIL
              if( m_DisplayName.Trim() == string.Empty ) return false;

              IShellFolder isf = GetDesktopFolder();

              STRRET ptrDisplayName;
              isf.GetDisplayNameOf( pidlSelected,
            (uint)SHGNO.SHGDN_NORMAL | (uint)SHGNO.SHGDN_FORPARSING,
            out ptrDisplayName );

              WindowsAPI.StrRetToBSTR( ref ptrDisplayName, pidlRoot, out sDisplay );
              m_sFullName = sDisplay;

              if( pidlRoot != IntPtr.Zero )
            pMalloc.Free( pidlRoot );

              if( pidlSelected != IntPtr.Zero )
            pMalloc.Free( pidlSelected );

              Marshal.ReleaseComObject( isf );
              Marshal.ReleaseComObject( pMalloc );

              return true;
        }
   public static extern IntPtr SHBrowseForFolder(
 ref BROWSEINFO lbpi);