重新开一个帖子。现在我还是想要读取显示器的尺寸,我用VC程序读取我PC的屏幕尺寸会随着分辨率的改变而改变,我现在改用EVC去读取触摸屏的显示器尺寸,因为触摸屏的分辨率是不用改变的。但是我读出来的结果都是一个,无论用哪个屏;代码如下:
CString str1,str2,str3; 
HDC  hScreenDC=CreateDC(_T("DISPlAY"),  NULL,  NULL,  NULL);  
m_Width = GetDeviceCaps(hScreenDC,HORZSIZE);  //结果是64 
m_Highth = GetDeviceCaps(hScreenDC,VERTSIZE);  //结果是60 
m_DSize=sqrt(m_Width*m_Width+m_Highth*m_Highth)/25.4;  
str1.Format(_T("%d"),m_Width); 
str2.Format(_T("%d"),m_Highth); 
str3.Format(_T("%f"),m_DSize); 
SetDlgItemText(IDC_EDIT1,str1); 
SetDlgItemText(IDC_EDIT2,str2); 
SetDlgItemText(IDC_EDIT3,str3);
无论哪个屏m_Width和m_Highth都是64和60(mm)。这显然是不对的,所以我也不知道改怎么弄了,莫非不用API函数去读取吗?哪位仁兄不是很忙的情况下,帮小弟弄弄这个问题,因为这个问题在网上也没有一个答案。虽然我的分数不多了,但是希望大家以学习为第一,谢谢了呵呵

解决方案 »

  1.   

    用GetSystemMetrics()函数看看
    SM_CXSCREEN, SM_CYSCREEN Width and height, in pixels 用这两个参数可以得到屏幕以像素点的高度和宽度.
      

  2.   

    这个我也试过了,这个函数就是来求分辨率的,例如1280*1024,800*600,跟m_Width = GetDeviceCaps(hScreenDC,HORZRES);m_Highth = GetDeviceCaps(hScreenDC,VERTRES); 结果是一样的。也就是GetDeviceCaps函数使用HORZRES和VERTRES而不是HORZSIZE和VERTSIZE的时候结果一样
      

  3.   

    大家也可以看看http://topic.csdn.net/u/20090902/16/ce3f3322-37af-4d73-afff-7a7ec3952b54.html这个帖子,里面有了很多讨论,但是没有结果。
      

  4.   

    你可以从注册表里读   
      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\Default_Monitor\5&3a7255c5&0&11223344&01&00\Device   Parameters   
      如果你的系统可得显示器的EDID,就有EDID项,否则有BAD_EDID项
      

  5.   

    我读取EDID的话,里面也没有关于尺寸的啊。而且显示器的分辨率里面也设置很多,我要是能读出最佳分辨率也行,但是最佳分辨率根据edid也读不出来啊
      

  6.   

    具体实现如下
    Reading   the   EDID   for   the   Current   Monitor     
      Your   display   driver   or   mini-VDD   can   use   the   EDID   structure   returned   to   the   VDD   at   boot   time   by   retrieving   this   structure   from   the   registry.   This   can   be   done   once   your   display   driver   (or   mini-VDD)   has   called   VDD_GET_DISPLAY_CONFIG   (or   VDD_GetDisplayInfo   if   your   mini-VDD   is   issuing   the   call   from   ring   0).   To   retrieve   the   EDID   for   the   current   monitor:     
      1.   Get   and   save   the   diMonitorDevNodeHandle   member   of   the   DISPLAYINFO   structure.     
      2.   Call   CONFIGMG_Read_Registry_Value.   Make   sure   that   you   have   CONFIGMG.INC   in   your   include   directory.   The   parameters   for   the   call   should   be   as   follows:     
      Parameter     
        Value     
          
      dnDevNode     
        diMonitorDevNodeHandle   retrieved   from   the   DISPLAYINFO     
          
      pszSubKey     
        NULL   (no   subkey   needed)     
          
      pszValueName     
        A   pointer   to   the   ASCIIz   string   "EDID"     
          
      ulExpectedType     
        REG_BINARY     
          
      Buffer     
        A   pointer   to   a   128   byte   buffer   (the   EDID   plus   the   null   terminator)   which   will   receive   the   EDID   data   back     
          
      pulLength     
        Size   of   Buffer   (129   bytes   or   longer)     
          
      ulFlags     
        CM_REGISTRY_HARDWARE     
      

  7.   

    EDID中有图像size 描述(2 bytes), 该2字节定义行、场最大size。注意单位为cm; 如最大行size 320mmà”20h”.
    就可以得出显示器的尺寸
      

  8.   

    哦 EDID似乎还真有这部分内容,那请问您有读取EDID的vc程序吗?我现在非常急的用。
      

  9.   

    源代码没有,不过只要读到了EDID就会很快写好的,具体参考
    http://hi.baidu.com/zebf/blog/item/2c8717d5ec3dacc151da4baf.html
      

  10.   

    我以前在一个做液晶显示器的单位实习过,有非常详细的EDID的资料。我还想问触摸屏里面有没有烧录EDID信息啊?我的最终目的是读取触摸屏的尺寸,害怕弄完了白弄了,确定一下。
      

  11.   

    呵呵,还是希望能够解决的。不知道谁有读取EDID的程序。
      

  12.   

    这个函数可以读取EDID,剩下的还需要自己去做啊,哪有什么都有现成的。
    Windows Driver Kit: Display Devices
    VideoPortDDCMonitorHelperThe VideoPortDDCMonitorHelper function queries a monitor for EDID information using the DDC protocol.BOOLEAN  VideoPortDDCMonitorHelper(    IN PVOID  HwDeviceExtension,    IN PVOID  DDCControl,    __inout PUCHAR  EdidBuffer,    IN ULONG  EdidBufferSize    );Parameters
    HwDeviceExtension 
    Pointer to the miniport driver's device extension. 
    DDCControl 
    Pointer to a DDC_CONTROL structure. 
    EdidBuffer 
    Pointer to a buffer in which the video port driver returns the EDID structure. For ACPI devices, the first four bytes are preset by the video port driver to indicate an attempt to read the EDID. 
    EdidBufferSize 
    Specifies the size in bytes of the buffer to which EdidBuffer points.
    http://msdn.microsoft.com/en-us/library/aa479182.aspx
      

  13.   

    EDID我已经读出来了,读的是注册表。
      

  14.   

    就是按照InitialJ在五楼说的方法