Jason,
Here is the code. Modify as desired. NOTE: I took out a lot of <summary>
blocks that make the constants compile without warnings. They just said the
same thing as the comments at the end.
====================snip=======================
namespace RLA.GetCaps
{
using System;
using System.Runtime.InteropServices;
/// <summary>
/// GetDeviceCaps and associated calls/values
/// </summary>
/// <remarks>
/// Use as desired. No warranties implied.
/// RLA 7/3/2002
/// </remarks>
public class GetDevCaps
{
#region "Device Parameters"
/* Device Parameters for GetDeviceCaps() */
public static short DRIVERVERSION = 0; // Device driver version
public static short TECHNOLOGY = 2; // Device classification
public static short HORZSIZE = 4; // Horizontal size in
millimeters
public static short VERTSIZE = 6; // Vertical size in millimeters
public static short HORZRES = 8; // Horizontal width in pixels
public static short VERTRES = 10; // Vertical height in pixels
public static short BITSPIXEL = 12; // Number of bits per pixel
public static short PLANES = 14; // Number of planes
public static short NUMBRUSHES = 16; // Number of brushes the device
has
public static short NUMPENS = 18; // Number of pens the device
has
public static short NUMMARKERS = 20; // Number of markers the device
has
public static short NUMFONTS = 22; // Number of fonts the device
has
public static short NUMCOLORS = 24; // Number of colors the device
supports
public static short PDEVICESIZE = 26; // Size required for device
descriptor
public static short CURVECAPS = 28; // Curve capibilities
public static short LINECAPS = 30; // Line capibilities
public static short POLYGONALCAPS = 32; // Polygonal capibilities
public static short TEXTCAPS = 34; // Text capibilities
public static short CLIPCAPS = 36; // Clipping capibilities
public static short RASTERCAPS = 38; // Bitblt capibilities
public static short ASPECTX = 40; // Length of the X leg
public static short ASPECTY = 42; // Length of the Y leg
public static short ASPECTXY = 44; // Length of the hypotenuse
public static short PHYSICALWIDTH = 110; // Physical Width in device
units
public static short PHYSICALHEIGHT = 111; // Physical Height in device
units
public static short PHYSICALOFFSETX = 112; // Physical Printable Area x
margin
public static short PHYSICALOFFSETY = 113; // Physical Printable Area y
margin
public static short SCALINGFACTORX = 114; // Scaling factor x
public static short SCALINGFACTORY = 115; // Scaling factor y
#endregion
public static float TwipsPerInch = 1440.0f;
public static float InchesPerTwip = 1.0f / TwipsPerInch;
public static float PointsPerInch = 72.0f;
public static float InchesPerPoint = 1.0f / PointsPerInch;
/// <summary>
/// Call the GetDeviceCaps Win32 method
/// </summary>
[DllImport("gdi32.dll")]
public static extern Int16 GetDeviceCaps(
[In] [MarshalAs (UnmanagedType.U4)] int hDc,
[In] [MarshalAs (UnmanagedType.U2)] Int16 funct);
/// <summary>
/// Return the device 'hard' margins for the passed in
/// Device Context handle. Return data in 1/100ths inch
/// </summary>
/// <param name="hDc">Input handle</param>
/// <param name="left">output left margin in 1/100ths inch</param>
/// <param name="top">output top margin in 1/100ths inch</param>
/// <param name="right">output right margin in 1/100ths inch</param>
/// <param name="bottom">output bottom margin in 1/100ths inch</param>
public static void GetHardMargins(int hDc, ref float left, ref float top,
ref float right, ref float bottom)
{
float offx = Convert.ToSingle(GetDeviceCaps(hDc, PHYSICALOFFSETX));
float offy = Convert.ToSingle(GetDeviceCaps(hDc, PHYSICALOFFSETY));;
float resx = Convert.ToSingle(GetDeviceCaps(hDc, HORZRES));
float resy = Convert.ToSingle(GetDeviceCaps(hDc, VERTRES));
float hsz = Convert.ToSingle(GetDeviceCaps(hDc, HORZSIZE))/25.4f; //
screen width in inches
float vsz = Convert.ToSingle(GetDeviceCaps(hDc, VERTSIZE))/25.4f; //
screen height in inches
float ppix = resx/hsz;
float ppiy = resy/vsz;
left = (offx/ppix) * 100.0f;
top = (offy/ppix) * 100.0f;
bottom = top + (vsz * 100.0f);
right = left + (hsz * 100.0f);
}
}
}
========================snip==========================
Ron,
If you don't mind, will you go ahead and post your code. I think I might
be needing to do something similar in the next few weeks and it may save
me some time. Thanks a lot.
Jason Newell
------------------snip==============