상속: Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
예제 #1
0
        public static SafeDC CreateCompatibleDC(SafeDC hdc)
        {
            SafeDC safeDC = null;

            try
            {
                IntPtr hdc2 = IntPtr.Zero;
                if (hdc != null)
                {
                    hdc2 = hdc.handle;
                }
                safeDC = SafeDC.NativeMethods.CreateCompatibleDC(hdc2);
                if (safeDC == null)
                {
                    HRESULT.ThrowLastError();
                }
            }
            finally
            {
                if (safeDC != null)
                {
                    safeDC._created = true;
                }
            }
            if (safeDC.IsInvalid)
            {
                safeDC.Dispose();
                throw new SystemException("Unable to create a device context from the specified device information.");
            }
            return(safeDC);
        }
예제 #2
0
 public static void UpdateLayeredWindow(IntPtr hwnd, SafeDC hdcDst, ref POINT pptDst, ref SIZE psize, SafeDC hdcSrc, ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags)
 {
     if (!NativeMethods._UpdateLayeredWindow(hwnd, hdcDst, ref pptDst, ref psize, hdcSrc, ref pptSrc, crKey, ref pblend, dwFlags))
     {
         HRESULT.ThrowLastError();
     }
 }
예제 #3
0
        public static SafeDC CreateDC(string deviceName)
        {
            SafeDC dc = null;

            try
            {
                // Should this really be on the driver parameter?
                dc = NativeMethods.CreateDC(deviceName, null, IntPtr.Zero, IntPtr.Zero);
            }
            finally
            {
                if (dc != null)
                {
                    dc._created = true;
                }
            }

            if (dc.IsInvalid)
            {
                dc.Dispose();
                throw new SystemException("Unable to create a device context from the specified device information.");
            }

            return(dc);
        }
예제 #4
0
        public static IntPtr SelectObject(SafeDC hdc, SafeHBITMAP hgdiobj)
        {
            IntPtr intPtr = NativeMethods._SelectObjectSafeHBITMAP(hdc, hgdiobj);

            if (intPtr == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
예제 #5
0
 private static int s_bitDepth;         // = 0;
 private static int _GetBitDepth()
 {
     if (s_bitDepth != 0)
     {
         return(s_bitDepth);
     }
     using (var dc = SafeDC.GetDesktop())
         s_bitDepth = NativeMethods.GetDeviceCaps(dc, DeviceCap.BITSPIXEL) * NativeMethods.GetDeviceCaps(dc, DeviceCap.PLANES);
     return(s_bitDepth);
 }
예제 #6
0
        public static IntPtr SelectObject(SafeDC hdc, IntPtr hgdiobj)
        {
            IntPtr intPtr = Standard.NativeMethods.SelectObject_1(hdc, hgdiobj);

            if (intPtr == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
예제 #7
0
 private static int _GetBitDepth()
 {
     if (s_bitDepth == 0)
     {
         using (SafeDC dc = SafeDC.GetDesktop())
         {
             s_bitDepth = NativeMethodsShell.GetDeviceCaps(dc, DeviceCap.BITSPIXEL) * NativeMethodsShell.GetDeviceCaps(dc, DeviceCap.PLANES);
         }
     }
     return(s_bitDepth);
 }
예제 #8
0
        public static SafeHBITMAP CreateDIBSection(SafeDC hdc, ref BITMAPINFO bitmapInfo, out IntPtr ppvBits, IntPtr hSection, int dwOffset)
        {
            SafeHBITMAP safeHBITMAP = null;

            safeHBITMAP = (hdc != null ? Standard.NativeMethods.CreateDIBSection_1(hdc, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset) : Standard.NativeMethods.CreateDIBSection_2(IntPtr.Zero, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset));
            if (safeHBITMAP.IsInvalid)
            {
                HRESULT.ThrowLastError();
            }
            return(safeHBITMAP);
        }
예제 #9
0
 private static int _GetBitDepth()
 {
     if (Utility.s_bitDepth == 0)
     {
         using (SafeDC desktop = SafeDC.GetDesktop())
         {
             Utility.s_bitDepth = NativeMethods.GetDeviceCaps(desktop, DeviceCap.BITSPIXEL) * NativeMethods.GetDeviceCaps(desktop, DeviceCap.PLANES);
         }
     }
     return(Utility.s_bitDepth);
 }
예제 #10
0
 static DpiHelper()
 {
     using (SafeDC desktop = SafeDC.GetDesktop())
     {
         int deviceCaps  = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSX);
         int deviceCaps2 = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSY);
         DpiHelper._transformToDip = Matrix.Identity;
         DpiHelper._transformToDip.Scale(96.0 / (double)deviceCaps, 96.0 / (double)deviceCaps2);
         DpiHelper._transformToDevice = Matrix.Identity;
         DpiHelper._transformToDevice.Scale((double)deviceCaps / 96.0, (double)deviceCaps2 / 96.0);
     }
 }
예제 #11
0
		static DpiHelper()
		{
			Class6.yDnXvgqzyB5jw();
			using (SafeDC desktop = SafeDC.GetDesktop())
			{
				int deviceCaps = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSX);
				int num = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSY);
				DpiHelper._transformToDip = Matrix.Identity;
				DpiHelper._transformToDip.Scale(96 / (double)deviceCaps, 96 / (double)num);
				DpiHelper._transformToDevice = Matrix.Identity;
				DpiHelper._transformToDevice.Scale((double)deviceCaps / 96, (double)num / 96);
			}
		}
