Click here to Skip to main content
15,912,756 members
Home / Discussions / Hardware & Devices
   

Hardware & Devices

 
GeneralRe: Wireless Router Recommendations Pin
Snowman5819-Nov-08 9:34
Snowman5819-Nov-08 9:34 
QuestionHow to simulate a device as printer, USB storage? Pin
XuanThinh TRAN20-Oct-08 16:00
XuanThinh TRAN20-Oct-08 16:00 
QuestionInstalling operation system on wrong partition ... how to fix the problem ? Pin
Yanshof14-Oct-08 5:40
Yanshof14-Oct-08 5:40 
AnswerRe: Installing operation system on wrong partition ... how to fix the problem ? Pin
Sebastian Schneider16-Oct-08 3:35
Sebastian Schneider16-Oct-08 3:35 
QuestionGetting hardware info Pin
alex__b14-Oct-08 1:27
professionalalex__b14-Oct-08 1:27 
AnswerRe: Getting hardware info Pin
#realJSOP15-Oct-08 11:13
professional#realJSOP15-Oct-08 11:13 
GeneralRe: Getting hardware info Pin
alex__b15-Oct-08 19:26
professionalalex__b15-Oct-08 19:26 
GeneralRe: Getting hardware info Pin
#realJSOP16-Oct-08 1:02
professional#realJSOP16-Oct-08 1:02 
public class WinAPI
{
    [DllImport("gdi32.dll")] 
    private static extern Int32 GetDeviceCaps(IntPtr hdc, Int32 capindex);
    [DllImport("user32.dll")]
    public static extern IntPtr GetDC(IntPtr ptr);

    private const int DRIVERVERSION   = 0x00;    //Device driver version
    private const int TECHNOLOGY      = 0x2;     //Device classification
    private const int HORZSIZE        = 0x4;     //Horizontal size in millimeters
    private const int VERTSIZE        = 0x6;     //Vertical size in millimeters
    private const int HORZRES         = 0x8;     //Horizontal width in pixels
    private const int VERTRES         = 0xA;     //Vertical height in pixels
    private const int BITSPIXEL       = 0xC;     //Number of bits per pixel
    private const int PLANES          = 0xE;     //Number of planes
    private const int NUMBRUSHES      = 0x10;    //Number of brushes the device has
    private const int NUMPENS         = 0x12;    //Number of pens the device has
    private const int NUMMARKERS      = 0x14;    //Number of markers the device has
    private const int NUMFONTS        = 0x16;    //Number of fonts the device has
    private const int NUMCOLORS       = 0x18;    //Number of colors the device supports
    private const int PDEVICESIZE     = 0x1A;    //Size required for device descriptor
    private const int CURVECAPS       = 0x1C;    //Curve capabilities
    private const int LINECAPS        = 0x1E;    //Line capabilities
    private const int POLYGONALCAPS   = 0x20;    //Polygonal capabilities
    private const int TEXTCAPS        = 0x22;    //Text capabilities
    private const int CLIPCAPS        = 0x24;    //Clipping capabilities
    private const int RASTERCAPS      = 0x26;    //Bitblt capabilities
    private const int ASPECTX         = 0x28;    //Length of the X leg
    private const int ASPECTY         = 0x2A;    //Length of the Y leg
    private const int ASPECTXY        = 0x2C;    //Length of the hypotenuse
    private const int SHADEBLENDCAPS  = 0x2D;    //Shading and blending caps (IE5)
    private const int LOGPIXELSX      = 0x58;    //Logical pixels/inch in X
    private const int LOGPIXELSY      = 0x5A;    //Logical pixels/inch in Y
    private const int SIZEPALETTE     = 0x68;    //Number of entries in physical palette
    private const int NUMRESERVED     = 0x6A;    //Number of reserved entries in palette
    private const int COLORRES        = 0x6C;    //Actual color resolution
    private const int VREFRESH        = 0x74;    //Current vertical refresh rate of the
                                                 //display device (for displays only) in Hz
    private const int DESKTOPVERTRES  = 0x75;    //Horizontal width of entire desktop in 
                                                 //pixels (NT5)
    private const int DESKTOPHORZRES  = 0x76;    //Vertical height of entire desktop in 
                                                 //pixels (NT5)
    private const int BLTALIGNMENT    = 0x77;    //Preferred blt alignment


    public static void GetLogPixels(IntPtr hDC, ref int logPixelsX, ref int logPixelsY)
    {
        logPixelsX= GetDeviceCaps(hDC , LOGPIXELSX );
        logPixelsY= GetDeviceCaps(hDC , LOGPIXELSY );
    }

