Skip to content

Commit

Permalink
Trying to fix icons.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Feb 14, 2020
1 parent eae6392 commit 2a21564
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions SuperGrate/Classes/Win32Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections.Generic;

namespace SuperGrate
{
Expand All @@ -24,6 +25,7 @@ static class Win32Interop
private static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);
[DllImport("gdi32.dll")]
private static extern IntPtr CreateSolidBrush(uint crColor);
private static Dictionary<IntPtr, IntPtr[]> MenuItemIcons = new Dictionary<IntPtr, IntPtr[]>();
/// <summary>
/// Sets an icon on a button with the FlatStyle set to System.
/// </summary>
Expand All @@ -35,9 +37,30 @@ public static void SetSystemIcon(this Button Button, Icon Icon, int Width = 16,
}
public static void SetMenuItemIcon(this MenuItem MenuItem, Icon Icon)
{
IntPtr hBitmap = Icon.ToBitmapAlpha(16, 16, SystemColors.Control).GetHbitmap();
SetMenuItemBitmaps(MenuItem.Parent.Handle, (IntPtr)MenuItem.Index, 0x400, hBitmap, hBitmap);
IntPtr[] hBitmaps =
{
Icon.ToBitmapAlpha(16, 16, SystemColors.Control).GetHbitmap(),
Icon.ToBitmapAlpha(16, 16, SystemColors.GrayText).GetHbitmap()
};
//SetMenuItemBitmaps(MenuItem.Parent.Handle, (IntPtr)MenuItem.Index, 0x400, hBitmap, hBitmap);
MenuItemIcons.Add(MenuItem.Handle, hBitmaps);
//MenuItem.Select += MenuItem_Select;
//MenuItem.MeasureItem += MenuItem_MeasureItem;

}

private static void MenuItem_MeasureItem(object sender, MeasureItemEventArgs e)
{
MenuItem mi = (MenuItem)sender;
SetMenuItemBitmaps(mi.Parent.Handle, (IntPtr)mi.Index, 0x400, MenuItemIcons[mi.Handle][0], MenuItemIcons[mi.Handle][0]);
}

private static void MenuItem_Select(object sender, EventArgs e)
{
MenuItem mi = (MenuItem)sender;
SetMenuItemBitmaps(mi.Parent.Handle, (IntPtr)mi.Index, 0x400, MenuItemIcons[mi.Handle][1], MenuItemIcons[mi.Handle][1]);
}

public static Bitmap ToBitmapAlpha(this Icon Icon, int Width, int Height, Color Background)
{
Icon rsIcon = new Icon(Icon, Width, Height);
Expand Down

0 comments on commit 2a21564

Please sign in to comment.