예제 #12
0
 static DpiHelper()
 {
     using (var desktop = SafeDC.GetDesktop())
     {
         // Can get these in the static constructor.  They shouldn't vary window to window,
         // and changing the system DPI requires a restart.
         var pixelsPerInchX = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSX);
         var pixelsPerInchY = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSY);
         _transformToDip = Matrix.Identity;
         _transformToDip.Scale(96d / pixelsPerInchX, 96d / pixelsPerInchY);
         _transformToDevice = Matrix.Identity;
         _transformToDevice.Scale(pixelsPerInchX / 96d, pixelsPerInchY / 96d);
     }
 }
예제 #13
0
        public static SafeHBITMAP CreateDIBSection(SafeDC hdc, ref BITMAPINFO bitmapInfo, out IntPtr ppvBits, IntPtr hSection, int dwOffset)
        {
            SafeHBITMAP safeHBITMAP;

            if (hdc == null)
            {
                safeHBITMAP = NativeMethods._CreateDIBSectionIntPtr(IntPtr.Zero, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset);
            }
            else
            {
                safeHBITMAP = NativeMethods._CreateDIBSection(hdc, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset);
            }
            if (safeHBITMAP.IsInvalid)
            {
                HRESULT.ThrowLastError();
            }
            return(safeHBITMAP);
        }
예제 #14
0
        public static SafeDC GetDC(IntPtr hwnd)
        {
            SafeDC safeDC = null;

            try
            {
                safeDC = SafeDC.NativeMethods.GetDC(hwnd);
            }
            finally
            {
                if (safeDC != null)
                {
                    safeDC.Hwnd = hwnd;
                }
            }
            if (safeDC.IsInvalid)
            {
                HRESULT.E_FAIL.ThrowIfFailed();
            }
            return(safeDC);
        }
예제 #15
0
        public static SafeDC CreateDC(string deviceName)
        {
            SafeDC safeDC = null;

            try
            {
                safeDC = SafeDC.NativeMethods.CreateDC(deviceName, null, IntPtr.Zero, IntPtr.Zero);
            }
            finally
            {
                if (safeDC != null)
                {
                    safeDC._created = true;
                }
            }
            if (safeDC.IsInvalid)
            {
                safeDC.Dispose();
                throw new SystemException("Unable to create a device context from the specified device information.");
            }
            return(safeDC);
        }
