
PS: Допускается использование DirectX
Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Dim Wid&, Hei&, BPP&, Freq&
Public Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const DM_DISPLAYFREQUENCY = &H400000
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
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 * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Public Sub ChangeResolution(iWidth As Single, iHeight As Single, Optional sReturn As Boolean)
Dim DevM As DEVMODE
Dim a As Boolean
Dim i As Long
Dim b As Long
Dim sfreq As Long
i = 0
Do
a = EnumDisplaySettings(0&, i&, DevM)
i = i + 1
Loop Until (a = False)
If NotFirstChange = False Then
GetVideoMode Wid, Hei, BPP, Freq
'cDebug.StrWrite "Current Desktop mode was: " & CStr(Wid) + "x" + CStr(Hei)+ "x" + CStr(Freq) + " Hz"
NotFirstChange = True
End If
If sReturn = True Then
b = ChangeDisplaySettings(0, 0)
DevM.dmFields = DM_DISPLAYFREQUENCY
If DevM.dmDisplayFrequency <= 1 Then
DevM.dmDisplayFrequency = Freq
End If
b = ChangeDisplaySettings(DevM, 0)
If b = -2 Then
b = ChangeDisplaySettings(0, 0)
'cDebug.StrWrite "Default Refresh rate changing is unsucsessful!"
End If
Exit Sub
End If
' Testing video modes
Dim testFreq&
testFreq = Freq
Do
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY
DevM.dmPelsWidth = iWidth
DevM.dmPelsHeight = iHeight
If DevM.dmDisplayFrequency <> testFreq Then
DevM.dmDisplayFrequency = testFreq
End If
b = ChangeDisplaySettings(DevM, CDS_TEST)
If b <> 0 Then testFreq = testFreq - 5
Loop Until b = 0
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY
DevM.dmPelsWidth = iWidth
DevM.dmPelsHeight = iHeight
If DevM.dmDisplayFrequency <> testFreq Then
DevM.dmDisplayFrequency = testFreq
End If
b = ChangeDisplaySettings(DevM, 0)
If b = -2 Then
'cDebug.StrWrite "Default Refresh rate changing is unsucsessful!" _
+ " Trying to launch in 60 Hz mode"
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY
DevM.dmPelsWidth = iWidth
DevM.dmPelsHeight = iHeight
DevM.dmDisplayFrequency = 60
b = ChangeDisplaySettings(DevM, 0)
If b = -2 Then
MsgBox "Your Monitor does not support any" _
& Cstr(iWidth) & "x" & Cstr(iHeight) & "x" & modes!" _
+ vbCrLf + "Program will close immidiately!", vbOKOnly Or vbCritical
End
End If
End If
End Sub
Сейчас этот форум просматривают: Yandex-бот и гости: 15