home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Common / selectDevice.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  2001-10-08  |  9.7 KB  |  300 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     =   5865
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2805
  13.    ScaleWidth      =   5865
  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.       Default         =   -1  'True
  63.       Height          =   375
  64.       Left            =   4800
  65.       TabIndex        =   3
  66.       Top             =   240
  67.       Width           =   975
  68.    End
  69.    Begin VB.Frame Frame1 
  70.       Caption         =   "Rendering device"
  71.       Height          =   1095
  72.       Left            =   120
  73.       TabIndex        =   0
  74.       Top             =   120
  75.       Width           =   4575
  76.       Begin VB.ComboBox cboDevice 
  77.          Height          =   315
  78.          Left            =   1440
  79.          Style           =   2  'Dropdown List
  80.          TabIndex        =   6
  81.          Top             =   600
  82.          Width           =   2775
  83.       End
  84.       Begin VB.ComboBox cboAdapter 
  85.          Height          =   315
  86.          Left            =   1440
  87.          Style           =   2  'Dropdown List
  88.          TabIndex        =   2
  89.          Top             =   240
  90.          Width           =   2775
  91.       End
  92.       Begin VB.Label Label2 
  93.          AutoSize        =   -1  'True
  94.          Caption         =   "D3D &device:"
  95.          Height          =   195
  96.          Left            =   360
  97.          TabIndex        =   5
  98.          Top             =   660
  99.          Width           =   900
  100.       End
  101.       Begin VB.Label Label1 
  102.          AutoSize        =   -1  'True
  103.          Caption         =   "&Adapter:"
  104.          Height          =   195
  105.          Left            =   360
  106.          TabIndex        =   1
  107.          Top             =   300
  108.          Width           =   600
  109.       End
  110.    End
  111. Attribute VB_Name = "frmSelectDevice"
  112. Attribute VB_GlobalNameSpace = False
  113. Attribute VB_Creatable = False
  114. Attribute VB_PredeclaredId = True
  115. Attribute VB_Exposed = False
  116. Option Explicit
  117. Dim m_callback As Object
  118. Public Sub SelectDevice(callback As Object)
  119.     If callback Is Nothing Then Exit Sub
  120.     Set m_callback = callback
  121.     Dim dm As D3DDISPLAYMODE
  122.     If g_d3dpp.Windowed = 0 Then
  123.         m_callback.InvalidateDeviceObjects
  124.         D3DUtil_ResetWindowed
  125.         m_callback.RestoreDeviceObjects
  126.         
  127.     End If
  128.     Me.Show 1
  129.     Set m_callback = Nothing
  130. End Sub
  131. Private Sub cboAdapter_Click()
  132.     Dim devtype As CONST_D3DDEVTYPE
  133.       
  134.     If (cboDevice.ListIndex = 1) Then
  135.         devtype = D3DDEVTYPE_REF
  136.     Else
  137.         devtype = D3DDEVTYPE_HAL
  138.     End If
  139.        
  140.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  141. End Sub
  142. Private Sub cboDevice_Change()
  143.     Dim devtype As CONST_D3DDEVTYPE
  144.     If (cboDevice.ListIndex = 1) Then
  145.         devtype = D3DDEVTYPE_REF
  146.     Else
  147.         devtype = D3DDEVTYPE_HAL
  148.     End If
  149.        
  150.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  151. End Sub
  152. Private Sub cmdCancel_Click()
  153.     Set m_callback = Nothing
  154.     Unload Me
  155. End Sub
  156. Private Sub cmdOk_Click()
  157.     On Local Error Resume Next
  158.     Dim bAdapterChanged As Boolean
  159.     Dim bRasterizerChanged As Boolean
  160.     Dim bRef As Boolean
  161.     Dim lWindowed As Long
  162.     Dim AdapterID As Long
  163.     Dim ModeID As Long
  164.     Dim devtype As CONST_D3DDEVTYPE
  165.     AdapterID = cboAdapter.ListIndex
  166.     ModeID = cboFullScreenMode.ListIndex
  167.         
  168.     ' see if user changed adapters
  169.     If g_lCurrentAdapter <> AdapterID Then bAdapterChanged = True
  170.                 
  171.     bRef = g_Adapters(g_lCurrentAdapter).bReference
  172.         
  173.     If (cboDevice.ListIndex = 1) Then
  174.         devtype = D3DDEVTYPE_REF
  175.     Else
  176.         devtype = D3DDEVTYPE_HAL
  177.     End If
  178.     ' see if user changed rasterizers
  179.     If (devtype = D3DDEVTYPE_REF And bRef = False) Then bRasterizerChanged = True
  180.     If (devtype = D3DDEVTYPE_HAL And bRef = True) Then bRasterizerChanged = True
  181.     If optRenderingMode(1).Value = True Then
  182.         lWindowed = 0
  183.     Else
  184.         lWindowed = 1
  185.     End If
  186.         
  187.     ' if they didnt change adapters or switch to refrast, then we can just use reset
  188.     If bAdapterChanged = False And bRasterizerChanged = False Then
  189.                 
  190.         'If trying to go Fullscreen
  191.         If lWindowed = 0 Then
  192.         
  193.             'call g_dev.reset
  194.             Call D3DUtil_ResizeFullscreen(g_focushwnd, cboFullScreenMode.ListIndex)
  195.         
  196.         Else
  197.             
  198.             Call D3DUtil_ResizeWindowed(g_focushwnd)
  199.         
  200.         End If
  201.         
  202.         'tell user needs to restore device objects
  203.         m_callback.RestoreDeviceObjects
  204.         
  205.         'exit modal dialog
  206.         Unload Me
  207.         Exit Sub
  208.     End If
  209.     Set g_dev = Nothing
  210.     D3DUtil_ReleaseAllTexturesFromPool
  211.     'tell user to lose reference counts in its objects device objects
  212.     m_callback.InvalidateDeviceObjects
  213.     m_callback.DeleteDeviceObjects
  214.     'Reinitialize D3D
  215.     If lWindowed = 0 Then
  216.         D3DUtil_InitFullscreen g_focushwnd, AdapterID, ModeID, devtype, True
  217.     Else
  218.         D3DUtil_InitWindowed g_focushwnd, AdapterID, devtype, True
  219.     End If
  220.     If g_dev Is Nothing Then
  221.         'The app still hit an error. Both HAL and REF devices weren't created. The app will have to exit at this point.
  222.         MsgBox "No suitable device was found to initialize D3D. Application will now exit.", vbCritical
  223.         End
  224.         Exit Sub
  225.     End If
  226.         
  227.     'tell user to re-create device objects
  228.     m_callback.InitDeviceObjects
  229.     'tell user to restore device objects
  230.     m_callback.RestoreDeviceObjects
  231.     'exit modal dialog
  232.     Unload Me
  233. End Sub
  234. Private Sub Form_Load()
  235.         
  236.     Call UpdateAdapters
  237.     Call UpdateDevices(g_lCurrentAdapter)
  238.     Call UpdateModes(g_lCurrentAdapter, g_Adapters(g_lCurrentAdapter).DeviceType)
  239. End Sub
  240. Private Sub UpdateAdapters()
  241.     Dim i As Long, j As Long
  242.     Dim sDescription As String
  243.     cboAdapter.Clear
  244.         
  245.     For i = 0 To g_lNumAdapters - 1
  246.         
  247.         sDescription = vbNullString
  248. '        For j = 0 To 511
  249. '            sDescription = sDescription & Chr$(g_Adapters(i).d3dai.Description(j))
  250. '        Next
  251. '        sDescription = Replace$(sDescription, Chr$(0), " ")
  252.         sDescription = StrConv(g_Adapters(i).d3dai.Description, vbUnicode)
  253.         cboAdapter.AddItem sDescription
  254.     Next
  255.     cboAdapter.ListIndex = g_lCurrentAdapter
  256. End Sub
  257. Private Sub UpdateDevices(adapter As Long)
  258.     Dim i As Long
  259.     cboDevice.Clear
  260.     cboDevice.AddItem "HAL"
  261.     cboDevice.AddItem "REF"
  262.     'If g_Adapters(g_lCurrentAdapter).bReference Then
  263.     If g_Adapters(adapter).bReference Then
  264.         cboDevice.ListIndex = 1
  265.     Else
  266.         cboDevice.ListIndex = 0
  267.     End If
  268. End Sub
  269. Private Sub UpdateModes(adapter As Long, devtype As CONST_D3DDEVTYPE)
  270.     Dim i As Long
  271.     Dim pAdapter As D3DUTIL_ADAPTERINFO
  272.     Dim sModeString As String
  273.     cboFullScreenMode.Clear
  274.             
  275.     With g_Adapters(adapter).DevTypeInfo(devtype)
  276.         For i = 0 To .lNumModes - 1
  277.             sModeString = .Modes(i).lWidth & " x "
  278.             sModeString = sModeString & .Modes(i).lHeight & " x "
  279.             If .Modes(i).format = D3DFMT_X8R8G8B8 Or _
  280.                 .Modes(i).format = D3DFMT_A8R8G8B8 Or _
  281.                 .Modes(i).format = D3DFMT_R8G8B8 Then
  282.                 sModeString = sModeString & "32"
  283.             Else
  284.                 sModeString = sModeString & "16"
  285.             End If
  286.             
  287.             cboFullScreenMode.AddItem sModeString
  288.         Next
  289.         If cboFullScreenMode.ListCount > 0 Then cboFullScreenMode.ListIndex = .lCurrentMode
  290.     End With
  291.                 
  292. End Sub
  293. Private Sub optRenderingMode_Click(Index As Integer)
  294.     If Index = 1 Then
  295.         cboFullScreenMode.Enabled = True
  296.     Else
  297.         cboFullScreenMode.Enabled = False
  298.     End If
  299. End Sub
  300.