首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

误差还是函数异常

2012-04-27 
误差还是函数错误要在屏幕上按1:1的比例显示一张表格,客户要求所见即所得,在使用以下函数时得到的结果却与

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

[解决办法]
分辨率一样吗
[解决办法]
参考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.

[解决办法]
使用EDID(0x100字节)信息可以得到显示器的物理尺寸。关于EDID搜索一下就知道了。
其中 0x42-0x44 描述了显示设备的水平和垂直尺寸,单位mm。

0x42 水平尺寸低8位
0x43 垂直尺寸低8位
0x44 其中高4位是水平尺寸高8位,低4位为垂直尺寸高8位。


Delphi(Pascal) code
  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];
[解决办法]
如果系统、屏幕尺寸、分辨率、驱动一样的情况下,出现你这个情况还真是比较不好判断
[解决办法]
不应该呀,也可以有是参数传递的有问题吧
[解决办法]
那么奇怪? 测试多一台显示器试试?

热点排行