误差还是函数错误

garnel 2012-03-27 08:19:47
要在屏幕上按1:1的比例显示一张表格,客户要求所见即所得,在使用以下函数时得到的结果却与实际不符,
mmW := GetDeviceCaps(GetDC(0), HORZSIZE); //获得水平尺寸,单位mm
mmH := GetDeviceCaps(GetDC(0), VERTSIZE); //获得垂直尺寸,单位mm
显示器为22寸,分辨率1680*1050,测得的结果为320mm*240mm,在另一台同型号品牌的屏幕上又测的是其它结果,22寸显示器屏幕物理尺寸大约为480mm*300mm
请高手指点
...全文
200 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mhhaifeng 2012-04-13
  • 打赏
  • 举报
回复
那么奇怪? 测试多一台显示器试试?
山东蓝鸟贵薪 2012-04-13
  • 打赏
  • 举报
回复
不应该呀,也可以有是参数传递的有问题吧
garnel 2012-04-13
  • 打赏
  • 举报
回复
真的无法得到相对准确的测量结果吗?
garnel 2012-03-29
  • 打赏
  • 举报
回复
问题补充:通过GetDeviceCaps获得的屏幕DPI基本都是96,系统默认的,但是当设置最佳分辨率后,经过实际测量,手工计算得到的屏幕DPI大约为90,哪位高手能解释一下,为什么屏幕能不按系统设置的参数工作?
  • 打赏
  • 举报
回复
如果系统、屏幕尺寸、分辨率、驱动一样的情况下,出现你这个情况还真是比较不好判断
garnel 2012-03-28
  • 打赏
  • 举报
回复
To ansinlee
您的程序中以下语句运行中出错
Reg.GetKeyNames(MONITOR_IDS);
garnel 2012-03-27
  • 打赏
  • 举报
回复
分辨率一样,都是1680*1050
bdmh 2012-03-27
  • 打赏
  • 举报
回复
分辨率一样吗
ansinlee 2012-03-27
  • 打赏
  • 举报
回复
使用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];




金卯刀 2012-03-27
  • 打赏
  • 举报
回复
参考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.

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