Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than gdi32, prefix the name with the module name and a period.
GetDeviceCaps (gdi32)
.
C# Signature:
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
VB.NET Signature:
<DllImport("gdi32.dll")> _
Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As Integer) As Integer
End Function
User-Defined Types:
You can use the following enumeration for passing in as nIndex:
C#
public enum DeviceCap
{
/// <summary>
/// Device driver version
/// </summary>
DRIVERVERSION = 0,
/// <summary>
/// Device classification
/// </summary>
TECHNOLOGY = 2,
/// <summary>
/// Horizontal size in millimeters
/// </summary>
HORZSIZE = 4,
/// <summary>
/// Vertical size in millimeters
/// </summary>
VERTSIZE = 6,
/// <summary>
/// Horizontal width in pixels
/// </summary>
HORZRES = 8,
/// <summary>
/// Vertical height in pixels
/// </summary>
VERTRES = 10,
/// <summary>
/// Number of bits per pixel
/// </summary>
BITSPIXEL = 12,
/// <summary>
/// Number of planes
/// </summary>
PLANES = 14,
/// <summary>
/// Number of brushes the device has
/// </summary>
NUMBRUSHES = 16,
/// <summary>
/// Number of pens the device has
/// </summary>
NUMPENS = 18,
/// <summary>
/// Number of markers the device has
/// </summary>
NUMMARKERS = 20,
/// <summary>
/// Number of fonts the device has
/// </summary>
NUMFONTS = 22,
/// <summary>
/// Number of colors the device supports
/// </summary>
NUMCOLORS = 24,
/// <summary>
/// Size required for device descriptor
/// </summary>
PDEVICESIZE = 26,
/// <summary>
/// Curve capabilities
/// </summary>
CURVECAPS = 28,
/// <summary>
/// Line capabilities
/// </summary>
LINECAPS = 30,
/// <summary>
/// Polygonal capabilities
/// </summary>
POLYGONALCAPS = 32,
/// <summary>
/// Text capabilities
/// </summary>
TEXTCAPS = 34,
/// <summary>
/// Clipping capabilities
/// </summary>
CLIPCAPS = 36,
/// <summary>
/// Bitblt capabilities
/// </summary>
RASTERCAPS = 38,
/// <summary>
/// Length of the X leg
/// </summary>
ASPECTX = 40,
/// <summary>
/// Length of the Y leg
/// </summary>
ASPECTY = 42,
/// <summary>
/// Length of the hypotenuse
/// </summary>
ASPECTXY = 44,
/// <summary>
/// Shading and Blending caps
/// </summary>
SHADEBLENDCAPS = 45,
/// <summary>
/// Logical pixels inch in X
/// </summary>
LOGPIXELSX = 88,
/// <summary>
/// Logical pixels inch in Y
/// </summary>
LOGPIXELSY = 90,
/// <summary>
/// Number of entries in physical palette
/// </summary>
SIZEPALETTE = 104,
/// <summary>
/// Number of reserved entries in palette
/// </summary>
NUMRESERVED = 106,
/// <summary>
/// Actual color resolution
/// </summary>
COLORRES = 108,
// Printing related DeviceCaps. These replace the appropriate Escapes
/// <summary>
/// Physical Width in device units
/// </summary>
PHYSICALWIDTH = 110,
/// <summary>
/// Physical Height in device units
/// </summary>
PHYSICALHEIGHT = 111,
/// <summary>
/// Physical Printable Area x margin
/// </summary>
PHYSICALOFFSETX = 112,
/// <summary>
/// Physical Printable Area y margin
/// </summary>
PHYSICALOFFSETY = 113,
/// <summary>
/// Scaling factor x
/// </summary>
SCALINGFACTORX = 114,
/// <summary>
/// Scaling factor y
/// </summary>
SCALINGFACTORY = 115,
/// <summary>
/// Current vertical refresh rate of the display device (for displays only) in Hz
/// </summary>
VREFRESH = 116,
/// <summary>
/// Vertical height of entire desktop in pixels
/// </summary>
DESKTOPVERTRES = 117,
/// <summary>
/// Horizontal width of entire desktop in pixels
/// </summary>
DESKTOPHORZRES = 118,
DESKTOPVERTRES = 117,
/// <summary>
/// Preferred blt alignment
/// Vertical height of entire desktop in pixels
/// </summary>
DESKTOPHORZRES = 118,
/// <summary>
/// Preferred blt alignment
/// </summary>
BLTALIGNMENT = 119
}
VB
Public Enum DeviceCap As Integer
''' <summary>
''' Device driver version
''' </summary>
DRIVERVERSION = 0
''' <summary>
''' Device classification
''' </summary>
TECHNOLOGY = 2
''' <summary>
''' Horizontal size in millimeters
''' </summary>
HORZSIZE = 4
''' <summary>
''' Vertical size in millimeters
''' </summary>
VERTSIZE = 6
''' <summary>
''' Horizontal width in pixels
''' </summary>
HORZRES = 8
''' <summary>
''' Vertical height in pixels
''' </summary>
VERTRES = 10
''' <summary>
''' Number of bits per pixel
''' </summary>
BITSPIXEL = 12
''' <summary>
''' Number of planes
''' </summary>
PLANES = 14
''' <summary>
''' Number of brushes the device has
''' </summary>
NUMBRUSHES = 16
''' <summary>
''' Number of pens the device has
''' </summary>
NUMPENS = 18
''' <summary>
''' Number of markers the device has
''' </summary>
NUMMARKERS = 20
''' <summary>
''' Number of fonts the device has
''' </summary>
NUMFONTS = 22
''' <summary>
''' Number of colors the device supports
''' </summary>
NUMCOLORS = 24
''' <summary>
''' Size required for device descriptor
''' </summary>
PDEVICESIZE = 26
''' <summary>
''' Curve capabilities
''' </summary>
CURVECAPS = 28
''' <summary>
''' Line capabilities
''' </summary>
LINECAPS = 30
''' <summary>
''' Polygonal capabilities
''' </summary>
POLYGONALCAPS = 32
''' <summary>
''' Text capabilities
''' </summary>
TEXTCAPS = 34
''' <summary>
''' Clipping capabilities
''' </summary>
CLIPCAPS = 36
''' <summary>
''' Bitblt capabilities
''' </summary>
RASTERCAPS = 38
''' <summary>
''' Length of the X leg
''' </summary>
ASPECTX = 40
''' <summary>
''' Length of the Y leg
''' </summary>
ASPECTY = 42
''' <summary>
''' Length of the hypotenuse
''' </summary>
ASPECTXY = 44
''' <summary>
''' Shading and Blending caps
''' </summary>
SHADEBLENDCAPS = 45
''' <summary>
''' Logical pixels inch in X
''' </summary>
LOGPIXELSX = 88
''' <summary>
''' Logical pixels inch in Y
''' </summary>
LOGPIXELSY = 90
''' <summary>
''' Number of entries in physical palette
''' </summary>
SIZEPALETTE = 104
''' <summary>
''' Number of reserved entries in palette
''' </summary>
NUMRESERVED = 106
''' <summary>
''' Actual color resolution
''' </summary>
COLORRES = 108
' Printing related DeviceCaps. These replace the appropriate Escapes
''' <summary>
''' Physical Width in device units
''' </summary>
PHYSICALWIDTH = 110
''' <summary>
''' Physical Height in device units
''' </summary>
PHYSICALHEIGHT = 111
''' <summary>
''' Physical Printable Area x margin
''' </summary>
PHYSICALOFFSETX = 112
''' <summary>
''' Physical Printable Area y margin
''' </summary>
PHYSICALOFFSETY = 113
''' <summary>
''' Scaling factor x
''' </summary>
SCALINGFACTORX = 114
''' <summary>
''' Scaling factor y
''' </summary>
SCALINGFACTORY = 115
''' <summary>
''' Current vertical refresh rate of the display device (for displays only) in Hz
''' </summary>
VREFRESH = 116
''' <summary>
''' Vertical height of entire desktop in pixels
''' </summary>
DESKTOPVERTRES = 117
''' <summary>
''' Horizontal width of entire desktop in pixels
''' </summary>
DESKTOPHORZRES = 118
DESKTOPVERTRES = 117
''' <summary>
''' Preferred blt alignment
''' Vertical height of entire desktop in pixels
''' </summary>
DESKTOPHORZRES = 118
''' <summary>
''' Preferred blt alignment
''' </summary>
BLTALIGNMENT = 119
End Enum
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
C#
static void Main(string[] args)
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
{
Console.WriteLine("Graphics.DpiX: " + g.DpiX);
Console.WriteLine("Graphics.DpiY: " + g.DpiY);
Console.WriteLine();
IntPtr hdc = g.GetHdc();
foreach (DeviceCap cap in Enum.GetValues(typeof(DeviceCap)))
{
int result = GetDeviceCaps(hdc, cap);
Console.WriteLine(string.Format("{0}: {1}", cap, result));
}
g.ReleaseHdc();
}
Console.WriteLine();
Console.Write("Press any key to exit...");
Console.ReadKey();
}
VB
Private Shared Sub Main(args As String())
Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero)
Console.WriteLine("Graphics.DpiX: " & g.DpiX)
Console.WriteLine("Graphics.DpiY: " & g.DpiY)
Console.WriteLine()
Dim hdc As IntPtr = g.GetHdc()
For Each cap As DeviceCap In [Enum].GetValues(GetType(DeviceCap))
Dim result As Integer = GetDeviceCaps(hdc, cap)
Console.WriteLine(String.Format("{0}: {1}", cap, result))
Next
g.ReleaseHdc()
End Using
Console.WriteLine()
Console.Write("Press any key to exit...")
Console.ReadKey()
End Sub
Alternative Managed API:
System.Windows.Forms.Screen.PrimaryScreen might be of help in some cases. (Matt M Jacobsen)
If you are using Graphics as a DeviceContext you can use the DpiX and DpiY attributes. (Julian Taupe)
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).