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); }
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(); } }
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); }
public static IntPtr SelectObject(SafeDC hdc, SafeHBITMAP hgdiobj) { IntPtr intPtr = NativeMethods._SelectObjectSafeHBITMAP(hdc, hgdiobj); if (intPtr == IntPtr.Zero) { HRESULT.ThrowLastError(); } return(intPtr); }
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); }
public static IntPtr SelectObject(SafeDC hdc, IntPtr hgdiobj) { IntPtr intPtr = Standard.NativeMethods.SelectObject_1(hdc, hgdiobj); if (intPtr == IntPtr.Zero) { HRESULT.ThrowLastError(); } return(intPtr); }
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); }
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); }
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); }
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); } }
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); } }
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); } }
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); }
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); }
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); }
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); }
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);
public static IntPtr SelectObject(SafeDC hdc, SafeHBITMAP hgdiobj) { IntPtr ret = _SelectObjectSafeHBITMAP(hdc, hgdiobj); if (ret == IntPtr.Zero) { HRESULT.ThrowLastError(); } return ret; }
private static extern IntPtr _SelectObjectSafeHBITMAP(SafeDC hdc, SafeHBITMAP hgdiobj);
private static extern IntPtr _SelectObject(SafeDC hdc, IntPtr hgdiobj);
public static extern int GetDeviceCaps(SafeDC hdc, DeviceCap nIndex);
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; }
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(); } } }
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; }
public static IntPtr SelectObject(SafeDC hdc, IntPtr hgdiobj) { var ret = _SelectObject(hdc, hgdiobj); if (ret == IntPtr.Zero) { HRESULT.ThrowLastError(); } return ret; }
private static extern SafeHBITMAP _CreateDIBSection(SafeDC hdc, [In] ref BITMAPINFO bitmapInfo, int iUsage, out IntPtr ppvBits, IntPtr hSection, int dwOffset);
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);
public static SafeDC GetDesktop() { return(SafeDC.GetDC(IntPtr.Zero)); }
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(); } }
private static extern SafeHBITMAP _CreateDIBSection(SafeDC hdc, [In] ref BITMAPINFO bitmapInfo, int iUsage, [Out] out IntPtr ppvBits, IntPtr hSection, int dwOffset);