#Include once "window9.bi"

Dim Shared EnumSetDis As Integer
Function EnumSettingsDisplay() As String Export
  EnumSetDis+=1
  dim as integer modeCount
  Dim as DEVMODE dm(0)
  dm(0).dmSize = sizeof(DEVMODE)
  if EnumDisplaySettings( 0, EnumSetDis, @dm(0) ) <> 0 then
    Function=dm(0).dmPelsWidth & "x" & dm(0).dmPelsHeight & "x" & dm(0).dmBitsPerPel & "x" & dm(0).dmDisplayFrequency
  end If
End Function

Function ResetEnum() As Integer Export
  EnumSetDis=0
  Return 1
End Function

Function SetCurrentSettingsDisplay(ByVal width_ As Integer,ByVal height_ As Integer,ByVal Bits As Integer,ByVal Frequency As Integer) As Integer Export
  EnumSetDis=0
  Dim as DEVMODE dm(0)
  dm(0).dmPelsWidth=width_
  dm(0).dmPelsHeight =height_
  dm(0).dmBitsPerPel = Bits
  dm(0).dmDisplayFrequency = Frequency
  dm(0).dmSize = sizeof(DEVMODE)
  dm(0).dmFields = DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT _
  or DM_DISPLAYFLAGS or DM_DISPLAYFREQUENCY
 Return  ChangeDisplaySettings( @dm(0), 0 )
End Function

Function GetCurrentSettingsDisplay() As string Export
  EnumSetDis=0
  Dim as DEVMODE dm(0)
  dm(0).dmSize = sizeof(DEVMODE)
  EnumDisplaySettings( 0, ENUM_CURRENT_SETTINGS, @dm(0))
  Return dm(0).dmPelsWidth  & "x" & dm(0).dmPelsHeight & "x" & dm(0).dmBitsPerPel & "x" & dm(0).dmDisplayFrequency
End Function

Function GetWidthDesktop(ByVal setting As String) As Integer Export
  Var Pos_=InStr(setting,"x")
  function=Val(Mid(setting,1,pos_-1))
End Function

Function GetHeightDesktop(ByVal setting As String) As Integer Export
  Var Pos_=InStr(setting,"x")
  Var Pos1_=InStr(Pos_+1,setting,"x")
  Function =Val(Mid(setting,pos_+1,Pos1_-1))
End Function

Function GetBitsDesktop(ByVal setting As String) As Integer Export
  Var Pos_=InStr(setting,"x")
  Var Pos1_=InStr(Pos_+1,setting,"x")
  Var Pos2_=InStr(Pos1_+1,setting,"x")
  Function = Val(Mid(setting,pos1_+1,Pos2_-1))
End Function

Function GetFrequencyDesktop(ByVal setting As String) As Integer Export
  Var Pos_=InStr(setting,"x")
  Var Pos1_=InStr(Pos_+1,setting,"x")
  Var Pos2_=InStr(Pos1_+1,setting,"x")
  Function = Val(Mid(setting,pos2_+1))
End Function



