/// <summary> /// Retrieves the handle of the system image list. /// </summary> public SystemImageList() { // Retrieve the info for a fake file so we can get the image list handle. ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO(); ShellAPI.SHGFI dwAttribs = ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES | ShellAPI.SHGFI.SHGFI_SMALLICON | ShellAPI.SHGFI.SHGFI_SYSICONINDEX; m_pImgHandle = ShellAPI.SHGetFileInfo(".txt", ShellAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), dwAttribs); // Make sure we got the handle. if (m_pImgHandle.Equals(IntPtr.Zero)) throw new Exception("Unable to retrieve system image list handle."); }
/// <summary> /// Retrieves the handle of the system image list. /// </summary> public SystemImageList() { // Retrieve the info for a fake file so we can get the image list handle. ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO(); ShellAPI.SHGFI dwAttribs = ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES | ShellAPI.SHGFI.SHGFI_SMALLICON | ShellAPI.SHGFI.SHGFI_SYSICONINDEX; m_pImgHandle = ShellAPI.SHGetFileInfo(".txt", ShellAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), dwAttribs); // Make sure we got the handle. if (m_pImgHandle.Equals(IntPtr.Zero)) { throw new Exception("Unable to retrieve system image list handle."); } }
private void UpdateNodeImage(TreeNode node) { int imageIndex = -1; if (node.Tag != null) { ProjectItem item = (ProjectItem)node.Tag; if (item is Folder || item is ProjectDocumentItem || item is RootItem) { ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO(); ShellAPI.SHGFI attrs = ShellAPI.SHGFI.SHGFI_SMALLICON | ShellAPI.SHGFI.SHGFI_SYSICONINDEX; if (node.IsExpanded) attrs |= ShellAPI.SHGFI.SHGFI_OPENICON; IntPtr handle = ShellAPI.SHGetFileInfo( System.Windows.Forms.Application.StartupPath, ShellAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), attrs); imageIndex = shInfo.iIcon; } else if (item is DocumentItem) { string fileName = ((DocumentItem)item).AbsoluteFileName; ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO(); ShellAPI.SHGFI attrs = ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES | ShellAPI.SHGFI.SHGFI_SMALLICON | ShellAPI.SHGFI.SHGFI_SYSICONINDEX; IntPtr handle = ShellAPI.SHGetFileInfo( fileName, ShellAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), attrs); imageIndex = shInfo.iIcon; } else { ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO(); ShellAPI.SHGFI attrs = ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES | ShellAPI.SHGFI.SHGFI_SMALLICON | ShellAPI.SHGFI.SHGFI_SYSICONINDEX; IntPtr handle = ShellAPI.SHGetFileInfo( "", ShellAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), attrs); imageIndex = shInfo.iIcon; } node.Text = item.Label; } node.ImageIndex = imageIndex; node.SelectedImageIndex = imageIndex; }