在几年前的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检索到此数据结构中。这对我也有用。我还想找到显示器相对于桌面区域的位置坐标。查看DEVMODE结构中的Windows开发中心中的信息,我看到还有一个dmPosition参数是POINTL结构。这已被排除在上面的DEVMODE类型定义之外,当我添加它时,dmPelsWidth和dmPelsHeight不再检索正确的信息。
为什么上面省略了dmPosition,为什么检索到的信息在我加入时不再有效?
答案 0 :(得分:0)
这个问题是C ++中的DEVMODE
定义包括
(according to Microsoft)
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
选项,第一个与打印机设备相关,第二个与显示设备相关。 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
中的桌面位置,并且仍可以dmPelsWidth
和dmPelsHeight