예제 #16
0
        public static SafeDC GetDC(IntPtr hwnd)
        {
            SafeDC dc = null;

            try
            {
                dc = NativeMethods.GetDC(hwnd);
            }
            finally
            {
                if (dc != null)
                {
                    dc.Hwnd = hwnd;
                }
            }

            if (dc.IsInvalid)
            {
                // GetDC does not set the last error...
                HRESULT.E_FAIL.ThrowIfFailed();
            }

            return(dc);
        }
예제 #17
0
 private static extern bool _UpdateLayeredWindow(
     IntPtr hwnd,
     SafeDC hdcDst,
     [In] ref POINT pptDst,
     [In] ref SIZE psize,
     SafeDC hdcSrc,
     [In] ref POINT pptSrc,
     int crKey,
     ref BLENDFUNCTION pblend,
     ULW dwFlags);
예제 #18
0
 public static IntPtr SelectObject(SafeDC hdc, SafeHBITMAP hgdiobj)
 {
     IntPtr ret = _SelectObjectSafeHBITMAP(hdc, hgdiobj);
     if (ret == IntPtr.Zero)
     {
         HRESULT.ThrowLastError();
     }
     return ret;
 }
예제 #19
0
 private static extern IntPtr _SelectObjectSafeHBITMAP(SafeDC hdc, SafeHBITMAP hgdiobj);
예제 #20
0
 private static extern IntPtr _SelectObject(SafeDC hdc, IntPtr hgdiobj);
예제 #21
0
 public static extern int GetDeviceCaps(SafeDC hdc, DeviceCap nIndex);
예제 #22
0
        public static SafeHBITMAP CreateDIBSection(SafeDC hdc, ref BITMAPINFO bitmapInfo, out IntPtr ppvBits, IntPtr hSection, int dwOffset)
        {
            const int DIB_RGB_COLORS = 0;
            SafeHBITMAP hBitmap = null;
            if (hdc == null)
            {
                hBitmap = _CreateDIBSectionIntPtr(IntPtr.Zero, ref bitmapInfo, DIB_RGB_COLORS, out ppvBits, hSection, dwOffset);
            }
            else
            {
                hBitmap = _CreateDIBSection(hdc, ref bitmapInfo, DIB_RGB_COLORS, out ppvBits, hSection, dwOffset);
            }

            if (hBitmap.IsInvalid)
            {
                HRESULT.ThrowLastError();
            }

            return hBitmap;
        }
예제 #23
0
        public void Show()
        {
            _VerifyMutability();

            using (Stream imageStream = _GetImageStream())
            {
                Size bitmapSize;
                _hBitmap = _CreateHBITMAPFromImageStream(imageStream, out bitmapSize);

                Point location = new Point(
                    (NativeMethods.GetSystemMetrics(SM.CXSCREEN) - bitmapSize.Width) / 2,
                    (NativeMethods.GetSystemMetrics(SM.CYSCREEN) - bitmapSize.Height) / 2);

                // Pass a null WndProc.  Let the MessageWindow use DefWindowProc.
                _hwndWrapper = new MessageWindow(
                    CS.HREDRAW | CS.VREDRAW,
                    WS.POPUP | WS.VISIBLE,
                    WS_EX.WINDOWEDGE | WS_EX.TOOLWINDOW | WS_EX.LAYERED | (IsTopMost ? WS_EX.TOPMOST : 0),
                    new Rect(location, bitmapSize),
                    "Splash Screen",
                    null);

                byte opacity = (byte)(FadeInDuration > TimeSpan.Zero ? 0 : 255);

                using (SafeDC hScreenDC = SafeDC.GetDesktop())
                {
                    using (SafeDC memDC = SafeDC.CreateCompatibleDC(hScreenDC))
                    {
                        IntPtr hOldBitmap = NativeMethods.SelectObject(memDC, _hBitmap);

                        RECT hwndRect = NativeMethods.GetWindowRect(_hwndWrapper.Handle);

                        POINT         hwndPos  = hwndRect.Position;
                        SIZE          hwndSize = hwndRect.Size;
                        POINT         origin   = new POINT();
                        BLENDFUNCTION bf       = _BaseBlendFunction;
                        bf.SourceConstantAlpha = opacity;

                        NativeMethods.UpdateLayeredWindow(_hwndWrapper.Handle, hScreenDC, ref hwndPos, ref hwndSize, memDC, ref origin, 0, ref bf, ULW.ALPHA);
                        NativeMethods.SelectObject(memDC, hOldBitmap);
                    }
                }

                if (CloseOnMainWindowCreation)
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        DispatcherPriority.Loaded,
                        (DispatcherOperationCallback) delegate(object splashObj)
                    {
                        var splashScreen = (SplashScreen)splashObj;
                        if (!splashScreen._isClosed)
                        {
                            splashScreen.Close();
                        }
                        return(null);
                    },
                        this);
                }

                _dispatcher = Dispatcher.CurrentDispatcher;
                if (FadeInDuration > TimeSpan.Zero)
                {
                    _fadeInEnd = DateTime.UtcNow + FadeInDuration;
                    _dt        = new DispatcherTimer(FadeInDuration, DispatcherPriority.Normal, _FadeInTick, _dispatcher);
                    _dt.Start();
                }
            }
        }
