public static bool AngleArc(HandleRef hDC, int x, int y, int radius, float startAngle, float endAngle) { bool retVal = IntAngleArc(hDC, x, y, radius, startAngle, endAngle); DbgUtil.AssertWin32(retVal, "AngleArc(hdc=[0x{0:X8}], ...) failed.", hDC.Handle); return(retVal); }
public static int GetMapMode(HandleRef hDC) { int mapMode = IntGetMapMode(hDC); DbgUtil.AssertWin32(mapMode != 0, "GetMapMode(hdc=[0x{0:X8}]", hDC.Handle); return(mapMode); }
public static bool GetViewportOrgEx(HandleRef hdc, [In, Out] IntNativeMethods.POINT lpPoint) { bool retVal = IntGetViewportOrgEx(hdc, lpPoint); DbgUtil.AssertWin32(retVal, "GetViewportOrgEx([hdc=0x{0:X8}], [out point]) failed.", hdc.Handle); return(retVal); }
public static bool MoveToEx(HandleRef hdc, int x, int y, IntNativeMethods.POINT pt) { bool retVal = IntMoveToEx(hdc, x, y, pt); DbgUtil.AssertWin32(retVal, "MoveToEx(hdc=[0x{0:X8}], x=[{1}], y=[{2}], pt=[{3}] failed.", hdc.Handle, x, y, pt); return(retVal); }
public static bool FillRect(HandleRef hDC, [In] ref IntNativeMethods.RECT rect, HandleRef hbrush) { bool retVal = IntFillRect(hDC, ref rect, hbrush); DbgUtil.AssertWin32(retVal, "FillRect(hdc=[0x{0:X8}], rect=[{1}], hbrush=[{2}]", hDC.Handle, rect, hbrush.Handle); return(retVal); }
public static int SetBkMode(HandleRef hDC, int nBkMode) { int oldMode = IntSetBkMode(hDC, nBkMode); DbgUtil.AssertWin32(oldMode != 0, "SetBkMode(hdc=[0x{0:X8}], Mode=[{1}]) failed.", hDC.Handle, nBkMode); return(oldMode); }
public static int DrawTextEx(HandleRef hDC, string text, ref IntNativeMethods.RECT lpRect, int nFormat, [In, Out] IntNativeMethods.DRAWTEXTPARAMS lpDTParams) { int retVal = DrawTextExW(hDC, text, text.Length, ref lpRect, nFormat, lpDTParams); DbgUtil.AssertWin32(retVal != 0, "DrawTextEx(hdc=[0x{0:X8}], text=[{1}], rect=[{2}], flags=[{3}] failed.", hDC.Handle, text, lpRect, nFormat); return(retVal); }
/// <summary> /// Creates the font handle. /// </summary> private void CreateFont() { Debug.Assert(hFont == IntPtr.Zero, "hFont is not null, this will generate a handle leak."); Debug.Assert(this.logFont != null, "WindowsFont.logFont not initialized."); this.hFont = IntUnsafeNativeMethods.CreateFontIndirect(this.logFont); #if TRACK_HFONT Debug.WriteLine(DbgUtil.StackTraceToStr(String.Format("HFONT[0x{0:x8}] = CreateFontIndirect( LOGFONT={1} )", (int)this.hFont, this.logFont))); #endif if (this.hFont == IntPtr.Zero) { this.logFont.lfFaceName = defaultFaceName; this.logFont.lfOutPrecision = IntNativeMethods.OUT_TT_ONLY_PRECIS; // True Type only. this.hFont = IntUnsafeNativeMethods.CreateFontIndirect(this.logFont); #if TRACK_HFONT Debug.WriteLine(DbgUtil.StackTraceToStr(String.Format("HFONT[0x{0:x8}] = CreateFontIndirect( LOGFONT={1} )", (int)this.hFont, this.logFont))); #endif } // Update logFont height and other adjusted parameters. // IntUnsafeNativeMethods.GetObject(new HandleRef(this, this.hFont), this.logFont); // We created the hFont, we will delete it on dispose. this.ownHandle = true; }
public static IntPtr CreateCompatibleDC(HandleRef hDC) { IntPtr compatibleDc = Interop.HandleCollector.Add(IntCreateCompatibleDC(hDC), Interop.CommonHandles.GDI); DbgUtil.AssertWin32(compatibleDc != IntPtr.Zero, "CreateCompatibleDC([hdc=0x{0:X8}]) failed", hDC.Handle); return(compatibleDc); }
public int SaveHdc() { HandleRef hdc = new HandleRef(this, this.Hdc); int state = IntUnsafeNativeMethods.SaveDC(hdc); if (contextStack == null) { contextStack = new Stack(); } GraphicsState g = new GraphicsState(); g.hBitmap = hCurrentBmp; g.hBrush = hCurrentBrush; g.hPen = hCurrentPen; g.hFont = hCurrentFont; #if !DRAWING_NAMESPACE g.font = new WeakReference(selectedFont); #endif contextStack.Push(g); #if TRACK_HDC Debug.WriteLine(DbgUtil.StackTraceToStr(String.Format("state[0]=DC.SaveHdc(hDc=0x{1:x8})", state, unchecked ((int)this.hDC)))); #endif return(state); }
internal void Dispose(bool disposing) { bool deletedHandle = false; if (this.ownHandle) { if (!ownedByCacheManager || !disposing) { // If we were ever owned by the CacheManger and we're being disposed // we can be sure that we're not in use by any DC's (otherwise Dispose() wouldn't have been called) // skip the check IsFontInUse check in this case. // Also skip the check if disposing == false, because the cache is thread-static // and that means we're being called from the finalizer. if (everOwnedByCacheManager || !disposing || !DeviceContexts.IsFontInUse(this)) { Debug.Assert(this.hFont != IntPtr.Zero, "Unexpected null hFont."); DbgUtil.AssertFinalization(this, disposing); IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, this.hFont)); #if TRACK_HFONT Debug.WriteLine(DbgUtil.StackTraceToStr(String.Format("DeleteObject(HFONT[0x{0:x8}]))", (int)this.hFont))); #endif this.hFont = IntPtr.Zero; this.ownHandle = false; deletedHandle = true; } } } if (disposing && (deletedHandle || !ownHandle)) { GC.SuppressFinalize(this); } }
public static string GetLastErrorStr() { int MAX_SIZE = 255; StringBuilder buffer = new StringBuilder(MAX_SIZE); string message = string.Empty; int err = 0; try { err = Marshal.GetLastWin32Error(); int retVal = FormatMessage( FORMAT_MESSAGE_DEFAULT, new HandleRef(null, IntPtr.Zero), err, GetUserDefaultLCID(), buffer, MAX_SIZE, new HandleRef(null, IntPtr.Zero)); message = retVal != 0 ? buffer.ToString() : "<error returned>"; } catch (Exception ex) { if (DbgUtil.IsCriticalException(ex)) { throw; //rethrow critical exception. } message = ex.ToString(); } return(string.Format(CultureInfo.CurrentCulture, "0x{0:x8} - {1}", err, message)); }
public static IntPtr CreateIC(string lpszDriverName, string lpszDeviceName, string lpszOutput, HandleRef /*DEVMODE*/ lpInitData) { IntPtr hdc = Interop.HandleCollector.Add(IntCreateIC(lpszDriverName, lpszDeviceName, lpszOutput, lpInitData), Interop.CommonHandles.HDC); DbgUtil.AssertWin32(hdc != IntPtr.Zero, "CreateIC([driverName={0}], [deviceName={1}], [fileName={2}], [devMode={3}]) failed.", lpszDriverName, lpszDeviceName, lpszOutput, lpInitData.Handle); return(hdc); }
public static bool Ellipse(HandleRef hDc, int x1, int y1, int x2, int y2) { bool retVal = IntEllipse(hDc, x1, y1, x2, y2); DbgUtil.AssertWin32(retVal, "Ellipse(hdc=[0x{0:X8}], x1=[{1}], y1=[{2}], x2=[{3}], y2=[{4}]) failed.", hDc.Handle, x1, y1, x2, y2); return(retVal); }
public static IntPtr GetDC(HandleRef hWnd) { IntPtr hdc = Interop.HandleCollector.Add(IntGetDC(hWnd), Interop.CommonHandles.HDC); DbgUtil.AssertWin32(hdc != IntPtr.Zero, "GetHdc([hWnd=0x{0:X8}]) failed.", hWnd); return(hdc); }
public static int SaveDC(HandleRef hDC) { int state = IntSaveDC(hDC); DbgUtil.AssertWin32(state != 0, "SaveDC([hdc=0x{0:X8}]) failed", hDC.Handle); return(state); }
public static IntPtr GetStockObject(int nIndex) { IntPtr hGdiObj = IntGetStockObject(nIndex); DbgUtil.AssertWin32(hGdiObj != IntPtr.Zero, "GetStockObject({0}) failed.", nIndex); return(hGdiObj); }
public static bool OffsetViewportOrgEx(HandleRef hDC, int nXOffset, int nYOffset, [In, Out] IntNativeMethods.POINT point) { bool retVal = IntOffsetViewportOrgEx(hDC, nXOffset, nYOffset, point); DbgUtil.AssertWin32(retVal, "OffsetViewportOrgEx([hdc=0x{0:X8}], dx=[{1}], dy=[{2}], [out pPoint]) failed.", hDC.Handle, nXOffset, nYOffset); return(retVal); }
public static int GetBkMode(HandleRef hDC) { int mode = IntGetBkMode(hDC); DbgUtil.AssertWin32(mode != 0, "GetBkMode(hdc=[0x{0:X8}]) failed.", hDC.Handle); return(mode); }
public static int GetClipRgn(HandleRef hDC, HandleRef hRgn) { int retVal = IntGetClipRgn(hDC, hRgn); DbgUtil.AssertWin32(retVal != -1, "IntGetClipRgn([hdc=0x{0:X8}], [hRgn]) failed.", hDC.Handle); return(retVal); }
public static bool LineTo(HandleRef hdc, int x, int y) { bool retVal = IntLineTo(hdc, x, y); DbgUtil.AssertWin32(retVal, "LineTo(hdc=[0x{0:X8}], x=[{1}], y=[{2}] failed.", hdc.Handle, x, y); return(retVal); }
public static extern IntPtr IntCreateFontIndirect([In, Out, MarshalAs(UnmanagedType.AsAny)] object lf); // need object here since LOGFONT is not public. public static IntPtr CreateFontIndirect(/*IntNativeMethods.LOGFONT*/ object lf) { IntPtr hFont = Interop.HandleCollector.Add(IntCreateFontIndirect(lf), Interop.CommonHandles.GDI); DbgUtil.AssertWin32(hFont != IntPtr.Zero, "CreateFontIndirect(logFont) failed."); return(hFont); }
public static bool Rectangle(HandleRef hdc, int left, int top, int right, int bottom) { bool retVal = IntRectangle(hdc, left, top, right, bottom); DbgUtil.AssertWin32(retVal, "Rectangle(hdc=[0x{0:X8}], left=[{1}], top=[{2}], right=[{3}], bottom=[{4}] failed.", hdc.Handle, left, top, right, bottom); return(retVal); }
public static int GetObject(HandleRef hBrush, IntNativeMethods.LOGBRUSH lb) { int retVal = IntGetObject(hBrush, System.Runtime.InteropServices.Marshal.SizeOf <IntNativeMethods.LOGBRUSH>(), lb); DbgUtil.AssertWin32(retVal != 0, "GetObject(hObj=[0x{0:X8}], [LOGBRUSH]) failed.", hBrush.Handle); return(retVal); }
public static int SetMapMode(HandleRef hDC, int nMapMode) { int oldMapMode = IntSetMapMode(hDC, nMapMode); DbgUtil.AssertWin32(oldMapMode != 0, "SetMapMode(hdc=[0x{0:X8}], MapMode=[{1}]", hDC.Handle, nMapMode); return(oldMapMode); }
public static int GetObject(HandleRef hFont, IntNativeMethods.LOGFONT lp) { int retVal = IntGetObject(hFont, System.Runtime.InteropServices.Marshal.SizeOf <IntNativeMethods.LOGFONT>(), lp); DbgUtil.AssertWin32(retVal != 0, "GetObject(hObj=[0x{0:X8}], [LOGFONT]) failed.", hFont.Handle); return(retVal); }
public static bool GetViewportExtEx(HandleRef hdc, [In, Out] IntNativeMethods.SIZE lpSize) { bool retVal = IntGetViewportExtEx(hdc, lpSize); DbgUtil.AssertWin32(retVal, "GetViewportExtEx([hdc=0x{0:X8}], [out size]) failed.", hdc.Handle); return(retVal); }
public static IntPtr SelectObject(HandleRef hdc, HandleRef obj) { IntPtr oldObj = IntSelectObject(hdc, obj); DbgUtil.AssertWin32(oldObj != IntPtr.Zero, "SelectObject(hdc=hObj=[0x{0:X8}], hObj=[0x{1:X8}]) failed.", hdc.Handle, obj.Handle); return(oldObj); }
public static bool SetViewportExtEx(HandleRef hDC, int x, int y, [In, Out] IntNativeMethods.SIZE size) { bool retVal = IntSetViewportExtEx(hDC, x, y, size); DbgUtil.AssertWin32(retVal, "SetViewportExtEx([hdc=0x{0:X8}], x=[{1}], y=[{2}], [out size]) failed.", hDC.Handle, x, y); return(retVal); }
public static bool StrokePath(HandleRef hDC) { bool retVal = IntStrokePath(hDC); DbgUtil.AssertWin32(retVal, "StrokePath(hdc=[0x{0:X8}]failed.", hDC.Handle); return(retVal); }