Sign in to follow this  

Get All Possible Screen Resolutions

Recommended Posts

redneon    134
Is it possible, using DirectX, to get a list of all the possible screen resolutions a card or monitor supports? The list I'm after is all the resolutions available in the Screen Resolution section of the Display Properties. It'd be handy too if it worked for multiple monitors. Any ideas? Cheers, Darrell

Share this post

Link to post
Share on other sites
Jacob Roman    120
Look for DirectX8_Enumerate_Display_Modes() in this code, as well as DirectX8_Initialize() to see how it's implemented. This is from a game I'm writing. Also DirectX8_Initialize() is a hybrid of Fullscreen/Windowed, so it makes it easier to work with. And if the screen resolution & color depth doesn't exist, it'll use the current reslution setting they have. Cool error handler there. I don't have DirectX8_Enumerate_Display_Modes() to where it'll list it in a Listbox, but what it does is put it in an array. Hope this helps.

Conversion to C++ shoudln't be a problem if that's what your

Option Explicit

Public Const COLOR_DEPTH_UNKNOWN As Long = D3DFMT_UNKNOWN '4 Bit 16 Color Mode or other.
Public Const COLOR_DEPTH_8_BIT As Long = D3DFMT_P8
Public Const COLOR_DEPTH_16_BIT As Long = D3DFMT_R5G6B5
Public Const COLOR_DEPTH_24_BIT As Long = D3DFMT_A8R8G8B8
Public Const COLOR_DEPTH_32_BIT As Long = D3DFMT_X8R8G8B8

Public Enum Device_Type


End Enum

Public DirectX8 As DirectX8
Public Direct3D8 As Direct3D8
Public Direct3DX As D3DX8
Public Direct3D_Device As Direct3DDevice8
Public Caps As D3DCAPS8

Public Direct3D_Adapter_Info As D3DADAPTER_IDENTIFIER8
Public Adapter_Info() As D3DADAPTER_IDENTIFIER8
Public Adapter_Name() As String
Public Number_Of_Adapters As Long
Public Current_Adapter As Long

Public Direct3D_Display_Mode As D3DDISPLAYMODE 'Actual Display mode to set.
Public Display_Mode() As D3DDISPLAYMODE 'Enumeration
Public Number_Of_Display_Modes As Long
Public Current_Display_Mode As Long

Public Swap_Effect_Default As Boolean

Public Fullscreen_Enabled As Boolean

Public Fullscreen_Width As Long
Public Fullscreen_Height As Long

Public Sub DirectX8_Initialize(Window As Long, ByVal Width As Long, ByVal Height As Long, ByVal Color_Depth As Long, Device_Type As Device_Type, Fullscreen_Enabled As Boolean, Optional ByVal Swap_Effect As Long = D3DSWAPEFFECT_FLIP)

Set DirectX8 = New DirectX8
Set Direct3D8 = DirectX8.Direct3DCreate()
Set Direct3DX = New D3DX8



Device_Type = DirectX8_Enumerate_Devices(Device_Type)

If Fullscreen_Enabled = True Then


DirectX8_Validate_Display_Mode Width, Height, Color_Depth

If Swap_Effect = D3DSWAPEFFECT_FLIP Then Swap_Effect_Default = True

Direct3D_Window.SwapEffect = Swap_Effect 'D3DSWAPEFFECT_FLIP
Direct3D_Window.BackBufferCount = 1
Direct3D_Window.BackBufferFormat = Direct3D_Display_Mode.Format
Direct3D_Window.BackBufferWidth = Direct3D_Display_Mode.Width
Direct3D_Window.BackBufferHeight = Direct3D_Display_Mode.Height
Direct3D_Window.hDeviceWindow = Window

Fullscreen_Width = Width
Fullscreen_Height = Height


Swap_Effect_Default = True

Direct3D_Window.Windowed = 1
Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
Direct3D_Window.BackBufferFormat = Direct3D_Display_Mode.Format

End If

End Sub

Public Sub DirectX8_Enumerate_Adapters()

Dim Temperary As String, Current_Character As Long

Number_Of_Adapters = Direct3D8.GetAdapterCount

ReDim Adapter_Info(Number_Of_Adapters) As D3DADAPTER_IDENTIFIER8

ReDim Adapter_Name(Number_Of_Adapters) As String

For Current_Adapter = 0 To Number_Of_Adapters - 1

Direct3D8.GetAdapterIdentifier Current_Adapter, 0, Adapter_Info(Current_Adapter)

For Current_Character = 0 To 511

Temperary = Temperary & Chr(Adapter_Info(Current_Adapter).Description(Current_Character))

Next Current_Character

Adapter_Name(Current_Adapter) = Trim(Temperary)

Next Current_Adapter

End Sub

Public Function DirectX8_Enumerate_Devices(ByVal Device_Type As Device_Type) As Long

On Error GoTo Error_Handler

Direct3D8.GetDeviceCaps 0, Device_Type, Caps

Select Case Device_Type

Case Is = HAL

Case Is = REF

Case Is = SW

End Select

DirectX8_Enumerate_Devices = Device_Type

Exit Function



Select Case Device_Type

Case Is = HAL

DirectX8_Enumerate_Devices REF

Case Is = REF

DirectX8_Enumerate_Devices SW

Case Is = SW

MsgBox "Your video card's acceleration Is unknown.", vbCritical

End Select

End If

End Function

Public Sub DirectX8_Enumerate_Display_Modes()

Number_Of_Display_Modes = Direct3D8.GetAdapterModeCount(0)

ReDim Display_Mode(Number_Of_Display_Modes) As D3DDISPLAYMODE

For Current_Display_Mode = 0 To Number_Of_Display_Modes - 1

'For every display mode it finds, it puts it
'into an array called Display_Mode().

Direct3D8.EnumAdapterModes 0, Current_Display_Mode, Display_Mode(Current_Display_Mode)

Next Current_Display_Mode

End Sub

Public Sub DirectX8_Validate_Display_Mode(ByVal Width As Long, ByVal Height As Long, ByVal Color_Depth As Long)

Select Case Color_Depth

Case 8

Color_Depth = COLOR_DEPTH_8_BIT

Case 16

Color_Depth = COLOR_DEPTH_16_BIT

Case 24

Color_Depth = COLOR_DEPTH_24_BIT

Case 32

Color_Depth = COLOR_DEPTH_32_BIT

End Select

For Current_Display_Mode = 0 To Number_Of_Display_Modes - 1

If Width = Display_Mode(Current_Display_Mode).Width And _
Height = Display_Mode(Current_Display_Mode).Height And _
Color_Depth = Display_Mode(Current_Display_Mode).Format Then

Direct3D_Display_Mode.Format = Color_Depth
Direct3D_Display_Mode.Width = Width
Direct3D_Display_Mode.Height = Height

End If


'Use current display mode.

Next Current_Display_Mode

End Sub

Public Sub DirectX8_Default_Display_Mode()

Direct3D8.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Direct3D_Display_Mode

End Sub

Public Sub DirectX8_Shutdown()

Set Direct3D_Device = Nothing
Set Direct3D8 = Nothing
Set DirectX8 = Nothing

'MsgBox "DirectX Shutdown", vbExclamation

End Sub

[Edited by - Jacob Roman on October 2, 2004 3:01:59 PM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this