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(); }
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); } } }
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(); }