Пример #1
0
 private void CacheInitialState()
 {
     this.hCurrentPen   = this.hInitialPen = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, this.hDC), 1);
     this.hCurrentBrush = this.hInitialBrush = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, this.hDC), 2);
     this.hCurrentBmp   = this.hInitialBmp = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, this.hDC), 7);
     this.hCurrentFont  = this.hInitialFont = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, this.hDC), 6);
 }
Пример #2
0
        /// <summary>
        ///  Creates a WindowsFont from the font selected in the supplied dc.
        /// </summary>
        public static WindowsFont FromHdc(IntPtr hdc)
        {
            IntPtr hFont = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(null, hdc), IntNativeMethods.OBJ_FONT);

            // don't call DeleteObject on handle from GetCurrentObject, it is the one selected in the hdc.

            return(FromHfont(hFont));
        }
Пример #3
0
        // Due to a problem with calling DeleteObject() on currently selected GDI objects,
        // we now track the initial set of objects when a DeviceContext is created.  Then,
        // we also track which objects are currently selected in the DeviceContext.  When
        // a currently selected object is disposed, it is first replaced in the DC and then
        // deleted.

        private void CacheInitialState()
        {
            Debug.Assert(hDC != IntPtr.Zero, "Cannot get initial state without a valid HDC");
            hCurrentPen   = hInitialPen = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, hDC), IntNativeMethods.OBJ_PEN);
            hCurrentBrush = hInitialBrush = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, hDC), IntNativeMethods.OBJ_BRUSH);
            hCurrentBmp   = hInitialBmp = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, hDC), IntNativeMethods.OBJ_BITMAP);
            hCurrentFont  = hInitialFont = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, hDC), IntNativeMethods.OBJ_FONT);
        }
Пример #4
0
 internal void DisposeFont(bool disposing)
 {
     if (disposing)
     {
         DeviceContexts.RemoveDeviceContext(this);
     }
     if ((this.selectedFont != null) && (this.selectedFont.Hfont != IntPtr.Zero))
     {
         if (IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, this.hDC), 6) == this.selectedFont.Hfont)
         {
             IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(null, this.hInitialFont));
             IntPtr hInitialFont = this.hInitialFont;
         }
         this.selectedFont.Dispose(disposing);
         this.selectedFont = null;
     }
 }
Пример #5
0
        internal void DisposeFont(bool disposing)
        {
            if (disposing)
            {
                DeviceContexts.RemoveDeviceContext(this);
            }

            if (selectedFont != null && selectedFont.Hfont != IntPtr.Zero)
            {
                IntPtr hCurrentFont = IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(this, hDC), IntNativeMethods.OBJ_FONT);
                if (hCurrentFont == selectedFont.Hfont)
                {
                    // select initial font back in
                    IntUnsafeNativeMethods.SelectObject(new HandleRef(this, Hdc), new HandleRef(null, hInitialFont));
                    hCurrentFont = hInitialFont;
                }

                selectedFont.Dispose(disposing);
                selectedFont = null;
            }
        }
Пример #6
0
 public static WindowsFont FromHdc(IntPtr hdc)
 {
     return(FromHfont(IntUnsafeNativeMethods.GetCurrentObject(new HandleRef(null, hdc), 6)));
 }