home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / common / selectdevice.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  2000-10-09  |  9.3 KB  |  292 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSelectDevice 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Select Device"
  5.    ClientHeight    =   2805
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   6045
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2805
  13.    ScaleWidth      =   6045
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Frame optRenderingModeoptRenderingMode 
  17.       Caption         =   "Rendering Mode"
  18.       Height          =   1335
  19.       Left            =   120
  20.       TabIndex        =   7
  21.       Top             =   1320
  22.       Width           =   4575
  23.       Begin VB.ComboBox cboFullScreenMode 
  24.          Enabled         =   0   'False
  25.          Height          =   315
  26.          Left            =   2040
  27.          Style           =   2  'Dropdown List
  28.          TabIndex        =   10
  29.          Top             =   720
  30.          Width           =   2295
  31.       End
  32.       Begin VB.OptionButton optRenderingMode 
  33.          Caption         =   "&Fullscreen mode"
  34.          Height          =   375
  35.          Index           =   1
  36.          Left            =   240
  37.          TabIndex        =   9
  38.          Top             =   690
  39.          Width           =   1455
  40.       End
  41.       Begin VB.OptionButton optRenderingMode 
  42.          Caption         =   "Use desktop &window"
  43.          Height          =   375
  44.          Index           =   0
  45.          Left            =   240
  46.          TabIndex        =   8
  47.          Top             =   240
  48.          Value           =   -1  'True
  49.          Width           =   1815
  50.       End
  51.    End
  52.    Begin VB.CommandButton cmdCancel 
  53.       Caption         =   "Cancel"
  54.       Height          =   375
  55.       Left            =   4800
  56.       TabIndex        =   4
  57.       Top             =   720
  58.       Width           =   975
  59.    End
  60.    Begin VB.CommandButton cmdOk 
  61.       Caption         =   "OK"
  62.       Height          =   375
  63.       Left            =   4800
  64.       TabIndex        =   3
  65.       Top             =   240
  66.       Width           =   975
  67.    End
  68.    Begin VB.Frame Frame1 
  69.       Caption         =   "Rendering device"
  70.       Height          =   1095
  71.       Left            =   120
  72.       TabIndex        =   0
  73.       Top             =   120
  74.       Width           =   4575
  75.       Begin VB.ComboBox cboDevice 
  76.          Height          =   315
  77.          Left            =   1440
  78.          Style           =   2  'Dropdown List
  79.          TabIndex        =   6
  80.          Top             =   600
  81.          Width           =   2775
  82.       End
  83.       Begin VB.ComboBox cboAdapter 
  84.          Height          =   315
  85.          Left            =   1440
  86.          Style           =   2  'Dropdown List
  87.          TabIndex        =   2
  88.          Top             =   240
  89.          Width           =   2775
  90.       End
  91.       Begin VB.Label Label2 
  92.          AutoSize        =   -1  'True
  93.          Caption         =   "D3D &device:"
  94.          Height          =   195
  95.          Left            =   360
  96.          TabIndex        =   5
  97.          Top             =   660
  98.          Width           =   900
  99.       End
  100.       Begin VB.Label Label1 
  101.          AutoSize        =   -1  'True
  102.          Caption         =   "&Adapter:"
  103.          Height          =   195
  104.          Left            =   360
  105.          TabIndex        =   1
  106.          Top             =   300
  107.          Width           =   600
  108.       End
  109.    End
  110. Attribute VB_Name = "frmSelectDevice"
  111. Attribute VB_GlobalNameSpace = False
  112. Attribute VB_Creatable = False
  113. Attribute VB_PredeclaredId = True
  114. Attribute VB_Exposed = False
  115. Option Explicit
  116. Dim m_callback As Object
  117. Public Sub SelectDevice(callback As Object)
  118.     If callback Is Nothing Then Exit Sub
  119.     Set m_callback = callback
  120.     Dim dm As D3DDISPLAYMODE
  121.     If g_d3dpp.Windowed = 0 Then
  122.         m_callback.InvalidateDeviceObjects
  123.         D3DUtil_ResetWindowed
  124.         m_callback.RestoreDeviceObjects
  125.         
  126.     End If
  127.     Me.Show 1
  128.     Set m_callback = Nothing
  129. End Sub
  130. Private Sub cboAdapter_Click()
  131.     Dim devtype As CONST_D3DDEVTYPE
  132.       
  133.     If (cboDevice.ListIndex = 1) Then
  134.         devtype = D3DDEVTYPE_REF
  135.     Else
  136.         devtype = D3DDEVTYPE_HAL
  137.     End If
  138.        
  139.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  140. End Sub
  141. Private Sub cboDevice_Change()
  142.     Dim devtype As CONST_D3DDEVTYPE
  143.     If (cboDevice.ListIndex = 1) Then
  144.         devtype = D3DDEVTYPE_REF
  145.     Else
  146.         devtype = D3DDEVTYPE_HAL
  147.     End If
  148.        
  149.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  150. End Sub
  151. Private Sub cmdCancel_Click()
  152.     Set m_callback = Nothing
  153.     Unload Me
  154. End Sub
  155. Private Sub cmdOk_Click()
  156.     On Local Error Resume Next
  157.     Dim bAdapterChanged As Boolean
  158.     Dim bRasterizerChanged As Boolean
  159.     Dim bRef As Boolean
  160.     Dim lWindowed As Long
  161.     Dim AdapterID As Long
  162.     Dim ModeID As Long
  163.     Dim devtype As CONST_D3DDEVTYPE
  164.     AdapterID = cboAdapter.ListIndex
  165.     ModeID = cboFullScreenMode.ListIndex
  166.         
  167.     ' see if user changed adapters
  168.     If g_lCurrentAdapter <> AdapterID Then bAdapterChanged = True
  169.                 
  170.     bRef = g_Adapters(g_lCurrentAdapter).bReference
  171.         
  172.     If (cboDevice.ListIndex = 1) Then
  173.         devtype = D3DDEVTYPE_REF
  174.     Else
  175.         devtype = D3DDEVTYPE_HAL
  176.     End If
  177.     ' see if user changed rasterizers
  178.     If (devtype = D3DDEVTYPE_REF And bRef = False) Then bRasterizerChanged = True
  179.     If (devtype = D3DDEVTYPE_HAL And bRef = True) Then bRasterizerChanged = True
  180.     If optRenderingMode(1).Value = True Then
  181.         lWindowed = 0
  182.     Else
  183.         lWindowed = 1
  184.     End If
  185.         
  186.     ' if they didnt change adapters or switch to refrast, then we can just use reset
  187.     If bAdapterChanged = False And bRasterizerChanged = False Then
  188.                 
  189.         'If trying to go Fullscreen
  190.         If lWindowed = 0 Then
  191.         
  192.             'call g_dev.reset
  193.             Call D3DUtil_ResizeFullscreen(g_focushwnd, cboFullScreenMode.ListIndex)
  194.         
  195.         Else
  196.             
  197.             Call D3DUtil_ResizeWindowed(g_focushwnd)
  198.         
  199.         End If
  200.         
  201.         'tell user needs to restore device objects
  202.         m_callback.RestoreDeviceObjects
  203.         
  204.         'exit modal dialog
  205.         Unload Me
  206.         Exit Sub
  207.     End If
  208.     Set g_dev = Nothing
  209.     D3DUtil_ReleaseAllTexturesFromPool
  210.     'tell user to lose reference counts in its objects device objects
  211.     m_callback.InvalidateDeviceObjects
  212.     m_callback.DeleteDeviceObjects
  213.     'Reinitialize D3D
  214.     If lWindowed = 0 Then
  215.         D3DUtil_InitFullscreen g_focushwnd, AdapterID, ModeID, devtype, True
  216.     Else
  217.         D3DUtil_InitWindowed g_focushwnd, AdapterID, devtype, True
  218.     End If
  219.         
  220.     'tell user to re-create device objects
  221.     m_callback.InitDeviceObjects
  222.     'tell user to restore device objects
  223.     m_callback.RestoreDeviceObjects
  224.     'exit modal dialog
  225.     Unload Me
  226. End Sub
  227. Private Sub Form_Load()
  228.         
  229.     Call UpdateAdapters
  230.     Call UpdateDevices(g_lCurrentAdapter)
  231.     Call UpdateModes(g_lCurrentAdapter, g_Adapters(g_lCurrentAdapter).DeviceType)
  232. End Sub
  233. Private Sub UpdateAdapters()
  234.     Dim i As Long, j As Long
  235.     Dim sDescription As String
  236.     cboAdapter.Clear
  237.         
  238.     For i = 0 To g_lNumAdapters - 1
  239.         
  240.         sDescription = vbNullString
  241.         For j = 0 To 511
  242.             sDescription = sDescription & Chr$(g_Adapters(i).d3dai.Description(j))
  243.         Next
  244.         sDescription = Replace$(sDescription, Chr$(0), " ")
  245.         cboAdapter.AddItem sDescription
  246.     Next
  247.     cboAdapter.ListIndex = g_lCurrentAdapter
  248. End Sub
  249. Private Sub UpdateDevices(adapter As Long)
  250.     Dim i As Long
  251.     cboDevice.Clear
  252.     cboDevice.AddItem "HAL"
  253.     cboDevice.AddItem "REF"
  254.     'If g_Adapters(g_lCurrentAdapter).bReference Then
  255.     If g_Adapters(adapter).bReference Then
  256.         cboDevice.ListIndex = 1
  257.     Else
  258.         cboDevice.ListIndex = 0
  259.     End If
  260. End Sub
  261. Private Sub UpdateModes(adapter As Long, devtype As CONST_D3DDEVTYPE)
  262.     Dim i As Long
  263.     Dim pAdapter As D3DUTIL_ADAPTERINFO
  264.     Dim sModeString As String
  265.     cboFullScreenMode.Clear
  266.             
  267.     With g_Adapters(adapter).DevTypeInfo(devtype)
  268.         For i = 0 To .lNumModes - 1
  269.             sModeString = .Modes(i).lWidth & " x "
  270.             sModeString = sModeString & .Modes(i).lHeight & " x "
  271.             If .Modes(i).format = D3DFMT_X8R8G8B8 Or _
  272.                 .Modes(i).format = D3DFMT_A8R8G8B8 Or _
  273.                 .Modes(i).format = D3DFMT_R8G8B8 Then
  274.                 sModeString = sModeString & "32"
  275.             Else
  276.                 sModeString = sModeString & "16"
  277.             End If
  278.             
  279.             cboFullScreenMode.AddItem sModeString
  280.         Next
  281.         If cboFullScreenMode.ListCount > 0 Then cboFullScreenMode.ListIndex = .lCurrentMode
  282.     End With
  283.                 
  284. End Sub
  285. Private Sub optRenderingMode_Click(Index As Integer)
  286.     If Index = 1 Then
  287.         cboFullScreenMode.Enabled = True
  288.     Else
  289.         cboFullScreenMode.Enabled = False
  290.     End If
  291. End Sub
  292.