要在屏幕上按1:1的比例显示一张表格,客户要求所见即所得,在使用以下函数时得到的结果却与实际不符,
mmW := GetDeviceCaps(GetDC(0), HORZSIZE);  //获得水平尺寸,单位mm
mmH := GetDeviceCaps(GetDC(0), VERTSIZE);  //获得垂直尺寸,单位mm
显示器为22寸,分辨率1680*1050,测得的结果为320mm*240mm,在另一台同型号品牌的屏幕上又测的是其它结果,22寸显示器屏幕物理尺寸大约为480mm*300mm
请高手指点

解决方案 »

  1.   

    参考MSDN,与驱动有关
    GetDeviceCaps reports info that the display driver provides. If the display driver declines to report any info, GetDeviceCaps calculates the info based on fixed calculations. If the display driver reports invalid info, GetDeviceCaps returns the invalid info. Also, if the display driver declines to report info, GetDeviceCaps might calculate incorrect info because it assumes either fixed DPI (96 DPI) or a fixed size (depending on the info that the display driver did and didn’t provide). Unfortunately, a display driver that is implemented to the Windows Display Driver Model (WDDM) (introduced in Windows Vista) causes GDI to not get the info, so GetDeviceCaps must always calculate the info.
      

  2.   

    使用EDID(0x100字节)信息可以得到显示器的物理尺寸。关于EDID搜索一下就知道了。
    其中 0x42-0x44 描述了显示设备的水平和垂直尺寸,单位mm。  0x42 水平尺寸低8位
      0x43 垂直尺寸低8位
      0x44 其中高4位是水平尺寸高8位,低4位为垂直尺寸高8位。
      const ROOT_NODE = '\SYSTEM\CurrentControlSet\Enum\DISPLAY\';
      {读取注册表显示设备EDID信息}
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      Registry.OpenKeyReadOnly(ROOT_NODE);
     {如果有多台显示器 \DISPLAY 至少包括2个以上子节点 其中第一个\Default_Monitor 可以忽略}
      {读取VESA_MONITOR_ID列表}
      Reg.GetKeyNames(MONITOR_IDS);
      
      {每一个VMID下面还会有个PNP_ID节点}
      Registry.OpenKeyReadOnly(MONITOR_IDS[i]);
        
      {读取PNP_ID节点}
      Reg.GetKeyNames(PNP_ID);
      
      {到这可以读取显示器的EDID信息了}
      Registry.OpenKeyReadOnly(PNP_ID[0] + '\Device Parameters');
      {
        Buf: array[0..$FF] of Byte;
        HorW, VerH: WORD;
      }
      Reg.ReadBinaryData('EDID', Buf[0], sizeof(Buf));
       
      HorW := ((Buf[$44] and $f0) shl 4) xor Buf[$42];
      VerH := ((Buf[$44] and $0f) shl 8) xor Buf[$43];
      
      
      

  3.   

    To ansinlee
    您的程序中以下语句运行中出错
    Reg.GetKeyNames(MONITOR_IDS);
      

  4.   

    问题补充:通过GetDeviceCaps获得的屏幕DPI基本都是96,系统默认的,但是当设置最佳分辨率后,经过实际测量,手工计算得到的屏幕DPI大约为90,哪位高手能解释一下,为什么屏幕能不按系统设置的参数工作?