Get All Possible Screen Resolutions
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
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
using.
[Edited by - Jacob Roman on October 2, 2004 3:01:59 PM]
Conversion to C++ shoudln't be a problem if that's what your
using.
'-----------------------------------------------------------'CODE BEGINS HERE'-----------------------------------------------------------Option ExplicitPublic Const COLOR_DEPTH_UNKNOWN As Long = D3DFMT_UNKNOWN '4 Bit 16 Color Mode or other.Public Const COLOR_DEPTH_8_BIT As Long = D3DFMT_P8Public Const COLOR_DEPTH_16_BIT As Long = D3DFMT_R5G6B5Public Const COLOR_DEPTH_24_BIT As Long = D3DFMT_A8R8G8B8Public Const COLOR_DEPTH_32_BIT As Long = D3DFMT_X8R8G8B8Public Enum Device_Type HAL = D3DDEVTYPE_HAL REF = D3DDEVTYPE_REF SW = D3DDEVTYPE_SW End EnumPublic DirectX8 As DirectX8Public Direct3D8 As Direct3D8Public Direct3DX As D3DX8Public Direct3D_Device As Direct3DDevice8Public Direct3D_Window As D3DPRESENT_PARAMETERSPublic Caps As D3DCAPS8Public Direct3D_Adapter_Info As D3DADAPTER_IDENTIFIER8Public Adapter_Info() As D3DADAPTER_IDENTIFIER8Public Adapter_Name() As StringPublic Number_Of_Adapters As LongPublic Current_Adapter As LongPublic Direct3D_Display_Mode As D3DDISPLAYMODE 'Actual Display mode to set.Public Display_Mode() As D3DDISPLAYMODE 'EnumerationPublic Number_Of_Display_Modes As LongPublic Current_Display_Mode As LongPublic Swap_Effect_Default As BooleanPublic Fullscreen_Enabled As BooleanPublic Fullscreen_Width As LongPublic Fullscreen_Height As LongPublic 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 DirectX8_Default_Display_Mode DirectX8_Enumerate_Adapters Device_Type = DirectX8_Enumerate_Devices(Device_Type) If Fullscreen_Enabled = True Then DirectX8_Enumerate_Display_Modes 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 Else Swap_Effect_Default = True Direct3D_Window.Windowed = 1 Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC Direct3D_Window.BackBufferFormat = Direct3D_Display_Mode.Format End If End SubPublic 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 SubPublic 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 Error_Handler: If Err.Number = D3DERR_INVALIDCALL Then 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 IfEnd FunctionPublic 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_ModeEnd SubPublic 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 'Else 'Use current display mode. Next Current_Display_ModeEnd SubPublic Sub DirectX8_Default_Display_Mode() Direct3D8.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Direct3D_Display_ModeEnd SubPublic Sub DirectX8_Shutdown() Set Direct3D_Device = Nothing Set Direct3D8 = Nothing Set DirectX8 = Nothing 'MsgBox "DirectX Shutdown", vbExclamationEnd Sub'-----------------------------------------------------------'CODE ENDS HERE'-----------------------------------------------------------
[Edited by - Jacob Roman on October 2, 2004 3:01:59 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement