internal static void DestroyIcon(NativeMethods.IconHandle hIcon) { if (IntDestroyIcon(hIcon) == false) { throw new Win32Exception(); } }
public static void GetDefaultIconHandles(out NativeMethods.IconHandle largeIconHandle, out NativeMethods.IconHandle smallIconHandle) { largeIconHandle = null; smallIconHandle = null; SecurityHelper.DemandUIWindowPermission(); string moduleFileName = UnsafeNativeMethods.GetModuleFileName(default(HandleRef)); int num = UnsafeNativeMethods.ExtractIconEx(moduleFileName, 0, out largeIconHandle, out smallIconHandle, 1); }
/// <returns></returns> public static void GetDefaultIconHandles(out NativeMethods.IconHandle largeIconHandle, out NativeMethods.IconHandle smallIconHandle) { largeIconHandle = null; smallIconHandle = null; // Get the handle of the module that created the running process. string iconModuleFile = UnsafeNativeMethods.GetModuleFileName(new HandleRef()); // We don't really care about the return value. Handles will be invalid on error. int extractedCount = UnsafeNativeMethods.ExtractIconEx(iconModuleFile, 0, out largeIconHandle, out smallIconHandle, 1); }
//------------------------------------------------------------------------------- // // Private Methods // //------------------------------------------------------------------------------- #region Private Methods /// <summary> /// Create a Cursor from a Drawing object /// </summary> /// <param name="drawing">Drawing</param> /// <param name="hotspot">Cursor Hotspot</param> /// <returns></returns> private static Cursor CreateCursorFromDrawing(Drawing drawing, Point hotspot) { // A default cursor. Cursor cursor = Cursors.Arrow; Rect drawingBounds = drawing.Bounds; double originalWidth = drawingBounds.Width; double originalHeight = drawingBounds.Height; // Cursors like to be multiples of 8 in dimension. int width = IconHelper.AlignToBytes(drawingBounds.Width, 1); int height = IconHelper.AlignToBytes(drawingBounds.Height, 1); // Now inflate the drawing bounds to the new dimension. drawingBounds.Inflate((width - originalWidth) / 2, (height - originalHeight) / 2); // Translate the hotspot accordingly. int xHotspot = (int)Math.Round(hotspot.X - drawingBounds.Left); int yHotspot = (int)Math.Round(hotspot.Y - drawingBounds.Top); // Create a DrawingVisual which represents the cursor drawing. DrawingVisual cursorDrawingVisual = CreateCursorDrawingVisual(drawing, width, height); // Render the cursor visual to a bitmap RenderTargetBitmap rtb = RenderVisualToBitmap(cursorDrawingVisual, width, height); // Get pixel data in Bgra32 fromat from the bitmap byte[] pixels = GetPixels(rtb, width, height); NativeMethods.IconHandle finalCursor = IconHelper.CreateIconCursor(pixels, width, height, xHotspot, yHotspot, false); if (finalCursor.IsInvalid) { // Return the default cursor if above is failed. return(Cursors.Arrow); } cursor = CursorInteropHelper.CriticalCreate(finalCursor); return(cursor); }
private static Cursor CreateCursorFromDrawing(Drawing drawing, Point hotspot) { Cursor arrow = Cursors.Arrow; Rect bounds = drawing.Bounds; double width = bounds.Width; double height = bounds.Height; int num = IconHelper.AlignToBytes(bounds.Width, 1); int num2 = IconHelper.AlignToBytes(bounds.Height, 1); bounds.Inflate(((double)num - width) / 2.0, ((double)num2 - height) / 2.0); int xHotspot = (int)Math.Round(hotspot.X - bounds.Left); int yHotspot = (int)Math.Round(hotspot.Y - bounds.Top); DrawingVisual visual = PenCursorManager.CreateCursorDrawingVisual(drawing, num, num2); RenderTargetBitmap rtb = PenCursorManager.RenderVisualToBitmap(visual, num, num2); byte[] pixels = PenCursorManager.GetPixels(rtb, num, num2); NativeMethods.IconHandle iconHandle = IconHelper.CreateIconCursor(pixels, num, num2, xHotspot, yHotspot, false); if (iconHandle.IsInvalid) { return(Cursors.Arrow); } return(CursorInteropHelper.CriticalCreate(iconHandle)); }
private static extern bool IntDestroyIcon(NativeMethods.IconHandle hIcon);
public static void GetIconHandlesFromImageSource(ImageSource image, out NativeMethods.IconHandle largeIconHandle, out NativeMethods.IconHandle smallIconHandle) { EnsureSystemMetrics(); largeIconHandle = CreateIconHandleFromImageSource(image, s_iconSize); smallIconHandle = CreateIconHandleFromImageSource(image, s_smallIconSize); }