/// <summary> /// Add property page for this object /// </summary> /// <param name="lpfnAddPage"></param> /// <param name="lParam"></param> /// <returns></returns> int IShellPropSheetExt.AddPages(LPFNSVADDPROPSHEETPAGE pfnAddPage, IntPtr lParam) { try { // ADD PAGES HERE PropertySheetControl samplePage; PROPSHEETPAGE psp; IntPtr hPage; // In ActiveDirectory extensions, Get type of object, and show page according to class // GetADPath(); // if(sClass.ToLower() == "organizationalunit") {...} // create new inherited property page(s) and pass dobj to it samplePage = new DescriptionControl(); psp = samplePage.GetPSP(250, 230); hPage = Comctl32.CreatePropertySheetPage(ref psp); bool result = pfnAddPage(hPage, lParam); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(0); }
private static Icon GetIconFromFile(string path, int iconOrdinal = 0) { var moduleHandle = Kernel32.LoadLibraryEx(path, IntPtr.Zero, Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE | Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE); IntPtr iconHandle = IntPtr.Zero; try { Comctl32.LoadIconMetric(moduleHandle, new IntPtr(iconOrdinal), Comctl32.LI_METRIC.LIM_SMALL, ref iconHandle); } finally { Kernel32.FreeLibrary(moduleHandle); } return(Icon.FromHandle(iconHandle)); }
public static Icon GetIconFromFile(string path, int iconOrdinal = 0, bool useLargeIcon = false) { var moduleHandle = Kernel32.LoadLibraryEx(path, IntPtr.Zero, Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE | Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE); IntPtr iconHandle = IntPtr.Zero; try { Comctl32.LoadIconWithScaleDown(moduleHandle, new IntPtr(iconOrdinal), SystemInformation.SmallIconSize.Width, SystemInformation.SmallIconSize.Height, ref iconHandle); } finally { Kernel32.FreeLibrary(moduleHandle); } return(Icon.FromHandle(iconHandle)); }
public void FileIcon(uint id, RectangleF rect, string path) { var systemIcon = SystemIcon.Get(path, true); //throw new NotImplementedException(); if (systemIcon.ImageList == IntPtr.Zero) { return; } int w = 0; int h = 0; if (!Comctl32.ImageList_GetIconSize(systemIcon.ImageList, ref w, ref h)) { return; } Bitmap bitmap; if (!m_imageListMap.TryGetValue(systemIcon.ImageListIndex, out bitmap)) { using (var memoryBitmap = new MemoryBitmap(w, h)) { Comctl32.ImageList_Draw(systemIcon.ImageList, systemIcon.ImageListIndex, memoryBitmap.DC, 0, 0, ILD.NORMAL); var bytes = memoryBitmap.GetBitmap(); if (bytes != null) { using (var s = new DataStream(w * h * 4, true, true)) { s.Write(bytes, 0, bytes.Length); s.Position = 0; bitmap = new Bitmap(m_device.D2DDeviceContext, new Size2(w, h), s, w * 4, GetBP); m_imageListMap.Add(systemIcon.ImageListIndex, bitmap); } } } } //m_device.D2DDeviceContext.DrawBitmap(bitmap, new RectangleF(rect.X, rect.Y, w, h), 1.0f, BitmapInterpolationMode.Linear); }
/// <summary> /// Creates the property page handle. /// </summary> public void CreatePropertyPageHandle(NativeBridge.NativeBridge nativeBridge) { Logging.Log("Creating property page handle via bridge."); // Create a prop sheet page structure. var psp = new PROPSHEETPAGE(); // Set the key properties. psp.dwSize = (uint)Marshal.SizeOf(psp); //psp.dwFlags = PSP.USETITLE | PSP.USECALLBACK/* | PSP.DEFAULT |*/| PSP.DLGINDIRECT; //psp.dwFlags = PSP.DEFAULT | PSP.USETITLE | PSP.DLGINDIRECT; //psp.hInstance = nativeBridge.GetInstanceHandle(); psp.hInstance = nativeBridge.GetInstanceHandle(); psp.dwFlags = PSP.PSP_DEFAULT | PSP.PSP_USETITLE | PSP.PSP_USECALLBACK; Logging.Log("Getting proxy host..."); psp.pTemplate = nativeBridge.GetProxyHostTemplate(); psp.pfnDlgProc = dialogProc; psp.pcRefParent = 0; psp.pfnCallback = callbackProc; psp.lParam = IntPtr.Zero; // If we have a title, set it. if (!string.IsNullOrEmpty(Target.PageTitle)) { psp.dwFlags |= PSP.PSP_USETITLE; psp.pszTitle = Target.PageTitle; } // If we have an icon, set it. if (Target.PageIcon != null && Target.PageIcon.Handle != IntPtr.Zero) { psp.dwFlags |= PSP.PSP_USEHICON; psp.hIcon = Target.PageIcon.Handle; } // Create a the property sheet page. HostWindowHandle = Comctl32.CreatePropertySheetPage(ref psp); // Log the host window handle. Logging.Log("Created Proxy Host: " + HostWindowHandle.ToString("X8")); }
/// <summary> /// Used to access system folder icons. /// </summary> /// <param name="size">Specify large or small icons.</param> /// <param name="folderType">Specify open or closed FolderType.</param> /// <param name="shfi">Return Folder Information</param> /// <returns>System.Drawing.Icon</returns> public static Icon GetFolderIcon(IconSize size, FolderType folderType, ref Shell32.SHFILEINFO shfi) { // Need to add size check, although errors generated at present! Shell32.SHGetFileInfoConstants flags = Shell32.SHGetFileInfoConstants.SHGFI_TYPENAME | Shell32.SHGetFileInfoConstants.SHGFI_DISPLAYNAME | Shell32.SHGetFileInfoConstants.SHGFI_ICON | Shell32.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES; if (FolderType.Open == folderType) { flags |= Shell32.SHGetFileInfoConstants.SHGFI_OPENICON; } if (IconSize.Small == size) { flags |= Shell32.SHGetFileInfoConstants.SHGFI_SMALLICON; } else { flags |= Shell32.SHGetFileInfoConstants.SHGFI_LARGEICON; } IntPtr hIml; // Get the folder icon shfi = new Shell32.SHFILEINFO(); if (IconHelper.Utils.IsSevenOrAbove()) // Windows 7 FIX { hIml = Shell32.SHGetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.System), Shell32.FILE_ATTRIBUTE.DIRECTORY, ref shfi, (uint)Marshal.SizeOf(shfi), flags); } else { hIml = Shell32.SHGetFileInfo(null, Shell32.FILE_ATTRIBUTE.DIRECTORY, ref shfi, (uint)Marshal.SizeOf(shfi), flags); } if (shfi.hIcon == IntPtr.Zero) { return(null); } if (!IconHelper.Utils.IsXpOrAbove()) { return(GetManagedIcon(shfi.hIcon)); } // Get the System IImageList object from the Shell: Guid iidImageList = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); Shell32.IImageList iImageList = null; int ret = Shell32.SHGetImageList( (int)size, ref iidImageList, ref iImageList ); // the image list handle is the IUnknown pointer, but // using Marshal.GetIUnknownForObject doesn't return // the right value. It really doesn't hurt to make // a second call to get the handle: Shell32.SHGetImageListHandle((int)size, ref iidImageList, ref hIml); IntPtr hIcon = IntPtr.Zero; if (iImageList == null) { hIcon = Comctl32.ImageList_GetIcon( hIml, shfi.iIcon, (int)Comctl32.ImageListDrawItemConstants.ILD_TRANSPARENT); } else { iImageList.GetIcon( shfi.iIcon, (int)Comctl32.ImageListDrawItemConstants.ILD_TRANSPARENT, ref hIcon); } return(hIcon == IntPtr.Zero ? GetManagedIcon(shfi.hIcon) : GetManagedIcon(hIcon)); }
/// <summary> /// Returns an icon for a given file - indicated by the name parameter. /// </summary> /// <param name="name">Extension or pathname for file.</param> /// <param name="size">Large or small</param> /// <param name="linkOverlay">Whether to include the link icon</param> /// <param name="shfi">Return File Information</param> /// <returns>System.Drawing.Icon</returns> public static Icon GetFileIcon(string name, IconSize size, bool linkOverlay, ref Shell32.SHFILEINFO shfi) { name = Environment.ExpandEnvironmentVariables(name); shfi = new Shell32.SHFILEINFO(); Shell32.SHGetFileInfoConstants flags = Shell32.SHGetFileInfoConstants.SHGFI_TYPENAME | Shell32.SHGetFileInfoConstants.SHGFI_DISPLAYNAME | Shell32.SHGetFileInfoConstants.SHGFI_ICON | Shell32.SHGetFileInfoConstants.SHGFI_SHELLICONSIZE | Shell32.SHGetFileInfoConstants.SHGFI_SYSICONINDEX | Shell32.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES; if (linkOverlay) { flags |= Shell32.SHGetFileInfoConstants.SHGFI_LINKOVERLAY; } /* Check the size specified for return. */ if (IconSize.Small == size) { flags |= Shell32.SHGetFileInfoConstants.SHGFI_SMALLICON; } else { flags |= Shell32.SHGetFileInfoConstants.SHGFI_LARGEICON; } IntPtr hIml = Shell32.SHGetFileInfo(name, Shell32.FILE_ATTRIBUTE.NORMAL, ref shfi, (uint)Marshal.SizeOf(shfi), flags); if (shfi.hIcon == IntPtr.Zero) { return(null); } if (!IconHelper.Utils.IsXpOrAbove()) { return(GetManagedIcon(shfi.hIcon)); } // Get the System IImageList object from the Shell: Guid iidImageList = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); Shell32.IImageList iImageList = null; int ret = Shell32.SHGetImageList( (int)size, ref iidImageList, ref iImageList ); // the image list handle is the IUnknown pointer, but // using Marshal.GetIUnknownForObject doesn't return // the right value. It really doesn't hurt to make // a second call to get the handle: Shell32.SHGetImageListHandle((int)size, ref iidImageList, ref hIml); IntPtr hIcon = IntPtr.Zero; if (iImageList == null) { hIcon = Comctl32.ImageList_GetIcon( hIml, shfi.iIcon, (int)Comctl32.ImageListDrawItemConstants.ILD_TRANSPARENT); } else { iImageList.GetIcon( shfi.iIcon, (int)Comctl32.ImageListDrawItemConstants.ILD_TRANSPARENT, ref hIcon); } return(hIcon == IntPtr.Zero ? GetManagedIcon(shfi.hIcon) : GetManagedIcon(hIcon)); }