public static int FillRect(IHandle hDC, ref RECT lprc, Gdi32.HBRUSH hbr) { int result = FillRect((Gdi32.HDC)hDC.Handle, ref lprc, hbr); GC.KeepAlive(hDC); return(result); }
private static void DrawAndFillEllipse(Gdi32.HDC hdc, Gdi32.HPEN borderPen, Gdi32.HBRUSH fieldBrush, Rectangle bounds) { Debug.Assert(!hdc.IsNull, "Calling DrawAndFillEllipse with null wg"); if (hdc.IsNull) { return; } hdc.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8)); hdc.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10)); hdc.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4)); hdc.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 0), new Point(bounds.X + 8, bounds.Y + 0)); hdc.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11)); hdc.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1)); hdc.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1)); hdc.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10)); hdc.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10)); hdc.DrawLine(borderPen, new Point(bounds.X + 0, bounds.Y + 4), new Point(bounds.X + 0, bounds.Y + 8)); hdc.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8)); hdc.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4)); hdc.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10)); hdc.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4)); hdc.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10)); }
private unsafe void CreateDitherBrush() { Debug.Assert(_hbrushDither.IsNull, "Brush should not be recreated."); short *patternBits = stackalloc short[] { unchecked ((short)0xAAAA), unchecked ((short)0x5555), unchecked ((short)0xAAAA), unchecked ((short)0x5555), unchecked ((short)0xAAAA), unchecked ((short)0x5555), unchecked ((short)0xAAAA), unchecked ((short)0x5555) }; Gdi32.HBITMAP hbitmapTemp = Gdi32.CreateBitmap(8, 8, 1, 1, patternBits); Debug.Assert( !hbitmapTemp.IsNull, "could not create dither bitmap. Page selector UI will not be correct"); if (!hbitmapTemp.IsNull) { _hbrushDither = Gdi32.CreatePatternBrush(hbitmapTemp); Debug.Assert( !_hbrushDither.IsNull, "Unable to created dithered brush. Page selector UI will not be correct"); Gdi32.DeleteObject(hbitmapTemp); } }
internal static void FillRectangle(this Gdi32.HDC hdc, Rectangle rectangle, Gdi32.HBRUSH hbrush) { RECT rect = rectangle; User32.FillRect( hdc, ref rect, hbrush); }
internal static void FillRectangle(this Gdi32.HDC hdc, Gdi32.HBRUSH brush, Rectangle rectangle) { Debug.Assert(!brush.IsNull, "brush == null"); RECT rect = rectangle; User32.FillRect( hdc, ref rect, brush); }
internal static void FillRectangle(this Gdi32.HDC hdc, Rectangle rectangle, Gdi32.HBRUSH hbrush) { Debug.Assert(!hbrush.IsNull); RECT rect = rectangle; User32.FillRect( hdc, ref rect, hbrush); }
protected override void OnHandleDestroyed(EventArgs e) { base.OnHandleDestroyed(e); if (!RecreatingHandle && !_hbrushDither.IsNull) { Gdi32.DeleteObject(_hbrushDither); _hbrushDither = default; } }
protected virtual void Dispose(bool disposing) { if (DC != null && !_nativeHandle.IsNull) { DC.DeleteObject(_nativeHandle, GdiObjectType.Brush); _nativeHandle = default; } if (disposing) { GC.SuppressFinalize(this); } }
internal static void DrawAndFillEllipse( this Gdi32.HDC hdc, Gdi32.HPEN pen, Gdi32.HBRUSH brush, int left, int top, int right, int bottom) { using var penSelection = pen.IsNull ? default : new Gdi32.SelectObjectScope(hdc, pen); using var brushSelection = brush.IsNull ? default : new Gdi32.SelectObjectScope(hdc, brush); Gdi32.Ellipse(hdc, left, top, right, bottom); }
public static extern int FillRect(Gdi32.HDC hDC, ref RECT lprc, Gdi32.HBRUSH hbr);
internal static void FillRectangle(this DeviceContextHdcScope hdc, Rectangle rectangle, Gdi32.HBRUSH hbrush) => FillRectangle(hdc.HDC, rectangle, hbrush);
internal static void FillRectangle(this User32.GetDcScope hdc, Gdi32.HBRUSH hbrush, Rectangle rectangle) => FillRectangle(hdc.HDC, hbrush, rectangle);
internal static void DrawAndFillEllipse( this DeviceContextHdcScope hdc, Gdi32.HPEN pen, Gdi32.HBRUSH brush, Rectangle bounds) => DrawAndFillEllipse(hdc.HDC, pen, brush, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
protected override void CreateBrush() { Gdi32.HBRUSH nativeHandle = Gdi32.CreateSolidBrush(ColorTranslator.ToWin32(Color)); Debug.Assert(!nativeHandle.IsNull); HBrush = nativeHandle; }
internal static void FillRectangle(this Gdi32.CreateDcScope hdc, Rectangle rectangle, Gdi32.HBRUSH hbrush) => FillRectangle(hdc.HDC, rectangle, hbrush);
internal static void DrawAndFillEllipse(this Gdi32.HDC hdc, Gdi32.HPEN pen, Gdi32.HBRUSH brush, Rectangle bounds) => DrawEllipse(hdc, pen, brush, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
/// <summary> /// Constructor. /// </summary> /// <param name="className">Name, or default will be generated.</param> /// <param name="moduleInstance">Module to associate with the window. The entry assembly is the default.</param> /// <param name="backgroundBrush">Use (IntPtr)(-1) for no background brush.</param> /// <param name="icon">Use (IntPtr)(-1) for no icon.</param> /// <param name="cursor">Use (IntPtr)(-1) for no cursor.</param> /// <param name="menuName">Menu name, can not set with <paramref name="menuId"/>.</param> /// <param name="menuId">Menu id, can not set with <paramref name="menuName"/>.</param> public unsafe WindowClass( string className = default, IntPtr moduleInstance = default, User32.CS classStyle = User32.CS.HREDRAW | User32.CS.VREDRAW, Gdi32.HBRUSH backgroundBrush = default, IntPtr icon = default, IntPtr cursor = default, string menuName = null, int menuId = 0, int classExtraBytes = 0, int windowExtraBytes = 0) { // Handle default values className ??= Guid.NewGuid().ToString(); if (backgroundBrush.IsNull) { backgroundBrush = User32.GetSysColorBrush(User32.COLOR.WINDOW); } else if (backgroundBrush.Handle == (IntPtr)(-1)) { backgroundBrush = default; } if (icon == default) { icon = LoadIconW(IntPtr.Zero, (IntPtr)IDI_APPLICATION); } else if (icon == (IntPtr)(-1)) { icon = default; } if (cursor == default) { cursor = User32.LoadCursorW(IntPtr.Zero, (IntPtr)User32.CursorResourceId.IDC_ARROW); } else if (cursor == (IntPtr)(-1)) { cursor = default; } if (moduleInstance == IntPtr.Zero) { Marshal.GetHINSTANCE(Assembly.GetCallingAssembly().Modules.First()); } if (menuId != 0 && menuName != null) { throw new ArgumentException($"Can't set both {nameof(menuName)} and {nameof(menuId)}."); } _windowProcedure = WNDPROC; ModuleInstance = moduleInstance; _className = className; _menuName = menuName ?? string.Empty; _wndClass = new User32.WNDCLASS { style = classStyle, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), cbClsExtra = classExtraBytes, cbWndExtra = windowExtraBytes, hInstance = moduleInstance, hIcon = icon, hCursor = cursor, hbrBackground = backgroundBrush, lpszMenuName = (char *)menuId }; }
public static partial int FillRect(Gdi32.HDC hDC, ref RECT lprc, Gdi32.HBRUSH hbr);