home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ipchat1a / frmmain.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-10-03  |  11.2 KB  |  351 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form frmMain 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "IP Chat"
  6.    ClientHeight    =   3180
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   4380
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   3180
  13.    ScaleWidth      =   4380
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.CommandButton cmdConnect 
  16.       Caption         =   "Connect"
  17.       Height          =   415
  18.       Left            =   3390
  19.       TabIndex        =   13
  20.       Top             =   2420
  21.       Width           =   975
  22.    End
  23.    Begin MSWinsockLib.Winsock sckConnect 
  24.       Left            =   3480
  25.       Top             =   2760
  26.       _ExtentX        =   741
  27.       _ExtentY        =   741
  28.       _Version        =   393216
  29.    End
  30.    Begin VB.TextBox txtIP 
  31.       Height          =   285
  32.       Left            =   1960
  33.       TabIndex        =   12
  34.       Text            =   "localhost"
  35.       Top             =   2880
  36.       Width           =   1415
  37.    End
  38.    Begin VB.TextBox txtPort 
  39.       Height          =   285
  40.       Left            =   440
  41.       TabIndex        =   10
  42.       Text            =   "400"
  43.       Top             =   2880
  44.       Width           =   1215
  45.    End
  46.    Begin VB.OptionButton optHostGuest 
  47.       Caption         =   "Guest"
  48.       Height          =   195
  49.       Index           =   1
  50.       Left            =   2520
  51.       TabIndex        =   8
  52.       Top             =   2520
  53.       Value           =   -1  'True
  54.       Width           =   735
  55.    End
  56.    Begin VB.OptionButton optHostGuest 
  57.       Caption         =   "Host"
  58.       Height          =   195
  59.       Index           =   0
  60.       Left            =   1800
  61.       TabIndex        =   7
  62.       Top             =   2520
  63.       Width           =   735
  64.    End
  65.    Begin VB.TextBox txtNick 
  66.       Height          =   285
  67.       Left            =   440
  68.       TabIndex        =   6
  69.       Text            =   "NickName"
  70.       Top             =   2460
  71.       Width           =   1215
  72.    End
  73.    Begin VB.CommandButton cmdSend 
  74.       Caption         =   "Send"
  75.       Height          =   300
  76.       Left            =   3600
  77.       TabIndex        =   4
  78.       Top             =   1990
  79.       Width           =   735
  80.    End
  81.    Begin VB.TextBox txtText 
  82.       BeginProperty Font 
  83.          Name            =   "Arial"
  84.          Size            =   9.75
  85.          Charset         =   0
  86.          Weight          =   400
  87.          Underline       =   0   'False
  88.          Italic          =   0   'False
  89.          Strikethrough   =   0   'False
  90.       EndProperty
  91.       Height          =   300
  92.       Left            =   80
  93.       TabIndex        =   3
  94.       Top             =   1990
  95.       Width           =   3495
  96.    End
  97.    Begin VB.Frame frmeSep 
  98.       Height          =   135
  99.       Left            =   0
  100.       TabIndex        =   2
  101.       Top             =   2280
  102.       Width           =   4385
  103.    End
  104.    Begin VB.TextBox txtChat 
  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          =   1660
  115.       Left            =   80
  116.       Locked          =   -1  'True
  117.       MultiLine       =   -1  'True
  118.       ScrollBars      =   2  'Vertical
  119.       TabIndex        =   1
  120.       Top             =   190
  121.       Width           =   4215
  122.    End
  123.    Begin VB.Frame frmeChatWindow 
  124.       Caption         =   "Chat Window"
  125.       Height          =   1935
  126.       Left            =   0
  127.       TabIndex        =   0
  128.       Top             =   0
  129.       Width           =   4365
  130.    End
  131.    Begin VB.Shape shpGreen 
  132.       BackColor       =   &H00008000&
  133.       BackStyle       =   1  'Opaque
  134.       BorderColor     =   &H00008000&
  135.       Height          =   255
  136.       Left            =   3960
  137.       Shape           =   3  'Circle
  138.       Top             =   2880
  139.       Width           =   255
  140.    End
  141.    Begin VB.Shape shpRed 
  142.       BackColor       =   &H000000FF&
  143.       BackStyle       =   1  'Opaque
  144.       BorderColor     =   &H000000FF&
  145.       FillColor       =   &H00000080&
  146.       Height          =   255
  147.       Left            =   3480
  148.       Shape           =   3  'Circle
  149.       Top             =   2880
  150.       Width           =   255
  151.    End
  152.    Begin VB.Label lblIP 
  153.       BackStyle       =   0  'Transparent
  154.       Caption         =   "IP:"
  155.       Height          =   255
  156.       Left            =   1710
  157.       TabIndex        =   11
  158.       Top             =   2910
  159.       Width           =   255
  160.    End
  161.    Begin VB.Label lblPort 
  162.       BackStyle       =   0  'Transparent
  163.       Caption         =   "Port:"
  164.       Height          =   255
  165.       Left            =   0
  166.       TabIndex        =   9
  167.       Top             =   2905
  168.       Width           =   375
  169.    End
  170.    Begin VB.Line lneSep3 
  171.       BorderColor     =   &H80000003&
  172.       Index           =   1
  173.       X1              =   3350
  174.       X2              =   3350
  175.       Y1              =   2400
  176.       Y2              =   2810
  177.    End
  178.    Begin VB.Line lneSep3 
  179.       BorderColor     =   &H00FFFFFF&
  180.       Index           =   0
  181.       X1              =   3360
  182.       X2              =   3360
  183.       Y1              =   2400
  184.       Y2              =   2820
  185.    End
  186.    Begin VB.Line lneSep2 
  187.       BorderColor     =   &H80000003&
  188.       Index           =   1
  189.       X1              =   1680
  190.       X2              =   1680
  191.       Y1              =   2790
  192.       Y2              =   2390
  193.    End
  194.    Begin VB.Line lneSep 
  195.       BorderColor     =   &H80000003&
  196.       Index           =   1
  197.       X1              =   0
  198.       X2              =   3360
  199.       Y1              =   2790
  200.       Y2              =   2790
  201.    End
  202.    Begin VB.Line lneSep2 
  203.       BorderColor     =   &H00FFFFFF&
  204.       Index           =   0
  205.       X1              =   1690
  206.       X2              =   1690
  207.       Y1              =   2805
  208.       Y2              =   2400
  209.    End
  210.    Begin VB.Line lneSep 
  211.       BorderColor     =   &H00FFFFFF&
  212.       Index           =   0
  213.       X1              =   0
  214.       X2              =   3360
  215.       Y1              =   2805
  216.       Y2              =   2805
  217.    End
  218.    Begin VB.Label lblNick 
  219.       BackStyle       =   0  'Transparent
  220.       Caption         =   "Nick: "
  221.       Height          =   255
  222.       Left            =   0
  223.       TabIndex        =   5
  224.       Top             =   2490
  225.       Width           =   495
  226.    End
  227. Attribute VB_Name = "frmMain"
  228. Attribute VB_GlobalNameSpace = False
  229. Attribute VB_Creatable = False
  230. Attribute VB_PredeclaredId = True
  231. Attribute VB_Exposed = False
  232. '**********************************************************
  233. '*               IP Chat by Joseph Huntley                *
  234. '*               joseph_huntley@email.com                 *
  235. '*                http://joseph.vr9.com                   *
  236. '*                                                        *
  237. '*  Made:  October 4, 1999                                *
  238. '*  Level: Intermediate                                   *
  239. '**********************************************************
  240. '* Notes: None                                            *
  241. '**********************************************************
  242. Private Const vbDarkRed = &H80&
  243. Private Const vbDarkGreen = &H8000&
  244. Private Sub cmdSend_Click()
  245.   ''Send text to other person and print it into our textbox
  246.   sckConnect.SendData txtNick.Text & ":" & vbTab & txtText.Text
  247.   txtChat.Text = txtChat.Text & txtNick.Text & ":" & vbTab & txtText.Text & vbCrLf
  248.   ''clear textbox
  249.   txtText.Text = ""
  250.   ''show bottom half of textbox
  251.   txtChat.SelStart = Len(txtChat.ytext)
  252.   txtChat.SelLength = 0
  253. End Sub
  254. Private Sub sckConnect_Close()
  255.    cmdConnect_Click 'Reset everything
  256. End Sub
  257. Private Sub sckConnect_Connect()
  258.    txtChat.Text = txtChat.Text & "*** Connected" & vbCrLf
  259.    ''change circles from red to green
  260.    shpRed.BackColor = vbDarkRed
  261.    shpRed.BorderColor = vbDarkRed
  262.    shpGreen.BackColor = vbGreen
  263.    shpGreen.BorderColor = vbGreen
  264. End Sub
  265. Private Sub sckConnect_ConnectionRequest(ByVal requestID As Long)
  266.    ''check if connected to something else. If so, close that connection
  267.    If sckConnect.State <> sckClosed Then sckConnect.Close
  268.    'accept the connection
  269.    sckConnect.Accept requestID
  270.    ''change circles from red to green
  271.    shpRed.BackColor = vbDarkRed
  272.    shpRed.BorderColor = vbDarkRed
  273.    shpGreen.BackColor = vbGreen
  274.    shpGreen.BorderColor = vbGreen
  275.    txtChat.Text = txtChat.Text & "*** Connected" & vbCrLf
  276. End Sub
  277. Private Sub sckConnect_DataArrival(ByVal bytesTotal As Long)
  278.    Dim strData As String
  279.    'get text to add
  280.    Call sckConnect.GetData(strData$, vbString)
  281.    txtChat.Text = txtChat.Text & strData$ & vbCrLf
  282.    txtChat.SelStart = Len(txtChat.Text)
  283.    txtChat.SelLength = 0
  284. End Sub
  285. Private Sub cmdConnect_Click()
  286.   Dim strIP As String
  287.     If cmdConnect.Caption = "Connect" Or cmdConnect.Caption = "Listen" Then
  288.        txtPort.Enabled = False
  289.        txtNick.Enabled = False
  290.        optHostGuest(0).Enabled = False
  291.        optHostGuest(1).Enabled = False
  292.        cmdConnect.Caption = "Disconnect"
  293.     Else
  294.        txtPort.Enabled = True
  295.        txtNick.Enabled = True
  296.        optHostGuest(0).Enabled = True
  297.        optHostGuest(1).Enabled = True
  298.        
  299.           If optHostGuest(0).Value = True Then
  300.              cmdConnect.Caption = "Listen"
  301.           Else
  302.              cmdConnect.Caption = "Connect"
  303.           End If
  304.           
  305.         sckConnect.Close
  306.         shpRed.BackColor = vbRed
  307.         shpRed.BorderColor = vbRed
  308.         shpGreen.BackColor = vbDarkGreen
  309.         shpGreen.BorderColor = vbDarkGreen
  310.         txtChat.Text = txtChat.Text & "*** Disconnected" & vbCrLf
  311.         Exit Sub
  312.     End If
  313.     Select Case optHostGuest(0).Value
  314.         Case True:  'Host
  315.            ''listen for connections
  316.            sckConnect.LocalPort = CLng(txtPort.Text)
  317.            sckConnect.Listen
  318.            txtChat.Text = "*** Waiting for connection..." & vbCrLf
  319.         Case False: 'Guest
  320.            ''try to connect
  321.            strIP$ = txtIP.Text
  322.            If LCase$(strIP$) = "localhost" Then strIP$ = sckConnect.LocalIP
  323.            sckConnect.Connect txtIP.Text, txtPort.Text
  324.            txtChat.Text = "*** Connecting..." & vbCrLf
  325.     End Select
  326.             
  327. End Sub
  328. Private Sub optHostGuest_Click(Index As Integer)
  329.     Select Case Index
  330.        Case 0: 'Host
  331.           txtIP.Text = sckConnect.LocalIP
  332.           txtIP.BackColor = &H8000000F  'Grey
  333.           txtIP.Locked = True
  334.           cmdConnect.Caption = "Listen"
  335.        Case 1: 'Guest
  336.           txtIP.Text = "localhost"
  337.           txtIP.BackColor = vbWhite
  338.           txtIP.Locked = False
  339.           cmdConnect.Caption = "Connect"
  340.           
  341.     End Select
  342. End Sub
  343. Private Sub Text1_Change()
  344. End Sub
  345. Private Sub txtText_KeyPress(KeyAscii As Integer)
  346.    If KeyAscii = 13 Then 'If user pressed 'Enter'
  347.       cmdSend_Click 'click 'Send' button
  348.       KeyAscii = 0 'Make sure it doesnt write enter to txtText
  349.    End If
  350. End Sub
  351.