home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Misc / DXSetup / serverdt.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-10-08  |  16.5 KB  |  437 lines

  1. VERSION 5.00
  2. Begin VB.Form frmRemoteServerDetails 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "#"
  5.    ClientHeight    =   4545
  6.    ClientLeft      =   3195
  7.    ClientTop       =   2400
  8.    ClientWidth     =   7800
  9.    ClipControls    =   0   'False
  10.    ControlBox      =   0   'False
  11.    HasDC           =   0   'False
  12.    Icon            =   "serverdt.frx":0000
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    NegotiateMenus  =   0   'False
  16.    ScaleHeight     =   4545
  17.    ScaleWidth      =   7800
  18.    ShowInTaskbar   =   0   'False
  19.    Begin VB.CommandButton cmdCancel 
  20.       Caption         =   "#"
  21.       Height          =   375
  22.       Left            =   5580
  23.       MaskColor       =   &H00000000&
  24.       TabIndex        =   5
  25.       Top             =   3930
  26.       Width           =   1935
  27.    End
  28.    Begin VB.CommandButton cmdOK 
  29.       Caption         =   "#"
  30.       Default         =   -1  'True
  31.       Enabled         =   0   'False
  32.       Height          =   375
  33.       Left            =   3540
  34.       MaskColor       =   &H00000000&
  35.       TabIndex        =   4
  36.       Top             =   3930
  37.       Width           =   1935
  38.    End
  39.    Begin VB.ComboBox cboNetworkProtocol 
  40.       Height          =   300
  41.       Left            =   2400
  42.       Style           =   2  'Dropdown List
  43.       TabIndex        =   3
  44.       Top             =   3165
  45.       Width           =   5100
  46.    End
  47.    Begin VB.TextBox txtNetworkAddress 
  48.       Height          =   300
  49.       Left            =   2400
  50.       MaxLength       =   128
  51.       TabIndex        =   1
  52.       Top             =   2535
  53.       Width           =   5100
  54.    End
  55.    Begin VB.Frame Frame1 
  56.       Height          =   555
  57.       Left            =   225
  58.       TabIndex        =   7
  59.       Top             =   1395
  60.       Width           =   7290
  61.       Begin VB.Label lblServerName 
  62.          Alignment       =   2  'Center
  63.          AutoSize        =   -1  'True
  64.          Caption         =   "#"
  65.          BeginProperty Font 
  66.             Name            =   "MS Sans Serif"
  67.             Size            =   8.25
  68.             Charset         =   0
  69.             Weight          =   700
  70.             Underline       =   0   'False
  71.             Italic          =   0   'False
  72.             Strikethrough   =   0   'False
  73.          EndProperty
  74.          Height          =   195
  75.          Left            =   135
  76.          TabIndex        =   8
  77.          Top             =   240
  78.          Width           =   7020
  79.          WordWrap        =   -1  'True
  80.       End
  81.    End
  82.    Begin VB.Label lblNetworkProtocol 
  83.       AutoSize        =   -1  'True
  84.       Caption         =   "#"
  85.       Height          =   195
  86.       Left            =   210
  87.       TabIndex        =   2
  88.       Top             =   3165
  89.       Width           =   2100
  90.       WordWrap        =   -1  'True
  91.    End
  92.    Begin VB.Label lblNetworkAddress 
  93.       AutoSize        =   -1  'True
  94.       Caption         =   "#"
  95.       Height          =   195
  96.       Left            =   225
  97.       TabIndex        =   0
  98.       Top             =   2535
  99.       Width           =   2100
  100.       WordWrap        =   -1  'True
  101.    End
  102.    Begin VB.Label lblRemoteServerDetails 
  103.       AutoSize        =   -1  'True
  104.       Caption         =   "#"
  105.       BeginProperty Font 
  106.          Name            =   "MS Sans Serif"
  107.          Size            =   9.75
  108.          Charset         =   0
  109.          Weight          =   400
  110.          Underline       =   0   'False
  111.          Italic          =   0   'False
  112.          Strikethrough   =   0   'False
  113.       EndProperty
  114.       Height          =   240
  115.       Left            =   360
  116.       TabIndex        =   6
  117.       Top             =   360
  118.       Width           =   7020
  119.       WordWrap        =   -1  'True
  120.    End
  121. Attribute VB_Name = "frmRemoteServerDetails"
  122. Attribute VB_GlobalNameSpace = False
  123. Attribute VB_Creatable = False
  124. Attribute VB_PredeclaredId = True
  125. Attribute VB_Exposed = False
  126. Option Explicit
  127. Private mfNetworkAddressSpecified As Boolean
  128. Private mfNetworkProtocolSpecified As Boolean
  129. Private mfDCOM As Boolean
  130. Private Declare Function RpcNetworkIsProtseqValid Lib "rpcrt4.dll" Alias "RpcNetworkIsProtseqValidA" (ByVal strProtseq As String) As Long
  131. 'Determines whether a given protocol sequence is supported and available on this machine
  132. Private Function fIsProtocolSeqSupported(ByVal strProto As String, ByVal strProtoFriendlyName) As Boolean
  133.     Const RPC_S_OK = 0&
  134.     Const RPC_S_PROTSEQ_NOT_SUPPORTED = 1703&
  135.     Const RPC_S_INVALID_RPC_PROTSEQ = 1704&
  136.     Dim rcps As Long
  137.     Static fUnexpectedErr As Boolean
  138.     On Error Resume Next
  139.     rcps = RpcNetworkIsProtseqValid(strProto)
  140.     Select Case rcps
  141.         Case RPC_S_OK
  142.             fIsProtocolSeqSupported = True
  143.         Case RPC_S_PROTSEQ_NOT_SUPPORTED
  144.             LogNote ResolveResString(resNOTEPROTOSEQNOTSUPPORTED, gstrPIPE1, strProto, gstrPIPE2, strProtoFriendlyName)
  145.         Case RPC_S_INVALID_RPC_PROTSEQ
  146.             LogWarning ResolveResString(resNOTEPROTOSEQINVALID, gstrPIPE1, strProto, gstrPIPE2, strProtoFriendlyName)
  147.         Case Else
  148.             If Not fUnexpectedErr Then
  149.                 MsgWarning ResolveResString(resPROTOSEQUNEXPECTEDERR), vbOKOnly Or vbInformation, gstrTitle
  150.                 If gfNoUserInput Then
  151.                     '
  152.                     ' This is probably redundant since this form should never
  153.                     ' be shown if we are running in silent or SMS mode.
  154.                     '
  155.                     ExitSetup frmRemoteServerDetails, gintRET_FATAL
  156.                 End If
  157.                 fUnexpectedErr = True
  158.             End If
  159.     End Select
  160. End Function
  161. Private Sub cboNetworkProtocol_Click()
  162.     cmdOK.Enabled = fValid()
  163. End Sub
  164. Private Sub cmdCancel_Click()
  165.     ExitSetup frmRemoteServerDetails, gintRET_EXIT
  166. End Sub
  167. Private Sub cmdOK_Click()
  168.     Hide
  169. End Sub
  170. Private Sub Form_Load()
  171.     Dim fMoveControlsUp As Boolean 'Whether or not to move controls up to fill in an empty space
  172.     Dim yTopCutoff As Integer 'We will move all controls lower down than this y value
  173.     Dim yDiff As Integer
  174.     Dim c As Control
  175.     SetFormFont Me
  176.     Caption = ResolveResString(resREMOTESERVERDETAILSTITLE)
  177.     lblRemoteServerDetails.Caption = ResolveResString(resREMOTESERVERDETAILSLBL)
  178.     lblNetworkAddress.Caption = ResolveResString(resNETWORKADDRESS)
  179.     lblNetworkProtocol.Caption = ResolveResString(resNETWORKPROTOCOL)
  180.     cmdOK.Caption = ResolveResString(resOK)
  181.     cmdCancel.Caption = ResolveResString(resCANCEL)
  182.     '
  183.     ' We don't care about protocols if this is DCOM.
  184.     '
  185.     If Not mfDCOM Then
  186.         FillInProtocols
  187.     End If
  188.     'Now we selectively turn on/off the available controls depending on how
  189.     '  much information we need from the user.
  190.     If mfNetworkAddressSpecified Then
  191.         'The network address has already been filled in, so we can hide this
  192.         '  control and move all the other controls up
  193.         txtNetworkAddress.Visible = False
  194.         lblNetworkAddress.Visible = False
  195.         fMoveControlsUp = True
  196.         yTopCutoff = txtNetworkAddress.Top
  197.     ElseIf mfNetworkProtocolSpecified Or mfDCOM Then
  198.         'The network protocol has already been filled in, so we can hide this
  199.         '  control and move all the other controls up
  200.         cboNetworkProtocol.Visible = False
  201.         lblNetworkProtocol.Visible = False
  202.         fMoveControlsUp = True
  203.         yTopCutoff = cboNetworkProtocol.Top
  204.     End If
  205.     If fMoveControlsUp Then
  206.         'Find out how much to move the controls up
  207.         yDiff = cboNetworkProtocol.Top - txtNetworkAddress.Top
  208.         
  209.         For Each c In Controls
  210.             If c.Top > yTopCutoff Then
  211.                 c.Top = c.Top - yDiff
  212.             End If
  213.         Next c
  214.         
  215.         'Finally, shrink the form
  216.         Height = Height - yDiff
  217.     End If
  218.     'Center the form
  219.     Top = (Screen.Height - Height) \ 2
  220.     Left = (Screen.Width - Width) \ 2
  221. End Sub
  222. '-----------------------------------------------------------
  223. ' SUB: GetServerDetails
  224. ' Requests any missing information about a remote server from
  225. ' the user.
  226. ' Input:
  227. '   [strRegFile] - the name of the remote registration file
  228. '   [strNetworkAddress] - the network address, if known
  229. '   [strNetworkProtocol] - the network protocol, if known
  230. '   [fDCOM] - if true, this component is being accessed via
  231. '             distributed com and not Remote automation.  In
  232. '             this case, we don't need the network protocol or
  233. '             Authentication level.
  234. ' Ouput:
  235. '   [strNetworkAddress] - the network address either passed
  236. '                         in or obtained from the user
  237. '   [strNetworkProtocol] - the network protocol either passed
  238. '                          in or obtained from the user
  239. '-----------------------------------------------------------
  240. Public Sub GetServerDetails( _
  241.     ByVal strRegFile As String, _
  242.     strNetworkAddress As String, _
  243.     strNetworkProtocol As String, _
  244.     fDCOM As Boolean _
  245.     Dim i As Integer
  246.     Dim strServerName As String
  247.     'See if anything is missing
  248.     mfNetworkAddressSpecified = (Len(strNetworkAddress) > 0)
  249.     mfNetworkProtocolSpecified = (Len(strNetworkProtocol) > 0)
  250.     mfDCOM = fDCOM
  251.     If mfNetworkAddressSpecified And (mfNetworkProtocolSpecified Or mfDCOM) Then
  252.         'Both the network address and protocol sequence have already
  253.         'been specified in SETUP.LST.  There is no need to ask the
  254.         'user for more information.
  255.         
  256.         'However, we do need to check that the protocol sequence specified
  257.         'in SETUP.LST is actually installed and available on this machine
  258.         '(Remote Automation only).
  259.         '
  260.         If Not mfDCOM Then
  261.             CheckSpecifiedProtocolSequence strNetworkProtocol, strGetServerName(strRegFile)
  262.         End If
  263.         Exit Sub
  264.     End If
  265.     strServerName = strGetServerName(strRegFile)
  266.     Load Me
  267.     lblServerName.Caption = strServerName
  268.     If Not gfNoUserInput Then
  269.         '
  270.         ' Show the form and extract necessary information from the user
  271.         '
  272.         Show vbModal
  273.     Else
  274.         '
  275.         ' Since this is silent, simply accept the first one on
  276.         ' the list.
  277.         '
  278.         ' Note that we know there is at least 1 protocol in the
  279.         ' list or else the program would have aborted in
  280.         ' the Form_Load code when it called FillInProtocols().
  281.         '
  282.         cboNetworkProtocol.ListIndex = 0
  283.     End If
  284.     If mfNetworkProtocolSpecified And Not mfDCOM Then
  285.         'The network protocol sequence had already been specified
  286.         'in SETUP.LST.  We need to check that the protocol sequence specified
  287.         'in SETUP.LST is actually installed and available on this machine
  288.         '(32-bit only).
  289.         CheckSpecifiedProtocolSequence strNetworkProtocol, strGetServerName(strRegFile)
  290.     End If
  291.     If Not mfNetworkAddressSpecified Then
  292.         strNetworkAddress = txtNetworkAddress
  293.     End If
  294.     If Not mfNetworkProtocolSpecified And Not mfDCOM Then
  295.         strNetworkProtocol = gProtocol(cboNetworkProtocol.ListIndex + 1).strName
  296.     End If
  297.     Unload Me
  298. End Sub
  299. '-----------------------------------------------------------
  300. ' SUB: FillInProtocols
  301. ' Fills in the protocol combo with the available protocols from
  302. '   setup.lst
  303. '-----------------------------------------------------------
  304. Private Sub FillInProtocols()
  305.     Dim i As Integer
  306.     Dim fSuccessReading As Boolean
  307.     Dim strMsg As String
  308.     cboNetworkProtocol.Clear
  309.     fSuccessReading = ReadProtocols(gstrSetupInfoFile, gstrINI_SETUP)
  310.     If Not fSuccessReading Or gcProtocols <= 0 Then
  311.         MsgError ResolveResString(resNOPROTOCOLSINSETUPLST), vbExclamation Or vbOKOnly, gstrTitle
  312.         ExitSetup frmRemoteServerDetails, gintRET_FATAL
  313.     End If
  314.     For i = 1 To gcProtocols
  315.         If fIsProtocolSeqSupported(gProtocol(i).strName, gProtocol(i).strFriendlyName) Then
  316.             cboNetworkProtocol.AddItem gProtocol(i).strFriendlyName
  317.         End If
  318.     Next i
  319.     If cboNetworkProtocol.ListCount > 0 Then
  320.         'We were successful in finding at least one protocol available on this machine
  321.         Exit Sub
  322.     End If
  323.     'None of the protocols specified in SETUP.LST are available on this machine.  We need
  324.     'to let the user know what's wrong, including which protocol(s) were expected.
  325.     MsgError ResolveResString(resNOPROTOCOLSSUPPORTED1), vbExclamation Or vbOKOnly, gstrTitle
  326.     '
  327.     ' Don't log the rest if this in SMS.  Ok for silent mode since
  328.     ' silent can take more than 255 characters.
  329.     '
  330. #If SMS Then
  331.     If Not gfSMS Then
  332. #End If
  333.         strMsg = ResolveResString(resNOPROTOCOLSSUPPORTED2) & vbLf
  334.         For i = 1 To gcProtocols
  335.             strMsg = strMsg & vbLf & vbTab & gProtocol(i).strFriendlyName
  336.         Next i
  337.         
  338.         MsgError strMsg, vbExclamation Or vbOKOnly, gstrTitle
  339. #If SMS Then
  340.     End If
  341. #End If
  342.     ExitSetup frmRemoteServerDetails, gintRET_FATAL
  343. End Sub
  344. '-----------------------------------------------------------
  345. ' SUB: strGetServerName
  346. ' Given a remote server registration file, retrieves the
  347. '   friendly name of the server
  348. '-----------------------------------------------------------
  349. Private Function strGetServerName(ByVal strRegFilename As String) As String
  350.     Const strKey = "AppDescription="
  351.     Dim strLine As String
  352.     Dim iFile As Integer
  353.     Dim strName As String
  354.     On Error GoTo DoErr
  355.     'This will have to do if we can't find the friendly name
  356.     SeparatePathAndFileName strRegFilename, , strGetServerName
  357.     iFile = FreeFile
  358.     Open strRegFilename For Input Access Read Lock Read Write As #iFile
  359.     Do Until EOF(iFile)
  360.         Line Input #iFile, strLine
  361.         If InStr(1, UCase$(strLine), UCase$(strKey)) = 1 Then
  362.             'We've found the line with the friendly server name
  363.             strName = Mid$(strLine, Len(strKey) + 1)
  364.             If Len(strName) > 0 Then
  365.                 strGetServerName = strName
  366.             End If
  367.             Exit Do
  368.         End If
  369.     Loop
  370.     Close iFile
  371.     Exit Function
  372. DoErr:
  373.     strGetServerName = vbNullString
  374. End Function
  375. Private Sub txtNetworkAddress_Change()
  376.     cmdOK.Enabled = fValid()
  377. End Sub
  378. 'Returns True iff the inputs are valid
  379. Private Function fValid() As Boolean
  380.     fValid = True
  381.     '
  382.     ' If this is dcom, we don't care about the network protocol.
  383.     '
  384.     If Not mfDCOM Then
  385.         If Not mfNetworkProtocolSpecified Then
  386.             If cboNetworkProtocol.ListIndex < 0 Then
  387.                 fValid = False
  388.                 Exit Function
  389.             End If
  390.         End If
  391.     End If
  392.     If Not mfNetworkAddressSpecified Then
  393.         If Len(txtNetworkAddress.Text) = 0 Then
  394.             fValid = False
  395.         End If
  396.     End If
  397. End Function
  398. Private Sub CheckSpecifiedProtocolSequence(ByVal strNetworkProtocol As String, ByVal strFriendlyServerName As String)
  399.     'Attempt to find the friendly name of this protocol from the list in SETUP.LST
  400.     Dim fSuccessReading As Boolean
  401.     Dim strFriendlyName As String
  402.     Dim i As Integer
  403.     strFriendlyName = strNetworkProtocol 'This will have to do if we can't find anything better
  404.     fSuccessReading = ReadProtocols(gstrSetupInfoFile, gstrINI_SETUP)
  405.     If fSuccessReading And gcProtocols > 0 Then
  406.         For i = 1 To gcProtocols
  407.             If UCase$(gProtocol(i).strName) = UCase$(strNetworkProtocol) Then
  408.                 strFriendlyName = gProtocol(i).strFriendlyName
  409.                 Exit For
  410.             End If
  411.         Next i
  412.     End If
  413.     'Now check to see if this protocol is available
  414.     If fIsProtocolSeqSupported(strNetworkProtocol, strFriendlyName) Then
  415.         'OK
  416.         Exit Sub
  417.     Else
  418.         'Nope, not supported.  Give an informational message about what to do, then continue with setup.
  419. Retry:
  420.         If gfNoUserInput Or MsgError( _
  421.             ResolveResString(resSELECTEDPROTONOTSUPPORTED, gstrPIPE1, strFriendlyServerName, gstrPIPE2, strFriendlyName), _
  422.             vbInformation Or vbOKCancel, _
  423.             gstrTitle) _
  424.           = vbCancel Then
  425.             '
  426.             ' The user chose cancel.  Give them a chance to exit (if this isn't a silent or sms install;
  427.             ' otherwise any call to ExitSetup is deemed fatal.
  428.             '
  429.             ExitSetup frmRemoteServerDetails, gintRET_EXIT
  430.             GoTo Retry
  431.         Else
  432.             'The user chose OK.  Continue with setup.
  433.             Exit Sub
  434.         End If
  435.     End If
  436. End Sub
  437.