예제 #1
0
        public ShellDebuggerModel(ShellDebuggerForm form)
        {
            this.Form = form;

            //  Get the desktop folder PIDL and interface.
            Shell32.SHGetFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, IntPtr.Zero, 0, out desktopFolderPidl);
            Shell32Ext.SHGetDesktopFolder(out desktopFolder);

            Form.Load += new System.EventHandler(ShellDebuggerForm_Load);
        }
예제 #2
0
        /// <summary>
        /// Creates the desktop shell folder.
        /// </summary>
        /// <returns>The desktop shell folder.</returns>
        private static ShellItem CreateDesktopShellFolder()
        {
            //  Get the desktop shell folder interface.
            //IShellFolder desktopShellFolderInterface = null;
            //var result = Shell32.SHGetDesktopFolder(out desktopShellFolderInterface);
            IShellFolder2 desktopShellFolderInterface = null;
            var           result = Shell32Ext.SHGetDesktopFolder(out desktopShellFolderInterface);

            //  Validate the result.
            if (result != 0)
            {
                //  Throw the failure as an exception.
                Marshal.ThrowExceptionForHR(result);
            }

            //  Get the dekstop PDIL.
            var desktopPIDL = IntPtr.Zero;

            result = Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref desktopPIDL);

            //  Validate the result.
            if (result != 0)
            {
                //  Throw the failure as an exception.
                Marshal.ThrowExceptionForHR(result);
            }

            //  Get the file info.
            var fileInfo = new SHFILEINFO();

            Shell32.SHGetFileInfo(desktopPIDL, 0, out fileInfo, (uint)Marshal.SizeOf(fileInfo),
                                  SHGFI.SHGFI_DISPLAYNAME | SHGFI.SHGFI_PIDL | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_SYSICONINDEX);

            //  Return the Shell Folder.
            return(new ShellItem
            {
                DisplayName = fileInfo.szDisplayName,
                IconIndex = fileInfo.iIcon,
                HasSubFolders = true,
                IsFolder = true,
                ShellFolderInterface = desktopShellFolderInterface,
                PIDL = desktopPIDL,
                RelativePIDL = desktopPIDL
            });
        }