Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Hardware & Devices
  4. Getting hardware info

Getting hardware info

Scheduled Pinned Locked Moved Hardware & Devices
hardwarearchitecturequestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex__b
    wrote on last edited by
    #1

    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.'

    realJSOPR 1 Reply Last reply
    0
    • A alex__b

      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.'

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • realJSOPR realJSOP

        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.

        A Offline
        A Offline
        alex__b
        wrote on last edited by
        #3

        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.'

        realJSOPR 1 Reply Last reply
        0
        • A alex__b

          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.'

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          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
          
          A 1 Reply Last reply
          0
          • realJSOPR realJSOP

            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
            
            A Offline
            A Offline
            alex__b
            wrote on last edited by
            #5

            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.'

            realJSOPR D 2 Replies Last reply
            0
            • A alex__b

              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.'

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              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

              A 1 Reply Last reply
              0
              • A alex__b

                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.'

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • realJSOPR realJSOP

                  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

                  A Offline
                  A Offline
                  alex__b
                  wrote on last edited by
                  #8

                  I set the display to large fonts and it still says 96 dpi. >it *should* come back with the same mm size that was reported with normal fonts It does, but the reported size is wrong.

                  alex 'Architecture is music frozen in space.'

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups