public void DeleteObject(IntPtr handle, GdiObjectType type)
        {
            IntPtr zero = IntPtr.Zero;
            switch (type)
            {
                case GdiObjectType.Pen:
                    if (handle == this.hCurrentPen)
                    {
                        IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(this, this.hInitialPen));
                        this.hCurrentPen = IntPtr.Zero;
                    }
                    zero = handle;
                    break;

                case GdiObjectType.Brush:
                    if (handle == this.hCurrentBrush)
                    {
                        IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(this, this.hInitialBrush));
                        this.hCurrentBrush = IntPtr.Zero;
                    }
                    zero = handle;
                    break;

                case GdiObjectType.Bitmap:
                    if (handle == this.hCurrentBmp)
                    {
                        IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(this, this.hInitialBmp));
                        this.hCurrentBmp = IntPtr.Zero;
                    }
                    zero = handle;
                    break;
            }
            IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, zero));
        }
示例#2
0
        public void DeleteObject(IntPtr handle, GdiObjectType type)
        {
            IntPtr handleToDelete = IntPtr.Zero;

            switch (type)
            {
            case GdiObjectType.Pen:
                if (handle == hCurrentPen)
                {
                    IntPtr currentPen = Gdi32.SelectObject(new HandleRef(this, Hdc), hInitialPen);
                    Debug.Assert(currentPen == hCurrentPen, "DeviceContext thinks a different pen is selected than the HDC");
                    hCurrentPen = IntPtr.Zero;
                }
                handleToDelete = handle;
                break;

            case GdiObjectType.Brush:
                if (handle == hCurrentBrush)
                {
                    IntPtr currentBrush = Gdi32.SelectObject(new HandleRef(this, Hdc), hInitialBrush);
                    Debug.Assert(currentBrush == hCurrentBrush, "DeviceContext thinks a different brush is selected than the HDC");
                    hCurrentBrush = IntPtr.Zero;
                }
                handleToDelete = handle;
                break;

            case GdiObjectType.Bitmap:
                if (handle == hCurrentBmp)
                {
                    IntPtr currentBmp = Gdi32.SelectObject(new HandleRef(this, Hdc), hInitialBmp);
                    Debug.Assert(currentBmp == hCurrentBmp, "DeviceContext thinks a different brush is selected than the HDC");
                    hCurrentBmp = IntPtr.Zero;
                }
                handleToDelete = handle;
                break;
            }

            Gdi32.DeleteObject(handleToDelete);
        }
示例#3
0
        public void DeleteObject(Gdi32.HGDIOBJ handle, GdiObjectType type)
        {
            Gdi32.HGDIOBJ handleToDelete = default;
            switch (type)
            {
            case GdiObjectType.Pen:
                if (handle == _hCurrentPen)
                {
                    Gdi32.HGDIOBJ currentPen = Gdi32.SelectObject(this, _hInitialPen);
                    Debug.Assert(currentPen == _hCurrentPen, "DeviceContext thinks a different pen is selected than the HDC");
                    _hCurrentPen = default;
                }
                handleToDelete = handle;
                break;

            case GdiObjectType.Brush:
                if (handle == _hCurrentBrush)
                {
                    Gdi32.HGDIOBJ currentBrush = Gdi32.SelectObject(this, _hInitialBrush);
                    Debug.Assert(currentBrush == _hCurrentBrush, "DeviceContext thinks a different brush is selected than the HDC");
                    _hCurrentBrush = default;
                }
                handleToDelete = handle;
                break;

            case GdiObjectType.Bitmap:
                if (handle == _hCurrentBmp)
                {
                    Gdi32.HGDIOBJ currentBmp = Gdi32.SelectObject(this, _hInitialBmp);
                    Debug.Assert(currentBmp == _hCurrentBmp, "DeviceContext thinks a different brush is selected than the HDC");
                    _hCurrentBmp = default;
                }
                handleToDelete = handle;
                break;
            }

            Gdi32.DeleteObject(handleToDelete);
        }
        public IntPtr SelectObject(IntPtr hObj, GdiObjectType type)
        {
            switch (type)
            {
                case GdiObjectType.Pen:
                    this.hCurrentPen = hObj;
                    break;

                case GdiObjectType.Brush:
                    this.hCurrentBrush = hObj;
                    break;

                case GdiObjectType.Bitmap:
                    this.hCurrentBmp = hObj;
                    break;
            }
            return IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(null, hObj));
        }
        public void DeleteObject(IntPtr handle, GdiObjectType type) {
            IntPtr handleToDelete = IntPtr.Zero;
            switch (type) {
                case GdiObjectType.Pen:
                    if (handle == hCurrentPen) {
                        IntPtr currentPen = IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef( this, hInitialPen));
                        Debug.Assert(currentPen == hCurrentPen, "DeviceContext thinks a different pen is selected than the HDC");
                        hCurrentPen = IntPtr.Zero;
                    }
                    handleToDelete = handle;
                    break;
                case GdiObjectType.Brush:
                    if (handle == hCurrentBrush) {
                        IntPtr currentBrush = IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef( this, hInitialBrush));
                        Debug.Assert(currentBrush == hCurrentBrush, "DeviceContext thinks a different brush is selected than the HDC");
                        hCurrentBrush = IntPtr.Zero;
                    }
                    handleToDelete = handle;
                    break;
                case GdiObjectType.Bitmap:
                    if (handle == hCurrentBmp) {
                        IntPtr currentBmp = IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef( this, hInitialBmp));
                        Debug.Assert(currentBmp == hCurrentBmp, "DeviceContext thinks a different brush is selected than the HDC");
                        hCurrentBmp = IntPtr.Zero;
                    }
                    handleToDelete = handle;
                    break;
            }

            IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, handleToDelete));
        }