-1

在几年前关于 stackoverflow 的示例中,EnumDisplaySettings 用于加载具有以下定义的数据结构 DEVMODE:

Private Type DEVMODE
  dmDeviceName As String * CCHDEVICENAME
  dmSpecVersion As Integer
  dmDriverVersion As Integer
  dmSize As Integer
  dmDriverExtra As Integer
  dmFields As Long
  dmOrientation As Integer
  dmPaperSize As Integer
  dmPaperLength As Integer
  dmPaperWidth As Integer
  dmScale As Integer
  dmCopies As Integer
  dmDefaultSource As Integer
  dmPrintQuality As Integer
  dmColor As Integer
  dmDuplex As Integer
  dmYResolution As Integer
  dmTTOption As Integer
  dmCollate As Integer
  dmFormName As String * CCHFORMNAME
  dmLogPixels As Integer
  dmBitsPerPel As Long
  dmPelsWidth As Long
  dmPelsHeight As Long
  dmDisplayFlags As Long
  dmDisplayFrequency As Long
End Type

dmPelsWidth 和 dmPelsHeight 被检索到此数据结构中。这也适用于我。我还想找到显示器相对于桌面区域的位置坐标。查看 Windows 开发中心中有关 DEVMODE 结构的信息,我看到还有一个 dmPosition 参数,它是一个 POINTL 结构。这已被排除在上面的 DEVMODE 类型定义之外,当我添加它时,dmPelsWidth 和 dmPelsHeight 不再检索正确的信息。

为什么上面省略了 dmPosition,为什么当我包含它时检索到的信息不再有效?

示例链接: 在 excel vba 中查找外部显示器的大小

4

1 回答 1

0

这个问题是DEVMODEC++ 中的定义包括(根据微软

  union {
    struct {
      short dmOrientation;
      short dmPaperSize;
      short dmPaperLength;
      short dmPaperWidth;
      short dmScale;
      short dmCopies;
      short dmDefaultSource;
      short dmPrintQuality;
    };
    struct {
      POINTL dmPosition;
      DWORD  dmDisplayOrientation;
      DWORD  dmDisplayFixedOutput;
    };
  };

union覆盖同一内存上的两个选项stuct,第一个与打印机设备相关,第二个与显示设备相关。AFAIK VBA 不支持这种技术

由于您正在尝试获取显示设备的数据,请将Type DEVMODE定义更改为此

Private Type DEVMODE
  dmDeviceName As String * CCHDEVICENAME
  dmSpecVersion As Integer
  dmDriverVersion As Integer
  dmSize As Integer
  dmDriverExtra As Integer
  dmFields As Long
'  dmOrientation As Integer
'  dmPaperSize As Integer
'  dmPaperLength As Integer
'  dmPaperWidth As Integer
'  dmScale As Integer
'  dmCopies As Integer
'  dmDefaultSource As Integer
'  dmPrintQuality As Integer
    dmPosition_X As Long
    dmPosition_Y As Long
    dmDisplayOrientation As Long
    dmDisplayFixedOutput As Long

  dmColor As Integer
  dmDuplex As Integer
  dmYResolution As Integer
  dmTTOption As Integer
  dmCollate As Integer
  dmFormName As String * CCHFORMNAME
  dmLogPixels As Integer
  dmBitsPerPel As Long
  dmPelsWidth As Long
  dmPelsHeight As Long
  dmDisplayFlags As Long
  dmDisplayFrequency As Long
End Type

您应该能够访问桌面位置dmPosition_X并且仍然dmPosition_Y获得解决方案dmPelsWidthdmPelsHeight

于 2013-05-12T05:38:54.717 回答