private void CreatePen() { if (width > 1) // Geometric pen. { // From MSDN: if width > 1, the style must be PS_NULL, PS_SOLID, or PS_INSIDEFRAME. style |= WindowsPenStyle.Geometric | WindowsPenStyle.Solid; } if (wndBrush == null) { nativeHandle = IntSafeNativeMethods.CreatePen((int)style, width, ColorTranslator.ToWin32(color)); } else { IntNativeMethods.LOGBRUSH lb = new IntNativeMethods.LOGBRUSH { lbColor = ColorTranslator.ToWin32(wndBrush.Color), lbStyle = IntNativeMethods.BS_SOLID, lbHatch = 0 }; // Note: We currently don't support custom styles, that's why 0 and null for last two params. nativeHandle = IntSafeNativeMethods.ExtCreatePen((int)style, width, lb, 0, null); } }
public static int GetObject(HandleRef hBrush, IntNativeMethods.LOGBRUSH lb) { int retVal = IntGetObject(hBrush, System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntNativeMethods.LOGBRUSH)), lb); DbgUtil.AssertWin32(retVal != 0, "GetObject(hObj=[0x{0:X8}], [LOGBRUSH]) failed.", hBrush.Handle); return(retVal); }
public static IntPtr ExtCreatePen(int fnStyle, int dwWidth, IntNativeMethods.LOGBRUSH lplb, int dwStyleCount, int[] lpStyle) { IntPtr hPen = System.Internal.HandleCollector.Add(IntExtCreatePen(fnStyle, dwWidth, lplb, dwStyleCount, lpStyle), IntSafeNativeMethods.CommonHandles.GDI); DbgUtil.AssertWin32(hPen != IntPtr.Zero, "IntExtCreatePen(style={0}, width={1}, brush={2}, styleCount={3}, styles={4}) failed.", fnStyle, dwWidth, lplb, dwStyleCount, lpStyle); return(hPen); }
public static WindowsBrush FromDC(DeviceContext dc) { IntPtr hBrush = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(null, dc.Hdc), IntNativeMethods.OBJ_BRUSH); IntNativeMethods.LOGBRUSH logBrush = new IntNativeMethods.LOGBRUSH(); IntUnsafeNativeMethods.GetObject(new HandleRef(null, hBrush), logBrush); // don't call DeleteObject on handle from GetCurrentObject, it is the one selected in the hdc. return(WindowsBrush.FromLogBrush(dc, logBrush)); }
public static WindowsBrush FromLogBrush(DeviceContext dc, IntNativeMethods.LOGBRUSH logBrush) { Debug.Assert(logBrush != null, "logBrush is null"); switch (logBrush.lbStyle) { // currently supported brushes: case IntNativeMethods.BS_HATCHED: return(new WindowsHatchBrush(dc, (WindowsHatchStyle)logBrush.lbHatch)); case IntNativeMethods.BS_SOLID: return(new WindowsSolidBrush(dc, Color.FromArgb(logBrush.lbColor))); default: Debug.Fail("Don't know how to create WindowsBrush from specified logBrush"); return(null); } }
private void CreatePen() { if (this.width > 1) { this.style |= WindowsPenStyle.Geometric; } if (this.wndBrush == null) { this.nativeHandle = IntSafeNativeMethods.CreatePen((int) this.style, this.width, ColorTranslator.ToWin32(this.color)); } else { IntNativeMethods.LOGBRUSH lplb = new IntNativeMethods.LOGBRUSH { lbColor = ColorTranslator.ToWin32(this.wndBrush.Color), lbStyle = 0, lbHatch = 0 }; this.nativeHandle = IntSafeNativeMethods.ExtCreatePen((int) this.style, this.width, lplb, 0, null); } }
private void CreatePen() { if (this.width > 1) // Geometric pen. { // From MSDN: if width > 1, the style must be PS_NULL, PS_SOLID, or PS_INSIDEFRAME. this.style |= WindowsPenStyle.Geometric | WindowsPenStyle.Solid; } if (this.wndBrush == null) { this.nativeHandle = IntSafeNativeMethods.CreatePen((int)this.style, this.width, ColorTranslator.ToWin32(this.color)); } else { IntNativeMethods.LOGBRUSH lb = new IntNativeMethods.LOGBRUSH(); lb.lbColor = ColorTranslator.ToWin32(this.wndBrush.Color); lb.lbStyle = IntNativeMethods.BS_SOLID; lb.lbHatch = 0; // CONSIDER: Check if HatchBrush and get the style if so (If needed in the future). // Note: We currently don't support custom styles, that's why 0 and null for last two params. this.nativeHandle = IntSafeNativeMethods.ExtCreatePen((int)this.style, this.width, lb, 0, null); } }
public static extern int IntGetObject(HandleRef hBrush, int nSize, [In, Out] IntNativeMethods.LOGBRUSH lb);
private static extern IntPtr IntExtCreatePen(int fnStyle, int dwWidth, IntNativeMethods.LOGBRUSH lplb, int dwStyleCount, [MarshalAs(UnmanagedType.LPArray)] int[] lpStyle);
public static WindowsBrush FromDC(DeviceContext dc) { IntPtr hBrush = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(null, dc.Hdc), IntNativeMethods.OBJ_BRUSH); IntNativeMethods.LOGBRUSH logBrush = new IntNativeMethods.LOGBRUSH(); IntUnsafeNativeMethods.GetObject(new HandleRef(null, hBrush), logBrush); // don't call DeleteObject on handle from GetCurrentObject, it is the one selected in the hdc. return WindowsBrush.FromLogBrush(dc, logBrush ); }
private void CreatePen() { if (this.width > 1) // Geometric pen. { // From MSDN: if width > 1, the style must be PS_NULL, PS_SOLID, or PS_INSIDEFRAME. this.style |= WindowsPenStyle.Geometric | WindowsPenStyle.Solid; } if (this.wndBrush == null) { this.nativeHandle = IntSafeNativeMethods.CreatePen((int) this.style, this.width, ColorTranslator.ToWin32(this.color) ); } else { IntNativeMethods.LOGBRUSH lb = new IntNativeMethods.LOGBRUSH(); lb.lbColor = ColorTranslator.ToWin32( this.wndBrush.Color ); lb.lbStyle = IntNativeMethods.BS_SOLID; lb.lbHatch = 0; // CONSIDER: Check if HatchBrush and get the style if so (If needed in the future). // Note: We currently don't support custom styles, that's why 0 and null for last two params. this.nativeHandle = IntSafeNativeMethods.ExtCreatePen((int)this.style, this.width, lb, 0, null ); } }