Beispiel #1
0
        ///<summary>Shows the common folder dialog.</summary>
        ///<param name="hWndOwner">The owner of the folder dialog.</param>
        ///<returns>True when successful, false otherwise.</returns>
        protected bool RunDialog(IntPtr hWndOwner)
        {
            BROWSEINFO udtBI = new BROWSEINFO();
            IntPtr     lpIDList;

            udtBI.pIDLRoot     = IntPtr.Zero;
            udtBI.lpfnCallback = IntPtr.Zero;
            // set the owner of the window
            udtBI.hWndOwner = hWndOwner;
            // set the title of the window
            udtBI.lpszTitle = Title;
            // set the flags of the dialog
            udtBI.ulFlags = (int)BrowseFor;
            // create string buffer for display name
            StringBuilder buffer = new StringBuilder(MAX_PATH);

            buffer.Length        = MAX_PATH;
            udtBI.pszDisplayName = buffer.ToString();
            // show the 'Browse for folder' dialog
            lpIDList = SHBrowseForFolder(ref udtBI);
            // examine the result
            if (!lpIDList.Equals(IntPtr.Zero))
            {
                if (BrowseFor == BrowseForTypes.Computers)
                {
                    m_Selected = udtBI.pszDisplayName.Trim();
                }
                else
                {
                    StringBuilder path = new StringBuilder(MAX_PATH);
                    // get the path from the IDList
                    SHGetPathFromIDList(lpIDList, path);
                    m_Selected = path.ToString();
                }
                // free the block of memory
                CoTaskMemFree(lpIDList);
                return(true);
            }
            else
            {
                // user pressed cancel
                return(false);
            }
        }
Beispiel #2
0
 private static extern IntPtr SHBrowseForFolder(ref BROWSEINFO lpbi);