예제 #24
0
        public static SafeDC CreateCompatibleDC(SafeDC hdc)
        {
            SafeDC dc = null;
            try
            {
                IntPtr hPtr = IntPtr.Zero;
                if (hdc != null)
                {
                    hPtr = hdc.handle;
                }
                dc = NativeMethods.CreateCompatibleDC(hPtr);
                if (dc == null)
                {
                    HRESULT.ThrowLastError();
                }
            }
            finally
            {
                if (dc != null)
                {
                    dc._created = true;
                }
            }

            if (dc.IsInvalid)
            {
                dc.Dispose();
                throw new SystemException("Unable to create a device context from the specified device information.");
            }

            return dc;
        }
예제 #25
0
 public static IntPtr SelectObject(SafeDC hdc, IntPtr hgdiobj)
 {
     var ret = _SelectObject(hdc, hgdiobj);
     if (ret == IntPtr.Zero)
     {
         HRESULT.ThrowLastError();
     }
     return ret;
 }
예제 #26
0
 private static extern SafeHBITMAP _CreateDIBSection(SafeDC hdc, [In] ref BITMAPINFO bitmapInfo, int iUsage, out IntPtr ppvBits, IntPtr hSection, int dwOffset);
예제 #27
0
 public static extern int GetDeviceCaps(SafeDC hdc, DeviceCap nIndex);
예제 #28
0
 private static extern bool _UpdateLayeredWindow(IntPtr hwnd, SafeDC hdcDst, [In] ref POINT pptDst, [In] ref SIZE psize, SafeDC hdcSrc, [In] ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags);
예제 #29
0
 public static SafeDC GetDesktop()
 {
     return(SafeDC.GetDC(IntPtr.Zero));
 }
예제 #30
0
 public static void UpdateLayeredWindow(
     IntPtr hwnd,
     SafeDC hdcDst,
     ref POINT pptDst,
     ref SIZE psize,
     SafeDC hdcSrc,
     ref POINT pptSrc,
     int crKey,
     ref BLENDFUNCTION pblend,
     ULW dwFlags)
 {
     if (!_UpdateLayeredWindow(hwnd, hdcDst, ref pptDst, ref psize, hdcSrc, ref pptSrc, crKey, ref pblend, dwFlags))
     {
         HRESULT.ThrowLastError();
     }
 }
예제 #31
0
 private static extern SafeHBITMAP _CreateDIBSection(SafeDC hdc, [In] ref BITMAPINFO bitmapInfo, int iUsage, [Out] out IntPtr ppvBits, IntPtr hSection, int dwOffset);
예제 #32
0
 private static extern IntPtr _SelectObjectSafeHBITMAP(SafeDC hdc, SafeHBITMAP hgdiobj);
예제 #33
0
 private static extern IntPtr _SelectObject(SafeDC hdc, IntPtr hgdiobj);