using System;
using Systemm = System;
using Forms = System.Windows.Forms;
using System.Windows.Forms;
using System.Drawing;
namespace Trigger.Classes.Screen
{
/// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space
public enum FixedOutput : byte
{
/// The display's default setting.
Default = 0,
/// The low-resolution image is centered in the larger screen space.
Stretch = 1,
/// The low-resolution image is stretched to fill the larger screen space.
Center = 2,
}
/// Specifies the color resolution, in bits per pixel, of the display device
public enum ColorDepth : byte
{
/// 4 Bit -> 16 Colors
_16_Colors = 4,
/// 4 Bit -> 16 Colors
_4bit = 4,
/// 8 Bit -> 256 Colors
_256_Colors = 8,
/// 8 Bit -> 256 Colors
_8bit = 8,
/// 16 Bit -> 65.536 Colors
_65536_Colors = 16,
/// 16 Bit -> 65.536 Colors
_16bit = 16,
/// 32 Bit -> 4.294.967.296 Colors
_4294967296_Colors = 32,
/// 32 Bit -> 4.294.967.296 Colors
_32bit = 32,
}
/// A class that provides more information than
public class ScreenEx : Device.Device // : Forms.Screen
{
#region Properties
/// Gets the bounds of the display.
private Rectangle bounds;
/// Gets the bounds of the display.
public Rectangle Bounds
{
get { return bounds; }
set
{
bounds = value;
this.fields |= DM.PELSWIDTH | DM.PELSHEIGHT;
}
}
/// Specifies the color resolution, in bits per pixel, of the display device
private byte bitsPerPixel;
/// Specifies the color resolution, in bits per pixel, of the display device
public byte BitsPerPixel
{
get { return bitsPerPixel; }
set
{
bitsPerPixel = value;
fields |= DM.BITSPERPEL;
}
}
/// Specifies the color resolution, in bits per pixel, of the display device
public ColorDepth ColorDepth
{
get { return (ColorDepth)this.BitsPerPixel; }
set { this.BitsPerPixel = (byte)value; }
}
/// Gets a value indicating whether a particular display is the primary device.
private bool primary;
/// Gets a value indicating whether a particular display is the primary device.
public bool Primary
{
get { return primary; }
private set { primary = value; }
}
/// The version number of the initialization data specification on which the structure is based
private short specVersion;
/// The version number of the initialization data specification on which the structure is based
public short SpecVersion
{
get { return specVersion; }
private set { specVersion = value; }
}
/// The driver version number assigned by the driver developer
private short driverVersion;
/// The driver version number assigned by the driver developer
public short DriverVersion
{
get { return driverVersion; }
private set { driverVersion = value; }
}
/// For display devices only, the orientation at which images should be presented.
private Forms.ScreenOrientation orientation;
/// For display devices only, the orientation at which images should be presented.
public Forms.ScreenOrientation Orientation
{
get { return orientation; }
set
{
orientation = value;
fields |= DM.DISPLAYORIENTATION;
}
}
/// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space
private FixedOutput fixedOutput;
/// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space
public FixedOutput FixedOutput
{
get { return fixedOutput; }
set
{
fixedOutput = value;
fields |= DM.DISPLAYFIXEDOUTPUT;
}
}
/// The number of pixels per logical inch.
private short logPixels;
/// The number of pixels per logical inch.
public short LogPixels
{
get { return logPixels; }
set
{
logPixels = value;
fields |= DM.LOGPIXELS;
}
}
/// Specifies the device's display mode. This member can be a combination of the following values.
///
/// GRAYSCALE: Specifies that the display is a noncolor device. If this flag is not set, color is assumed.
/// INTERLACED: Specifies that the display mode is interlaced. If the flag is not set, noninterlaced is assumed.
///
private int displayFlags;
/// Specifies the device's display mode. This member can be a combination of the following values.
///
/// GRAYSCALE: Specifies that the display is a noncolor device. If this flag is not set, color is assumed.
/// INTERLACED: Specifies that the display mode is interlaced. If the flag is not set, noninterlaced is assumed.
///
public int DisplayFlags
{
get { return displayFlags; }
set
{
displayFlags = value;
fields |= DM.DISPLAYFLAGS;
}
}
///
/// Specifies the frequency, in hertz (cycles per second), of the display device in a particular mode. This value is also known as the display device's vertical refresh rate. Display drivers use this member. It is used, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member.
/// May be the value 0 or 1. These values represent the display hardware's default refresh rate. This default rate is typically set by switches on a display card or computer motherboard, or by a configuration program that does not use display functions such as ChangeDisplaySettings.
///
private byte frequency;
///
/// Specifies the frequency, in hertz (cycles per second), of the display device in a particular mode. This value is also known as the display device's vertical refresh rate. Display drivers use this member. It is used, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member.
/// May be the value 0 or 1. These values represent the display hardware's default refresh rate. This default rate is typically set by switches on a display card or computer motherboard, or by a configuration program that does not use display functions such as ChangeDisplaySettings.
///
public byte Frequency
{
get { return frequency; }
set
{
frequency = value;
fields |= DM.DISPLAYFREQUENCY;
}
}
/// Specifies whether certain members of the DEVMODE structure have been initialized. If a member is initialized, its corresponding bit is set, otherwise the bit is clear. A driver supports only those DEVMODE members that are appropriate for the printer or display technology.
/// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565%28v=vs.85%29.aspx
private DM fields = 0;
#endregion
#region enum Field
///
/// Specifies whether certain members of the DEVMODE structure have been initialized. If a member is initialized, its corresponding bit is set, otherwise the bit is clear. A driver supports only those DEVMODE members that are appropriate for the printer or display technology.
///
[Flags]
private enum DM : int
{
///
ORIENTATION = 0x00000001,
///
PAPERSIZE = 0x00000002,
///
PAPERLENGTH = 0x00000004,
///
PAPERWIDTH = 0x00000008,
///
SCALE = 0x00000010,
///
COPIES = 0x00000100,
///
DEFAULTSOURCE = 0x00000200,
///
PRINTQUALITY = 0x00000400,
///
POSITION = 0x00000020,
///
DISPLAYORIENTATION = 0x00000080,
///
DISPLAYFIXEDOUTPUT = 0x20000000,
///
COLOR = 0x00000800,
///
DUPLEX = 0x00001000,
///
YRESOLUTION = 0x00002000,
///
TTOPTION = 0x00004000,
///
COLLATE = 0x00008000,
///
FORMNAME = 0x00010000,
///
LOGPIXELS = 0x00020000,
///
BITSPERPEL = 0x00040000,
///
PELSWIDTH = 0x00080000,
///
PELSHEIGHT = 0x00100000,
///
DISPLAYFLAGS = 0x00200000,
///
NUP = 0x00000040,
///
DISPLAYFREQUENCY = 0x00400000,
///
ICMMETHOD = 0x00800000,
///
ICMINTENT = 0x01000000,
///
MEDIATYPE = 0x02000000,
///
DITHERTYPE = 0x04000000,
///
PANNINGWIDTH = 0x08000000,
///
PANNINGHEIGHT = 0x10000000,
}
#endregion
#region Constructors
///
/// Create a new instance of
///
///
/// A received from
public ScreenEx(Forms.Screen screen, ScreenSettingsDevMode devMode) : base(screen.DeviceName)
{
this.Type = DeviceType.Screen;
this.Name = screen.DeviceName;
this.BitsPerPixel = (byte)screen.BitsPerPixel;
this.Bounds = new Rectangle(screen.Bounds.Location, screen.Bounds.Size);
this.Primary = screen.Primary;
this.SpecVersion = devMode.dmSpecVersion;
this.DriverVersion = devMode.dmDriverVersion;
this.FixedOutput = (FixedOutput)devMode.dmDisplayFixedOutput;
this.LogPixels = devMode.dmLogPixels;
this.ColorDepth = (ColorDepth)devMode.dmBitsPerPel;
this.DisplayFlags = devMode.dmDisplayFlags;
this.Frequency = (byte)devMode.dmDisplayFrequency;
this.Orientation = (ScreenOrientation)devMode.dmDisplayOrientation;
this.fields = 0;
}
#endregion
#region Methods
///
/// Converts this class to a struct which then may be used to update the settings
///
///
public ScreenSettingsDevMode ToDEVMODE()
{
ScreenSettingsDevMode devMode = new ScreenSettingsDevMode(true);
devMode.dmBitsPerPel = this.BitsPerPixel;
devMode.dmDeviceName = this.Name;
devMode.dmDisplayFixedOutput = (int)this.FixedOutput;
devMode.dmDisplayFlags = this.DisplayFlags;
devMode.dmDisplayFrequency = this.Frequency;
devMode.dmDisplayOrientation = (int)this.Orientation;
devMode.dmDriverVersion = this.DriverVersion;
devMode.dmFields = (int)this.fields;
devMode.dmFormName = "";
devMode.dmLogPixels = this.LogPixels;
devMode.dmPelsHeight = this.Bounds.Height;
devMode.dmPelsWidth = this.Bounds.Width;
devMode.dmPositionX = this.Bounds.X;
devMode.dmPositionY = this.Bounds.Y;
devMode.dmSpecVersion = this.SpecVersion;
devMode.dmSize = (short)Systemm.Runtime.InteropServices.Marshal.SizeOf(devMode);
return devMode;
}
#endregion
}
}