    public static void GetResolution(IntPtr hDC, ref int horzPixels, ref int vertPixels)
    {
        horzPixels = GetDeviceCaps(hDC, HORZRES);
        vertPixels = GetDeviceCaps(hDC, VERTRES);
    }

    public static void GetScreenMM(IntPtr hDC, ref int horzMM, ref int vertMM)
    {
        horzMM = GetDeviceCaps(hDC, HORZSIZE);
        vertMM = GetDeviceCaps(hDC, VERTSIZE);
    }

	public static void GetCalculatedScreenMM(IntPtr hDC, ref int horzMM, ref int vertMM)
	{
		int logX = 0;
		int logY = 0;
		int resX = 0;
		int resY = 0;
		double inchesX = 0.0d;
		double inchesY = 0.0d;

		// get the pixels per inch
		GetLogPixels(hDC, ref logX, ref logY);

		// get the resolution of the monitor
		GetResolution(hDC, ref resX, ref resY);

		inchesX = resX / logX;
		inchesY = resY / logY;

		// calculate the number of pixels per millimeter
		horzMM = (int)(inchesX * 0.0394d);
		vertMM = (int)(inchesY * 0.0394d);
	}
}

// get the device context
IntPtr dc = WinAPI.GetDC(this.Handle);

// calculate the resolution in millimeters
int horzMM = 0;
int vertMM = 0;
WinAPI.GetCalculatedScreenMM(hDC, ref horzMM, ref vertMM);

// just for grins, let's see if our numbers match what Windows is reporting
int xMM = 0;
int yMM = 0;
WinAPI.GetScreenMM(hDC, xMM, yMM);


Well, what do you know!? My calculated mm millimeter resolution is 444x277, and calling the DeviceCaps function with (HORZSIZE, VERTSIZE) returned 470x293!

Anyway, there's your calculation for determining the width/height in millimeters.


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


GeneralRe: Getting hardware info Pin
alex__b16-Oct-08 2:06
professionalalex__b16-Oct-08 2:06 
GeneralRe: Getting hardware info Pin
#realJSOP16-Oct-08 2:55
professional#realJSOP16-Oct-08 2:55 
GeneralRe: Getting hardware info Pin
alex__b16-Oct-08 4:39
professionalalex__b16-Oct-08 4:39 
GeneralRe: Getting hardware info Pin
Dan Neely16-Oct-08 3:52
Dan Neely16-Oct-08 3:52 
QuestionIs there any definite range for index of an network adapter? Pin
an8913-Oct-08 2:31
an8913-Oct-08 2:31 
AnswerRe: Is there any definite range for index of an network adapter? Pin
Dave Kreskowiak13-Oct-08 3:51
mveDave Kreskowiak13-Oct-08 3:51 
QuestionRe: Is there any definite range for index of an network adapter? Pin
an8913-Oct-08 17:43
an8913-Oct-08 17:43 
AnswerRe: Is there any definite range for index of an network adapter? Pin
Dave Kreskowiak14-Oct-08 1:09
mveDave Kreskowiak14-Oct-08 1:09 
QuestionRe: Is there any definite range for index of an network adapter? Pin
an8914-Oct-08 1:50
an8914-Oct-08 1:50 
AnswerRe: Is there any definite range for index of an network adapter? Pin
Dave Kreskowiak14-Oct-08 2:04
mveDave Kreskowiak14-Oct-08 2:04 
QuestionRe: Is there any definite range for index of an network adapter? Pin
an8914-Oct-08 2:50
an8914-Oct-08 2:50 
AnswerRe: Is there any definite range for index of an network adapter? Pin
Dave Kreskowiak14-Oct-08 4:12
mveDave Kreskowiak14-Oct-08 4:12 
QuestionRe: Is there any definite range for index of an network adapter? Pin
an8914-Oct-08 17:51
an8914-Oct-08 17:51 
AnswerRe: Is there any definite range for index of an network adapter? Pin
Dave Kreskowiak15-Oct-08 1:32
mveDave Kreskowiak15-Oct-08 1:32 
QuestionRe: Is there any definite range for index of an network adapter? Pin
an8915-Oct-08 18:17
an8915-Oct-08 18:17 
AnswerRe: Is there any definite range for index of an network adapter? Pin
Dave Kreskowiak16-Oct-08 2:18
mveDave Kreskowiak16-Oct-08 2:18 
QuestionRe: Is there any definite range for index of an network adapter? Pin
an8916-Oct-08 2:49
an8916-Oct-08 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.