The sample script demonstrates how to get and set display settings (the pixels resolution and color depth).
Sub Test
Call SetDisplay(800, 600, 32)
LogDisplayProperties()
Call SetDisplay(1024, 768, 32)
LogDisplayProperties()
End Sub
' The function changes the display settings:
' x - resolution
' y - resolution
' d - color depth
Function SetDisplay(x, y, d)
Dim dm
Dim res
Set dm = Win32API.DEVMODE
If (Win32API.EnumDisplaySettings(VarToInteger(0), -1, dm) <> 0) Then
dm.dmPelsWidth = x
dm.dmPelsHeight = y
dm.dmBitsPerPel = d
res = Win32API.ChangeDisplaySettings(dm, 0)
If (res = DISP_CHANGE_BADMODE) Then
Call Log.Error("A call to the ChangeDisplaySettings() function failed" &_
" in the SetDisplay() function.", "The specified graphics mode" &_
" (screen resolution: " & x & "*" & y & "; color depth: " & d &_
" bits per pixel) is not supported.", pmLower)
End If
SetDisplay = res
Else
Dim dwLastError
dwLastError = Win32API.GetLastError()
Call Log.Error("A call to the EnumDisplaySettings() failed" &_
" in the SetDisplay() function.", "System error code: " &_
dwLastError & " (" &_
Utilities.SysErrorMessage(dwLastError) &")", pmLower)
SetDisplay = -1
End If
End Function
Sub LogDisplayProperties
Dim dm
Set dm = Win32API.DEVMODE
If (Win32API.EnumDisplaySettings(VarToInteger(0), -1, dm) <> 0) Then
Log.AppendFolder("Current display settings")
Log.Message("Width: " & dm.dmPelsWidth)
Log.Message("Height: " & dm.dmPelsHeight)
Log.Message("Bits: " & dm.dmBitsPerPel)
Log.PopLogFolder()
End If
End Sub
Sub Test
Call SetDisplay(800, 600, 32)
LogDisplayProperties()
Call SetDisplay(1024, 768, 32)
LogDisplayProperties()
End Sub
' The function changes the display settings:
' x - resolution
' y - resolution
' d - color depth
Function SetDisplay(x, y, d)
Dim dm
Dim res
Set dm = Win32API.DEVMODE
If (Win32API.EnumDisplaySettings(VarToInteger(0), -1, dm) <> 0) Then
dm.dmPelsWidth = x
dm.dmPelsHeight = y
dm.dmBitsPerPel = d
res = Win32API.ChangeDisplaySettings(dm, 0)
If (res = DISP_CHANGE_BADMODE) Then
Call Log.Error("A call to the ChangeDisplaySettings() function failed" &_
" in the SetDisplay() function.", "The specified graphics mode" &_
" (screen resolution: " & x & "*" & y & "; color depth: " & d &_
" bits per pixel) is not supported.", pmLower)
End If
SetDisplay = res
Else
Dim dwLastError
dwLastError = Win32API.GetLastError()
Call Log.Error("A call to the EnumDisplaySettings() failed" &_
" in the SetDisplay() function.", "System error code: " &_
dwLastError & " (" &_
Utilities.SysErrorMessage(dwLastError) &")", pmLower)
SetDisplay = -1
End If
End Function
Sub LogDisplayProperties
Dim dm
Set dm = Win32API.DEVMODE
If (Win32API.EnumDisplaySettings(VarToInteger(0), -1, dm) <> 0) Then
Log.AppendFolder("Current display settings")
Log.Message("Width: " & dm.dmPelsWidth)
Log.Message("Height: " & dm.dmPelsHeight)
Log.Message("Bits: " & dm.dmBitsPerPel)
Log.PopLogFolder()
End If
End Sub
No comments:
Post a Comment