/*
* Util.DeviceInfo.cs
* Authors: Adam Nabinger
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
namespace Util
{
///
/// Try to get the specified Hardware param. If the value is unavailable, it will probably return 0 or -1.
/// These values are not necessarily correct, only what is reported.
///
public sealed class DeviceInfo
{
#region Enums
///
/// Defines the information obtainable from the hardware
///
private enum DeviceCap
{
///
/// Device driver version
///
DriverVersion = 0,
///
/// Device classification
///
Technology = 2,
///
/// Horizontal size in millimeters
///
HorizontalSize = 4,
///
/// Vertical size in millimeters
///
VerticalSize = 6,
///
/// Horizontal width in pixels
///
HorizontalRes = 8,
///
/// Vertical height in pixels
///
VerticalRes = 10,
///
/// Number of bits per pixel
///
BitsPerPixel = 12,
///
/// Number of planes
///
Planes = 14,
///
/// Number of brushes the device has
///
NumberBrushes = 16,
///
/// Number of pens the device has
///
NumberPens = 18,
///
/// Number of markers the device has
///
NumberMarkers = 20,
///
/// Number of fonts the device has
///
NumberFonts = 22,
///
/// Number of colors the device supports
///
NumberColors = 24,
///
/// Size required for device descriptor
///
PDeviceSize = 26,
///
/// Curve capabilities
///
CurveCaps = 28,
///
/// Line capabilities
///
LineCaps = 30,
///
/// Polygonal capabilities
///
PolygonalCaps = 32,
///
/// Text capabilities
///
TextCaps = 34,
///
/// Clipping capabilities
///
ClipCaps = 36,
///
/// Bitblt capabilities
///
RasterCaps = 38,
///
/// Length of the X leg
///
AspectX = 40,
///
/// Length of the Y leg
///
AspectY = 42,
///
/// Length of the hypotenuse
///
AspectXY = 44,
///
/// Shading and Blending caps
///
ShadeBlendCaps = 45,
///
/// Logical pixels inch in X
///
LogPixelsX = 88,
///
/// Logical pixels inch in Y
///
LogPixelsY = 90,
///
/// Number of entries in physical palette
///
SizePalette = 104,
///
/// Number of reserved entries in palette
///
NumberReserveEntries = 106,
///
/// Actual color resolution
///
ColorResolution = 108,
// Printing related DeviceCaps. These replace the appropriate Escapes
///
/// Physical Width in device units
///
PhysicalWidth = 110,
///
/// Physical Height in device units
///
PhysicalHeight = 111,
///
/// Physical Printable Area x margin
///
PhysicalOffsetX = 112,
///
/// Physical Printable Area y margin
///
PhysicalOffsetY = 113,
///
/// Scaling factor x
///
ScalingFactorX = 114,
///
/// Scaling factor y
///
ScalingFactorY = 115,
///
/// Current vertical refresh rate of the display device (for displays only) in Hz
///
VRefresh = 116,
///
/// Vertical height of entire desktop in pixels
///
DesktopVerticalRes = 117,
///
/// Horizontal width of entire desktop in pixels
///
DesktopHorizontalRes = 118,
///
/// Preferred blt alignment
///
BltAlignment = 119
}
#endregion
#region Fields
// Pointer to start of the device memory
private static readonly IntPtr hSDC = NativeMethods.GetDC(IntPtr.Zero);
#endregion
#region Properties
///
/// Horizontal size in millimeters
///
public static int PhysicalHorizontalSize
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.HorizontalSize); } }
///
/// Vertical size in millimeters
///
public static int PhysicalVerticalSize
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.VerticalSize); } }
///
/// Device driver version
///
public static int DriverVersion
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.DriverVersion); } }
///
/// Device classification
///
public static int Technology
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.Technology); } }
///
/// Horizontal width in pixels
///
public static int HorizontalRes
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.HorizontalRes); } }
///
/// Vertical height in pixels
///
public static int VerticalRes
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.VerticalRes); } }
///
/// Number of bits per pixel
///
public static int BitsPerPixel
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.BitsPerPixel); } }
///
/// Number of planes
///
public static int Planes
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.Planes); } }
///
/// Number of brushes the device has
///
public static int NumberBrushes
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.NumberBrushes); } }
///
/// Number of pens the device has
///
public static int NumberPens
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.NumberPens); } }
///
/// Number of markers the device has
///
public static int NumberMarkers
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.NumberMarkers); } }
///
/// Number of fonts the device has
///
public static int NumberFonts
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.NumberFonts); } }
///
/// Number of colors the device supports
///
public static int NumberColors
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.NumberColors); } }
///
/// Size required for device descriptor
///
public static int PDeviceSize
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.PDeviceSize); } }
///
/// Curve capabilities
///
public static int CurveCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.CurveCaps); } }
///
/// Line capabilities
///
public static int LineCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.LineCaps); } }
///
/// Polygonal capabilities
///
public static int PolygonalCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.PolygonalCaps); } }
///
/// Text capabilities
///
public static int TextCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.TextCaps); } }
///
/// Clipping capabilities
///
public static int ClipCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.ClipCaps); } }
///
/// Bitblt capabilities
///
public static int RasterCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.RasterCaps); } }
///
/// Length of the X leg
///
public static int AspectX
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.AspectX); } }
///
/// Length of the Y leg
///
public static int AspectY
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.AspectY); } }
///
/// Length of the hypotenuse
///
public static int AspectXY
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.AspectXY); } }
///
/// Shading and Blending caps
///
public static int ShadeBlendCaps
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.ShadeBlendCaps); } }
///
/// Logical pixels inch in X
///
public static int LogPixelsX
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.LogPixelsX); } }
///
/// Logical pixels inch in Y
///
public static int LogPixelsY
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.LogPixelsY); } }
///
/// Number of entries in physical palette
///
public static int SizePalette
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.SizePalette); } }
///
/// Number of reserved entries in palette
///
public static int NumberReserveEntries
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.NumberReserveEntries); } }
///
/// Actual color resolution
///
public static int ColorResolution
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.ColorResolution); } }
///
/// Physical Width in device units
///
public static int PhysicalWidth
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.PhysicalWidth); } }
///
/// Physical Height in device units
///
public static int PhysicalHeight
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.PhysicalHeight); } }
///
/// Physical Printable Area x margin
///
public static int PhysicalOffsetX
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.PhysicalOffsetX); } }
///
/// Physical Printable Area y margin
///
public static int PhysicalOffsetY
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.PhysicalOffsetY); } }
///
/// Scaling factor x
///
public static int ScalingFactorX
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.ScalingFactorX); } }
///
/// Scaling factor y
///
public static int ScalingFactorY
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.ScalingFactorY); } }
///
/// Current vertical refresh rate of the display device (for displays only) in Hz
///
public static int VRefresh
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.VRefresh); } }
///
/// Vertical height of entire desktop in pixels
///
public static int DesktopVerticalRes
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.DesktopVerticalRes); } }
///
/// Horizontal width of entire desktop in pixels
///
public static int DesktopHorizontalRes
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.DesktopHorizontalRes); } }
///
/// Preferred blt alignment
///
public static int BltAlignment
{ get { return NativeMethods.GetDeviceCaps(hSDC, (int)DeviceCap.BltAlignment); } }
#endregion
#region Deconstructor
///
/// Release when no longer needed.
///
~DeviceInfo()
{
NativeMethods.ReleaseDC(IntPtr.Zero, hSDC);
}
#endregion
}
}