Getting hardware info
-
Hi I need to get - programatically - the graphic display's properties (specifically the x and y physical dimensions). I found that using GetDeviceCaps(HORZSIZE) returns erroneous answers. Is there any other way to get the info (maybe by communicating directly with the device), short of asking the user to measure the screen :) ? Thanks
alex 'Architecture is music frozen in space.'
-
Hi I need to get - programatically - the graphic display's properties (specifically the x and y physical dimensions). I found that using GetDeviceCaps(HORZSIZE) returns erroneous answers. Is there any other way to get the info (maybe by communicating directly with the device), short of asking the user to measure the screen :) ? Thanks
alex 'Architecture is music frozen in space.'
-
Go to this article: http://www.codeproject.com/KB/graphics/TextOnABitmap.aspx[^] And scroll down to the section titled "Full Screen Mode". All the code you need (and more) is right there.
Thank you for answering. As I wrote, I need the physical screen size (in milimeters), and GetSystemMetrics(SM_CXSCREEN) returns pixels. The problem is GetDeviceCaps(HORZSIZE/VERTSIZE) is supposed to return the screen size in milimeters, but gives incorrect answers. That's why I'm looking for the way to directly get the data from the hardware.
alex 'Architecture is music frozen in space.'
-
Thank you for answering. As I wrote, I need the physical screen size (in milimeters), and GetSystemMetrics(SM_CXSCREEN) returns pixels. The problem is GetDeviceCaps(HORZSIZE/VERTSIZE) is supposed to return the screen size in milimeters, but gives incorrect answers. That's why I'm looking for the way to directly get the data from the hardware.
alex 'Architecture is music frozen in space.'
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 vertic
-
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 vertic
The values you compute are based on the results of GetLogPixels() which returns pixels/inch. On my machine it seems I get 96dpi no matter what I do (i.e. no matter the screen resolution), so the result of the calculation is (very close to) what the system reports. 1. It seems there is a problem with the results of GetLogPixels(): it always returns 96. Look it up on the web. 2. What I am interested in is to interrogate the display device (EDID data) directly. Even so, it seems that the EDID data is sometimes erroneous or even completely missing (fault of manufacturer). Again, see the web.
alex 'Architecture is music frozen in space.'
-
The values you compute are based on the results of GetLogPixels() which returns pixels/inch. On my machine it seems I get 96dpi no matter what I do (i.e. no matter the screen resolution), so the result of the calculation is (very close to) what the system reports. 1. It seems there is a problem with the results of GetLogPixels(): it always returns 96. Look it up on the web. 2. What I am interested in is to interrogate the display device (EDID data) directly. Even so, it seems that the EDID data is sometimes erroneous or even completely missing (fault of manufacturer). Again, see the web.
alex 'Architecture is music frozen in space.'
Most of the time, the DPI *is* 96 on a normal Windows desktop. But you can set your DPI to be higher (120 DPI) by using "large fonts". If you want to verify that GetDeviceCaps is returning accurate info regarding size in mm, you could try setting the DPI to 120 and it *should* come back with the same mm size that was reported with normal fonts.
"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 -
The values you compute are based on the results of GetLogPixels() which returns pixels/inch. On my machine it seems I get 96dpi no matter what I do (i.e. no matter the screen resolution), so the result of the calculation is (very close to) what the system reports. 1. It seems there is a problem with the results of GetLogPixels(): it always returns 96. Look it up on the web. 2. What I am interested in is to interrogate the display device (EDID data) directly. Even so, it seems that the EDID data is sometimes erroneous or even completely missing (fault of manufacturer). Again, see the web.
alex 'Architecture is music frozen in space.'
On windows versions prior to vista DPI scaling was so fubar that if hardware didn't lie and claim 96 DPI everything was a mess. Vista's better, but anytime it has to scale an app bitmap image instead of a vector image it still sucks.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
-
Most of the time, the DPI *is* 96 on a normal Windows desktop. But you can set your DPI to be higher (120 DPI) by using "large fonts". If you want to verify that GetDeviceCaps is returning accurate info regarding size in mm, you could try setting the DPI to 120 and it *should* come back with the same mm size that was reported with normal fonts.
"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