#include once "window9.bi"

Dim Shared g_EnumSetDis As Integer

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

Function ResetEnum() As Integer Export
	g_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
	g_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 USTRING Export
	g_EnumSetDis=0
	Dim as DEVMODE dm(0)
	dm(0).dmSize = sizeof(DEVMODE)
	EnumDisplaySettings( 0, ENUM_CURRENT_SETTINGS, @dm(0))
	dim as USTRING sRet
	sRet = dm(0).dmPelsWidth  & "x" & dm(0).dmPelsHeight & "x" & dm(0).dmBitsPerPel & "x" & dm(0).dmDisplayFrequency
	Return sRet
End Function

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

Function GetHeightDesktop(ByRef setting As USTRING) 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(ByRef setting As USTRING) 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(ByRef setting As USTRING) 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
