home *** CD-ROM | disk | FTP | other *** search
/ Microsoft DirectX SDK 7.0 / Dx7.bin / DXF / samples / multimedia / vbsamples / d3dim / src / tutorials / enumerate / dialog.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-06-23  |  9.1 KB  |  241 lines

  1. VERSION 5.00
  2. Begin VB.Form Dialog 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Pick a Direct3D Device"
  5.    ClientHeight    =   1650
  6.    ClientLeft      =   885
  7.    ClientTop       =   1485
  8.    ClientWidth     =   3255
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   110
  13.    ScaleMode       =   0  'User
  14.    ScaleWidth      =   222.25
  15.    Begin VB.ComboBox cmbDevice 
  16.       Height          =   315
  17.       ItemData        =   "Dialog.frx":0000
  18.       Left            =   840
  19.       List            =   "Dialog.frx":0002
  20.       Style           =   2  'Dropdown List
  21.       TabIndex        =   2
  22.       Top             =   120
  23.       Width           =   2295
  24.    End
  25.    Begin VB.ComboBox cmbMode 
  26.       Height          =   315
  27.       Left            =   840
  28.       Style           =   2  'Dropdown List
  29.       TabIndex        =   1
  30.       Top             =   720
  31.       Width           =   2295
  32.    End
  33.    Begin VB.CommandButton cmdOK 
  34.       Caption         =   "OK"
  35.       Height          =   330
  36.       Left            =   2040
  37.       TabIndex        =   0
  38.       Top             =   1200
  39.       Width           =   1095
  40.    End
  41.    Begin VB.Label Label2 
  42.       Caption         =   "&Mode"
  43.       Height          =   255
  44.       Left            =   120
  45.       TabIndex        =   4
  46.       Top             =   720
  47.       Width           =   855
  48.    End
  49.    Begin VB.Label Label1 
  50.       Caption         =   "&Device"
  51.       Height          =   255
  52.       Left            =   120
  53.       TabIndex        =   3
  54.       Top             =   120
  55.       Width           =   855
  56.    End
  57. Attribute VB_Name = "Dialog"
  58. Attribute VB_GlobalNameSpace = False
  59. Attribute VB_Creatable = False
  60. Attribute VB_PredeclaredId = True
  61. Attribute VB_Exposed = False
  62. Option Explicit
  63. Dim g_dx As New DirectX7
  64. Dim g_ddEnum As DirectDrawEnum
  65. Dim g_d3dEnumDevices As Direct3DEnumDevices
  66. Dim g_ddEnumModes As DirectDrawEnumModes
  67. Dim g_d3d As Direct3D7
  68. Dim g_dd As DirectDraw7
  69. ' Variables to hold enumerated values.
  70. Dim g_sDriverGUID As String
  71. Dim g_sDeviceGUID As String
  72. Dim g_ddsdMode As DDSURFACEDESC2
  73. Dim g_bUsingFullScreen As Boolean
  74. Dim g_bUsing3DHardware As Boolean
  75. Dim g_enumInfo As DDSURFACEDESC2
  76. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  77. '   Called by the main form to retrieve selected driver, device, and mode
  78. '   information.
  79. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  80. Public Sub GetSelectedDriver(sDriverGUID As String, sDeviceGUID As String, Width As Long, Height As Long, BitCount As Long, bUsingFullScreen As Boolean, bUsing3DHardware As Boolean)
  81.     ' Set the enumerated values.
  82.     sDeviceGUID = g_sDriverGUID
  83.     sDeviceGUID = g_sDeviceGUID
  84.     Width = g_ddsdMode.lWidth
  85.     Height = g_ddsdMode.lHeight
  86.     BitCount = g_ddsdMode.ddpfPixelFormat.lRGBBitCount
  87.     bUsingFullScreen = g_bUsingFullScreen
  88.     bUsing3DHardware = g_bUsing3DHardware
  89. End Sub
  90. Private Sub cmbDevice_Click()
  91.     SelectDisplayModes
  92. End Sub
  93. Private Sub Form_Load()
  94.     Form1.Show
  95.     ' Get driver information.
  96.     EnumDriver
  97.     ' Enumerate the display modes.
  98.     EnumModes
  99.     ' Enumerate the devices.
  100.     EnumDevices
  101.     ' Select an enumerated device and build a list of supported display modes
  102.     ' for that device.
  103.     SelectDisplayModes
  104.     Me.Show
  105.  End Sub
  106. Private Sub EnumDriver()
  107.     Dim i As Long
  108.     ' Create the driver, in this case the active display driver.
  109.     Set g_dd = g_dx.DirectDrawCreate("")
  110.         
  111.     ' Get driver information. For this simple tutorial we are just going to use
  112.     ' the primary display driver.
  113.     Set g_ddEnum = g_dx.GetDDEnum()
  114.     For i = 1 To g_ddEnum.GetCount()
  115.         g_sDriverGUID = g_ddEnum.GetDescription(i)
  116.     Next i
  117. End Sub
  118. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  119. '   Enumerate devices.
  120. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  121. Private Sub EnumDevices()
  122.     Dim i As Long
  123.       
  124.     ' Retrieve the Direct3D object for the current display device.
  125.     Set g_d3d = g_dd.GetDirect3D()
  126.             
  127.     ' Get device information and place device user-friendly names in a combo box.
  128.     cmbDevice.Clear
  129.     Set g_d3dEnumDevices = g_d3d.GetDevicesEnum()
  130.     For i = 1 To g_d3dEnumDevices.GetCount()
  131.         cmbDevice.AddItem g_d3dEnumDevices.GetName(i)
  132.     Next
  133.           
  134.     cmbDevice.ListIndex = 0
  135.       
  136.     End Sub
  137. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  138. '   Enumerate display modes.
  139. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  140. Private Sub EnumModes()
  141.    Set g_ddEnumModes = g_dd.GetDisplayModesEnum(DDEDM_DEFAULT, g_enumInfo)
  142. End Sub
  143. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  144. '   Retrieve the display modes for a specific device and display those values in a
  145. '   combo box.
  146. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  147. Private Sub SelectDisplayModes()
  148.     Dim desc As DDSURFACEDESC2
  149.     Dim deviceDesc As D3DDEVICEDESC7
  150.     Dim j As Long
  151.     Dim bCompatible As Boolean
  152.     Dim modeDepth As Long
  153.     Dim bitDepth As Long
  154.     Dim currMode As Long
  155.                
  156.     ' Get the current display mode information
  157.     g_dd.GetDisplayMode desc
  158.     currMode = desc.ddpfPixelFormat.lRGBBitCount
  159.     ' Add the first item to the combo box, which is the current display mode.
  160.     cmbMode.Clear
  161.     cmbMode.AddItem Str(currMode) + "-bit Display Window"
  162.     ' Determine which device has been selected in the combo box. This is the device we want to
  163.     ' build a list of supported modes for, which we will then place in the combo box.
  164.     Call g_d3dEnumDevices.GetDesc(cmbDevice.ListIndex + 1, deviceDesc)
  165.     '
  166.     ' Build the list of supported modes for the device using the following algorithm:
  167.     '   Step 1: Return a video mode description for the specified element in the
  168.     '           DirectDrawEnumModes object.
  169.     '   Step 2: Retrieve the bits per pixel support in the returned video mode description.
  170.     '   Step 3: Retrieve the given device's rendering depth.
  171.     '   Step 4: Check to see if the video mode of the specified element in the DirectDrawEnumModes
  172.     '           object is compatible with the given device's rendering depth. If it is, then accept
  173.     '           the display mode; otherwise, reject it. Skip all 8-bit modes.
  174.     '
  175.     For j = 1 To g_ddEnumModes.GetCount()
  176.         ' We have not tested this display mode yet, so assume it is not compatible.
  177.         bCompatible = False
  178.         ' Step 1:
  179.         g_ddEnumModes.GetItem j, g_enumInfo
  180.                 
  181.         ' Step 2:
  182.         modeDepth = g_enumInfo.ddpfPixelFormat.lRGBBitCount
  183.         
  184.         ' Step 3:
  185.         bitDepth = deviceDesc.lDeviceRenderBitDepth
  186.         
  187.         ' Step 4:
  188.         If (32 = modeDepth) And (bitDepth And DDBD_32) Then bCompatible = True
  189.         If (24 = modeDepth) And (bitDepth And DDBD_24) Then bCompatible = True
  190.         If (16 = modeDepth) And (bitDepth And DDBD_16) Then bCompatible = True
  191.         
  192.         ' Populate the combo box with only the display modes that we want.
  193.         If bCompatible Then
  194.             cmbMode.AddItem Str(g_enumInfo.lWidth) + " x" + Str(g_enumInfo.lHeight) + " x" + Str(g_enumInfo.ddpfPixelFormat.lRGBBitCount)
  195.         End If
  196.     Next j  ' move on to the next mode
  197.        
  198.     cmbMode.ListIndex = 0
  199. End Sub
  200. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  201. '   Save the driver, device, and mode information that was selected in the
  202. '   combo box.
  203. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  204. Private Sub cmdOK_Click()
  205. Dim i As Long
  206.     Dim sDeviceDesc As String
  207.     Dim sModeRes As String
  208.     ' Find the device in the combo list.
  209.     sDeviceDesc = cmbDevice.Text
  210.     For i = 1 To g_d3dEnumDevices.GetCount()
  211.         If sDeviceDesc = g_d3dEnumDevices.GetName(i) Then
  212.             g_sDeviceGUID = g_d3dEnumDevices.GetGuid(i)
  213.         End If
  214.     Next
  215.     ' Determine if we are using a hardware device.
  216.     If g_sDeviceGUID = "IID_IDirect3DHALDevice" Then
  217.         g_bUsing3DHardware = True
  218.     Else
  219.         g_bUsing3DHardware = False
  220.     End If
  221.         
  222.     ' Determine if we are going to render in windowed mode or in full-screen exclusive mode.
  223.     sModeRes = cmbMode.Text
  224.     If sModeRes = cmbMode.List(0) Then
  225.         g_bUsingFullScreen = False
  226.     Else
  227.         g_bUsingFullScreen = True
  228.     End If
  229.     ' Find the DirectDraw surface description.
  230.     Dim ddsd As DDSURFACEDESC2
  231.     For i = 1 To g_ddEnumModes.GetCount()
  232.         g_ddEnumModes.GetItem i, ddsd
  233.          If sModeRes = Str(ddsd.lWidth) + " x" + Str(ddsd.lHeight) + " x" + Str(ddsd.ddpfPixelFormat.lRGBBitCount) Then
  234.             g_ddsdMode = ddsd
  235.          End If
  236.     Next i
  237.     Unload Me
  238.     ' Run the Application.
  239.     Form1.RunApp
  240. End Sub
  241.