Как получить текущие настройки экрана
Автор: Randy Birch
Компилятор: Visual Basic 5.0, 6.0
API функция GetDeviceCaps() позволяет получить наиболее
часто используемые параметры видео адаптера,
такие как разрешение по вертикали и горизонтали,
а также глубину цвета и текущую частоту
обновления.
Добавьте на форму четыре текстовых поля (Label1 -
Label4) кнопку и следующий код:
Option Explicit
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, _
ByVal nIndex As Long) As Long
Private Const HORZRES As Long = 8
Private Const VERTRES As Long = 10
Private Const BITSPIXEL As Long = 12
Private Const VREFRESH As Long = 116
Private Sub Command1_Click()
Dim currHRes As Long
Dim currVRes As Long
Dim currBPP As Long
Dim currVFreq As Long
Dim sBPPtype As String
Dim sFreqtype As String
'Получаем системные установки
currHRes = GetDeviceCaps(hdc, HORZRES)
currVRes = GetDeviceCaps(hdc, VERTRES)
currBPP = GetDeviceCaps(hdc, BITSPIXEL)
currVFreq = GetDeviceCaps(hdc, VREFRESH)
'Подписываем глубину цвета для удобства чтения
Select Case currBPP
Case 4: sBPPtype = "(16 Color)"
Case 8: sBPPtype = "(256 Color)"
Case 16: sBPPtype = "(High Color)"
Case 24, 32: sBPPtype = "(True Color)"
End Select
Select Case currVFreq
Case 0, 1: sFreqtype = "(Hardware default)"
Case Else: sFreqtype = "(User-selected)"
End Select
Label1.Caption = currHRes & " pixels"
Label2.Caption = currVRes & " pixels"
Label3.Caption = currBPP & " bits per pixel " & sBPPtype
Label4.Caption = currVFreq & " hz " & sFreqtype
End Sub
Ниже приведены константы из заголовочного
файла Windows, которые возвращаются функцией
GetDeviceCaps().
Private Const DRIVERVERSION As Long = 0 'Версия драйвера
Private Const TECHNOLOGY As Long = 2 'Классификация устройства
Private Const HORZSIZE As Long = 4 'Размер по горизонтали в мм.
Private Const VERTSIZE As Long = 6 'Размер по вертикали в мм.
Private Const HORZRES As Long = 8 'Размер по горизонтали в точках
Private Const VERTRES As Long = 10 'Размер по вертикали в точках
Private Const BITSPIXEL As Long = 12 'Кол-во бит на точку
Private Const PLANES As Long = 14 'Number of planes
Private Const NUMBRUSHES As Long = 16 'Number of brushes the device has
Private Const NUMPENS As Long = 18 'Number of pens the device has
Private Const NUMMARKERS As Long = 20 'Number of markers the device has
Private Const NUMFONTS As Long = 22 'Number of fonts the device has
Private Const NUMCOLORS As Long = 24 'Макс. кол-во возможных цветов
Private Const PDEVICESIZE As Long = 26 'Size required for device descripto
Private Const CURVECAPS As Long = 28 'Curve capabilities
Private Const LINECAPS As Long = 30 'Line capabilities
Private Const POLYGONALCAPS As Long = 32 'Polygonal capabilities
Private Const TEXTCAPS As Long = 34 'Text capabilities
Private Const CLIPCAPS As Long = 36 'Clipping capabilities
Private Const RASTERCAPS As Long = 38 'Bitblt capabilities
Private Const ASPECTX As Long = 40 'Length of the X leg
Private Const ASPECTY As Long = 42 'Length of the Y leg
Private Const ASPECTXY As Long = 44 'Length of the hypotenuse
Private Const SHADEBLENDCAPS As Long = 45 'Shading and blending caps (IE5)
Private Const LOGPIXELSX As Long = 88 'Logical pixels/inch in X
Private Const LOGPIXELSY As Long = 90 'Logical pixels/inch in Y
Private Const SIZEPALETTE As Long = 104 'Number of entries in physical palette
Private Const NUMRESERVED As Long = 106 'Number of reserved entries in palette
Private Const COLORRES As Long = 108 'Количество цветов
Private Const VREFRESH As Long = 116 'Текущий рефрешь по вертикали в Гц
'(только для монитора)
Private Const DESKTOPVERTRES As Long = 117 'Размер десктопа по горизонтали
Private Const DESKTOPHORZRES As Long = 118 'Размер десктопа по вертикали
Private Const BLTALIGNMENT As Long = 119 'Preferred blt alignment
Private Sub Command1_Click()
'Получаем системные установки
Print GetDeviceCaps(hdc, DRIVERVERSION) 'Версия драйвера
Print GetDeviceCaps(hdc, TECHNOLOGY) 'Классификация устройства
Print GetDeviceCaps(hdc, HORZSIZE) 'Размер по горизонтали в мм.
Print GetDeviceCaps(hdc, VERTSIZE) 'Размер по вертикали в мм.
Print GetDeviceCaps(hdc, HORZRES) 'Размер по горизонтали в точках
Print GetDeviceCaps(hdc, VERTRES) 'Размер по вертикали в точках
Print GetDeviceCaps(hdc, BITSPIXEL) 'Кол-во бит на точку
Print GetDeviceCaps(hdc, PLANES) 'Number of planes
Print GetDeviceCaps(hdc, NUMBRUSHES) 'Number of brushes the device has
Print GetDeviceCaps(hdc, NUMPENS) 'Number of pens the device has
Print GetDeviceCaps(hdc, NUMMARKERS) 'Number of markers the device has
Print GetDeviceCaps(hdc, NUMFONTS) 'Number of fonts the device has
Print GetDeviceCaps(hdc, NUMCOLORS) 'Number of colours the device supports
Print GetDeviceCaps(hdc, PDEVICESIZE) 'Size required for device descriptor
Print GetDeviceCaps(hdc, CURVECAPS) 'Curve capabilities
Print GetDeviceCaps(hdc, LINECAPS) 'Line capabilities
Print GetDeviceCaps(hdc, POLYGONALCAPS) 'Polygonal capabilities
Print GetDeviceCaps(hdc, TEXTCAPS) 'Text capabilities
Print GetDeviceCaps(hdc, CLIPCAPS) 'Clipping capabilities
Print GetDeviceCaps(hdc, RASTERCAPS) 'BitBlt capabilities
Print GetDeviceCaps(hdc, ASPECTX) 'Length of the X leg
Print GetDeviceCaps(hdc, ASPECTY) 'Length of the Y leg
Print GetDeviceCaps(hdc, ASPECTXY) 'Length of the hypotenuse
Print GetDeviceCaps(hdc, SHADEBLENDCAPS) 'Shading and blending caps (IE5)
Print GetDeviceCaps(hdc, LOGPIXELSX) 'Logical pixels/inch in X
Print GetDeviceCaps(hdc, LOGPIXELSY) 'Logical pixels/inch in Y
Print GetDeviceCaps(hdc, SIZEPALETTE) 'Number of entries in physical palette
Print GetDeviceCaps(hdc, NUMRESERVED) 'Number of reserved entries in palette
Print GetDeviceCaps(hdc, COLORRES) 'Количество цветов
Print GetDeviceCaps(hdc, VREFRESH) 'Текущий рефрешь по вертикали в Гц
'(только для монитора)
Print GetDeviceCaps(hdc, DESKTOPVERTRES) 'Размер десктопа по горизонтали
Print GetDeviceCaps(hdc, DESKTOPHORZRES) 'Размер десктопа по вертикали
Print GetDeviceCaps(hdc, BLTALIGNMENT) 'Preferred blt alignment
End Sub
|