Ejemplo n.º 1
0
    static DpiHelper()
    {
        var dC = InteropMethods.GetDC(IntPtr.Zero);

        if (dC != IntPtr.Zero)
        {
            // 沿着屏幕宽度每逻辑英寸的像素数。在具有多个显示器的系统中,这个值对所有显示器都是相同的
            const int logicPixelsX = 88;
            // 沿着屏幕高度每逻辑英寸的像素数
            const int logicPixelsY = 90;
            DeviceDpiX = InteropMethods.GetDeviceCaps(dC, logicPixelsX);
            DeviceDpiY = InteropMethods.GetDeviceCaps(dC, logicPixelsY);
            InteropMethods.ReleaseDC(IntPtr.Zero, dC);
        }
        else
        {
            DeviceDpiX = LogicalDpi;
            DeviceDpiY = LogicalDpi;
        }

        var identity  = Matrix.Identity;
        var identity2 = Matrix.Identity;

        identity.Scale(DeviceDpiX / LogicalDpi, DeviceDpiY / LogicalDpi);
        identity2.Scale(LogicalDpi / DeviceDpiX, LogicalDpi / DeviceDpiY);
        TransformFromDevice = new MatrixTransform(identity2);
        TransformFromDevice.Freeze();
        TransformToDevice = new MatrixTransform(identity);
        TransformToDevice.Freeze();
    }
Ejemplo n.º 2
0
        private static void EnsureSystemMetrics()
        {
            if (SystemBitDepth == 0)
            {
                var hdcDesktop = new HandleRef(null, InteropMethods.GetDC(new HandleRef()));
                try
                {
                    var sysBitDepth = InteropMethods.GetDeviceCaps(hdcDesktop, InteropValues.BITSPIXEL);
                    sysBitDepth *= InteropMethods.GetDeviceCaps(hdcDesktop, InteropValues.PLANES);

                    if (sysBitDepth == 8)
                    {
                        sysBitDepth = 4;
                    }

                    var cxSmallIcon = InteropMethods.GetSystemMetrics(InteropValues.SM.CXSMICON);
                    var cySmallIcon = InteropMethods.GetSystemMetrics(InteropValues.SM.CYSMICON);
                    var cxIcon      = InteropMethods.GetSystemMetrics(InteropValues.SM.CXICON);
                    var cyIcon      = InteropMethods.GetSystemMetrics(InteropValues.SM.CYICON);

                    SmallIconSize  = new Size(cxSmallIcon, cySmallIcon);
                    IconSize       = new Size(cxIcon, cyIcon);
                    SystemBitDepth = sysBitDepth;
                }
                finally
                {
                    InteropMethods.ReleaseDC(new HandleRef(), hdcDesktop);
                }
            }
        }
Ejemplo n.º 3
0
        static DpiHelper()
        {
            var dC = InteropMethods.GetDC(IntPtr.Zero);

            if (dC != IntPtr.Zero)
            {
                DeviceDpiX = InteropMethods.GetDeviceCaps(dC, 88);
                DeviceDpiY = InteropMethods.GetDeviceCaps(dC, 90);
                InteropMethods.ReleaseDC(IntPtr.Zero, dC);
            }
            else
            {
                DeviceDpiX = LogicalDpi;
                DeviceDpiY = LogicalDpi;
            }

            var identity  = Matrix.Identity;
            var identity2 = Matrix.Identity;

            identity.Scale(DeviceDpiX / LogicalDpi, DeviceDpiY / LogicalDpi);
            identity2.Scale(LogicalDpi / DeviceDpiX, LogicalDpi / DeviceDpiY);
            TransformFromDevice = new MatrixTransform(identity2);
            TransformFromDevice.Freeze();
            TransformToDevice = new MatrixTransform(identity);
            TransformToDevice.Freeze();
        }
Ejemplo n.º 4
0
 internal GlowDrawingContext(int width, int height)
 {
     ScreenDC = InteropMethods.GetDC(IntPtr.Zero);
     if (ScreenDC == IntPtr.Zero)
     {
         return;
     }
     WindowDC = InteropMethods.CreateCompatibleDC(ScreenDC);
     if (WindowDC == IntPtr.Zero)
     {
         return;
     }
     BackgroundDC = InteropMethods.CreateCompatibleDC(ScreenDC);
     if (BackgroundDC == IntPtr.Zero)
     {
         return;
     }
     Blend.BlendOp             = 0;
     Blend.BlendFlags          = 0;
     Blend.SourceConstantAlpha = 255;
     Blend.AlphaFormat         = 1;
     _windowBitmap             = new GlowBitmap(ScreenDC, width, height);
     InteropMethods.SelectObject(WindowDC, _windowBitmap.Handle);
 }