home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Easy_COM_b985726252002.psc / demoServer.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-06-26  |  7.6 KB  |  204 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "InterCommVB Server Application (Demo)"
  5.    ClientHeight    =   2610
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   7440
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   2610
  12.    ScaleWidth      =   7440
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.CommandButton Vote 
  15.       Caption         =   "&Vote Now...."
  16.       Height          =   330
  17.       Left            =   3450
  18.       TabIndex        =   7
  19.       Top             =   2265
  20.       Width           =   1860
  21.    End
  22.    Begin VB.CommandButton Transmit 
  23.       Caption         =   "Transmit Now >>"
  24.       Height          =   330
  25.       Left            =   5325
  26.       TabIndex        =   5
  27.       Top             =   2265
  28.       Width           =   2115
  29.    End
  30.    Begin VB.Frame Frame1 
  31.       Caption         =   "Type any Text that you want transmitted"
  32.       Height          =   1620
  33.       Left            =   15
  34.       TabIndex        =   1
  35.       Top             =   405
  36.       Width           =   7440
  37.       Begin VB.CheckBox Dyn 
  38.          Caption         =   "&Dynamic Transmissiion"
  39.          Height          =   195
  40.          Left            =   5100
  41.          TabIndex        =   4
  42.          Top             =   1335
  43.          Value           =   1  'Checked
  44.          Width           =   2880
  45.       End
  46.       Begin VB.TextBox SData 
  47.          Height          =   1020
  48.          Left            =   105
  49.          MultiLine       =   -1  'True
  50.          ScrollBars      =   3  'Both
  51.          TabIndex        =   2
  52.          Top             =   225
  53.          Width           =   7200
  54.       End
  55.    End
  56.    Begin VB.Label ProcID 
  57.       Caption         =   "Current Process ID:"
  58.       BeginProperty Font 
  59.          Name            =   "MS Sans Serif"
  60.          Size            =   8.25
  61.          Charset         =   0
  62.          Weight          =   700
  63.          Underline       =   0   'False
  64.          Italic          =   0   'False
  65.          Strikethrough   =   0   'False
  66.       EndProperty
  67.       Height          =   240
  68.       Left            =   30
  69.       TabIndex        =   6
  70.       Top             =   2325
  71.       Width           =   4380
  72.    End
  73.    Begin VB.Label Lastres 
  74.       Caption         =   "Label1"
  75.       BeginProperty Font 
  76.          Name            =   "MS Sans Serif"
  77.          Size            =   8.25
  78.          Charset         =   0
  79.          Weight          =   700
  80.          Underline       =   0   'False
  81.          Italic          =   0   'False
  82.          Strikethrough   =   0   'False
  83.       EndProperty
  84.       Height          =   195
  85.       Left            =   30
  86.       TabIndex        =   3
  87.       Top             =   2070
  88.       Width           =   7440
  89.    End
  90.    Begin VB.Label Label3 
  91.       Caption         =   "Welcome to the InterCommVB Demonstration !"
  92.       BeginProperty Font 
  93.          Name            =   "MS Sans Serif"
  94.          Size            =   12
  95.          Charset         =   0
  96.          Weight          =   700
  97.          Underline       =   0   'False
  98.          Italic          =   0   'False
  99.          Strikethrough   =   0   'False
  100.       EndProperty
  101.       Height          =   360
  102.       Left            =   0
  103.       TabIndex        =   0
  104.       Top             =   0
  105.       Width           =   7530
  106.    End
  107.    Begin VB.Shape Shape1 
  108.       FillColor       =   &H00C0E0FF&
  109.       FillStyle       =   0  'Solid
  110.       Height          =   105
  111.       Left            =   0
  112.       Top             =   300
  113.       Width           =   7590
  114.    End
  115. Attribute VB_Name = "Form1"
  116. Attribute VB_GlobalNameSpace = False
  117. Attribute VB_Creatable = False
  118. Attribute VB_PredeclaredId = True
  119. Attribute VB_Exposed = False
  120. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  121. Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
  122. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
  123. Const SW_SHOWNORMAL = 1
  124. Const CodeID = 25759
  125. Dim WithEvents Server As InterCommVB.IServer
  126. Attribute Server.VB_VarHelpID = -1
  127. Private Sub Form_Load()
  128. Lastres.Caption = "Result of last transmission:N/A"
  129. 'Initialize the IServer object
  130. Set Server = New IServer
  131. ProcID.Caption = "Current Process ID:" & CStr(GetCurrentProcessId())
  132. 'The last parameter if set to true, ignores a missing
  133. 'data channel and fired the OnConnectionWait event
  134. 'It then waits for the client to connect to the client side
  135. 'interface and causes the OnChannelOpen() event to fire
  136. Server.ConnectToDataChannel 1, Me.hwnd, True
  137. End Sub
  138. Private Sub Form_Unload(Cancel As Integer)
  139. 'Destroy the IServer Object
  140. Server.DisconnectFromChannel
  141. Set Server = Nothing
  142. End Sub
  143. Private Sub SData_Change()
  144. If Dyn.Value = 1 Then
  145. 'Transmit text in textbox to client registered with id# 1
  146. Server.TransmitToClient SData.Text
  147. End If
  148. End Sub
  149. Private Sub Server_OnChannelClose(ByVal ChannelID As Long)
  150.     MsgBox "The Data channel has been closed by the client - No more transmission possible", vbExclamation Or vbOKOnly, "Channel ID:" & ChannelID
  151. End Sub
  152. Private Sub Server_OnChannelOpen(ByVal ChannelID As Long)
  153.     MsgBox "The client app had opened the data channel - Communication is now possible"
  154. End Sub
  155. Private Sub Server_OnChannelReOpen(ByVal ChannelID As Long)
  156.     MsgBox "The data channel has been re-opened by the client - Data transfer is now possible", vbExclamation Or vbOKOnly, "Channel ID:" & ChannelID
  157. End Sub
  158. Private Sub Server_OnConnectionFailure(Reason As String)
  159.     MsgBox "Unable to connect to client - Reason:" & Reason
  160. End Sub
  161. Private Sub Server_OnConnectionSuccess()
  162.     MsgBox "Connection to client established"
  163. End Sub
  164. Private Sub Server_OnConnectionWait()
  165.     MsgBox "The client app had not initialized the data channel as yet. But the communication channel has been initiated and communication will be possible the moment the client initializes the data reception service"
  166. End Sub
  167. Private Sub Server_OnTransmissionFailure(Reason As String)
  168.     'This event fires when transmission fails
  169.     Lastres.Caption = "Result of last transmission:Failure     " & "Reason:" & Reason
  170. End Sub
  171. Private Sub Server_OnTransmissionSuccess()
  172.     'This event fires when transmission is successful
  173.     Lastres.Caption = "Result of last transmission:Success"
  174. End Sub
  175. Private Sub Server_OnVBInternalError(ByVal ErrCode As Long, ByVal ErrDesc As String)
  176.     MsgBox "Internal Error - " & ErrDesc, vbCritical Or vbOKOnly, "Error Code:" & ErrCode
  177. End Sub
  178. Private Sub Transmit_Click()
  179. 'Transmit text in textbox to client registered with id# 1
  180. Server.TransmitToClient SData.Text
  181. End Sub
  182. Sub VoteNow(URL As String)
  183.     Dim Res As Long
  184.     Dim TFile As String, Browser As String, Dum As String
  185.     TFile = App.Path + "\test.htm"
  186.     Open TFile For Output As #1
  187.     Close
  188.     Browser = String(255, " ")
  189.     Res = FindExecutable(TFile, Dum, Browser)
  190.     Browser = Trim$(Browser)
  191.     If Len(Browser) = 0 Then
  192.         MsgBox "Cannot find browser"
  193.         Exit Sub
  194.     End If
  195.     Res = ShellExecute(Me.hwnd, "open", Browser, URL, Dum, SW_SHOWNORMAL)
  196.     If Res <= 32 Then
  197.         MsgBox "Cannot open web page"
  198.         Exit Sub
  199.     End If
  200. End Sub
  201. Private Sub Vote_Click()
  202. VoteNow ("http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=25759&lngWId=1")
  203. End Sub
  204.