Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Chat biutente (Client) - Client.frm

Client.frm

Caricato da: Roberto VB
Scarica il programma completo

  1. Option Explicit
  2. Dim iConta As Integer
  3. Dim X As Long
  4. Dim Nick As String
  5.  
  6.  
  7.  
  8.  
  9. Private Sub cmdConnetti_Click()
  10. On Error GoTo errore
  11. Static Stat As Boolean
  12. Dim vIP As Variant
  13. Dim iPorta As Integer
  14.     'Carico i dati del form Login
  15.    
  16.     vIP = frmLogin.txtIP
  17.     iPorta = frmLogin.txtPorta
  18.     If Stat = False Then
  19.         'Se le caselle di testo txtIP e txtPorta hanno almeno pių di 0 caratteri
  20.         'Allora eseguo le seguenti istruzioni:
  21.         If Len(vIP) > 0 And Len(iPorta) > 0 Then
  22.             TCP.Connect vIP, Val(iPorta)
  23.             'Cambio la caption del CommandButton cmdConnetti
  24.             cmdConnetti.Caption = "Disconnetti"
  25.             'Cambio la caption del menų
  26.             mnuConnetti.Caption = "Disconnetti"
  27.             'Cambio la caption del pannello numero uno
  28.             StatusBar1.Panels(1) = "Disconnette il client"
  29.             'Imposto la variabile Stat a True
  30.             Stat = True
  31.             'Cambio la caption della statusbar
  32.             StatusBar1.Panels(1) = "Stato: " & "Connettendo"
  33.            
  34.         Else
  35.             'Manda un MessageBox con un avviso di dati mancanti
  36.             MsgBox "Dati Mancanti!", vbExclamation
  37.         End If
  38.     Else
  39.         'Chiudo il socket
  40.         TCP.Close
  41.         'Imposto la variabile Stat a False
  42.         Stat = False
  43.         'Cambio la caption della statusbar
  44.         StatusBar1.Panels(1) = "Stato: " & "Chiudendo"
  45.         'Cambio la caption del CommandButton cmdConnetti
  46.         cmdConnetti.Caption = "Connetti"
  47.         'Cambio la caption del menų
  48.         mnuConnetti.Caption = "Connetti"
  49.         'Disattivo i due CommandButton e la TextBox txtInvia
  50.         cmdInvia.Enabled = False
  51.         cmdTrillo.Enabled = False
  52.         txtInvia.Enabled = False
  53.         'Svuoto le textbox dei nick
  54.         txtNick.Text = ""
  55.         txtMioNick.Text = ""
  56.         Exit Sub
  57. errore:
  58.         MsgBox Err.Description, vbExclamation + vbOKOnly, "ERRORE"
  59.     End If
  60. End Sub
  61.  
  62. Private Sub cmdInvia_Click()
  63.     If Len(txtInvia) > 0 Then
  64.         TCP.SendData txtInvia.Text
  65.         txtChat.Text = txtChat.Text & Time$ & Nick & ":" & vbCrLf & txtInvia.Text & vbCrLf
  66.         txtChat.SelStart = Len(txtChat.Text)
  67.         txtInvia.Text = vbNullString
  68.         StatusBar1.Panels(1) = "Stato: " & "Inviando " & LenB(txtInvia.Text) & "Bytes"
  69.     End If
  70. End Sub
  71.  
  72.  
  73.  
  74.  
  75. Private Sub cmdTrillo_Click()
  76. Dim a As String
  77.     a = "Hai ricevuto un trillo!"
  78.     TCP.SendData a
  79.     txtChat.Text = txtChat.Text & "Hai inviato un trillo!" & vbCrLf
  80.     txtChat.SelStart = Len(txtChat.Text)
  81.     txtInvia.Text = vbNullString
  82.     StatusBar1.Panels(1) = "Nota: " & "E' Stato inviato un trillo!"
  83. End Sub
  84.  
  85.  
  86.  
  87.  
  88. Private Sub cmmLogin_Click()
  89.     frmLogin.Show vbModal
  90. End Sub
  91.  
  92. Private Sub Form_Load()
  93.     'Imposto il valore alla variabile iConta
  94.     iConta = 5
  95.     'Visualizzo la schermata di connessione
  96. End Sub
  97.  
  98. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  99.     Dim msg As Long
  100.     msg = Me.ScaleX(X, Me.ScaleMode, vbPixels)
  101.     Select Case msg
  102.     Case WM_LBUTTONDBLCLK
  103.         frmClient.Show
  104.         frmClient.WindowState = 0
  105.         Shell_NotifyIcon NIM_DELETE, nid
  106.     End Select
  107. End Sub
  108.  
  109. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  110.     'Forzo la chiusura del programma
  111.     End
  112. End Sub
  113.  
  114. Private Sub mnuAbout_Click()
  115.     ' Visualizzo le info sul prodotto
  116.     frmAbout.Show
  117. End Sub
  118.  
  119. Private Sub mnuClientLogin_Click()
  120.     'Mostro il form Login
  121.     frmLogin.Show
  122. End Sub
  123.  
  124. 'Private Sub mnuClientAggiornamenti_Click()
  125. '    'Richiamo l'evento Click del tasto aggiorna
  126. '    cmdSegnalazioneErrori_Click
  127. 'End Sub
  128.  
  129. Private Sub mnuConnetti_Click()
  130.     'Richiamo l'evento Click del tasto connetti
  131.     cmdConnetti_Click
  132. End Sub
  133.  
  134. Private Sub mnuDimensionecarattereAumenta_Click()
  135.     txtChat.FontSize = txtChat.FontSize + 1
  136.     If txtChat.FontSize >= 25 Then
  137.         txtChat.FontSize = 10
  138.     End If
  139. End Sub
  140.  
  141. Private Sub mnuDimensionecarattereDiminuisci_Click()
  142.     txtChat.FontSize = txtChat.FontSize - 1
  143.     If txtChat.FontSize <= 9 Then
  144.         txtChat.FontSize = 10
  145.     End If
  146. End Sub
  147.  
  148. Private Sub mnuEsci_Click()
  149. Dim Answer As String
  150.     Answer = MsgBox("Sei sicuro di voler terminare il programma?", vbExclamation + vbYesNo + vbDefaultButton2, "Termina programma")
  151.     If Answer = vbYes Then
  152.         End
  153.     Else
  154.         frmClient.Show
  155.     End If
  156. End Sub
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. Private Sub mnuFileSalva_Click()
  165. Dim NomeFile As String
  166. Dim File As String
  167.     'Chiede il nome del file da salvare
  168.     NomeFile = InputBox("Inserisci il nome del file da salvare", "NOME")
  169.     File = "C:/" & NomeFile & ".txt"
  170.     Open File For Output As #1
  171.     'Salva il contenuto della TextBox Chat
  172.     Write #1, txtChat.Text
  173.     'Chiude
  174.     Close #1
  175. End Sub
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. Private Sub mnuHelpAggiornamenti_Click()
  185.     frmAggiornamenti.Show 1
  186. End Sub
  187.  
  188. Private Sub mnuHelpInfo_Click()
  189.     'Procura all'utente tutte le informazioni sulla connessione stabilita con il server
  190.     MsgBox "INFORMAZIONI CLIENT:" & vbCrLf & "Host : " & TCP.LocalHostName & vbCrLf & "IP : " & TCP.LocalIP _
  191.     & vbCrLf & "Porta : " & TCP.LocalPort & vbCrLf & "---------" & vbCrLf & "INFORMAZIONI SERVER:" _
  192.     & vbCrLf & "Host: " & TCP.RemoteHost & vbCrLf & "Host IP: " & TCP.RemoteHostIP & vbCrLf & "Porta: " _
  193.     & TCP.RemotePort, vbInformation + vbOKOnly, "INFORMAZIONI"
  194.    
  195. End Sub
  196.  
  197.  
  198.  
  199. Private Sub mnuModificaDimensionecarattereColorecarattere_Click()
  200.     dlgComune.ShowColor
  201.     txtChat.ForeColor = dlgComune.Color
  202.     End Sub
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212. Private Sub mnuTipocarattereArial_Click()
  213.     'Imposto come tipo carattere Arial
  214.     txtChat.FontName = "Arial"
  215.     mnuTipocaratterePredefinito.Checked = False
  216.     mnuTipocarattereArial.Checked = True
  217.     mnuTipocarattereTimesnewroman.Checked = False
  218. End Sub
  219.  
  220. Private Sub mnuTipocaratterePredefinito_Click()
  221.     'Imposto come tipo carattere Comic Sans MS
  222.     txtChat.FontName = "Comic Sans MS"
  223.     mnuTipocaratterePredefinito.Checked = True
  224.     mnuTipocarattereArial.Checked = False
  225.     mnuTipocarattereTimesnewroman.Checked = False
  226. End Sub
  227.  
  228. Private Sub mnuTipocarattereTimesnewroman_Click()
  229.     'Imposto come tipo carattere Times New Roman
  230.     txtChat.FontName = "Times New Roman"
  231.     mnuTipocaratterePredefinito.Checked = False
  232.     mnuTipocarattereArial.Checked = False
  233.     mnuTipocarattereTimesnewroman.Checked = True
  234. End Sub
  235.  
  236. Private Sub mnuToolPortScan_Click()
  237.     'Visualizzo il Port Scan
  238.     frmPortScan.Show 1
  239. End Sub
  240.  
  241. Private Sub mnuVisualizzaRiduci_Click()
  242.     'Riduce in traybar il form
  243.     nid.cbSize = Len(nid)
  244.     nid.hWnd = frmClient.hWnd
  245.     nid.uId = 0
  246.     nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  247.     nid.uCallBackMessage = WM_MOUSEMOVE
  248.     'nid.hIcon = cmdRiduci.Picture
  249.     Shell_NotifyIcon NIM_ADD, nid
  250.     Me.WindowState = vbMinimized
  251.     Me.Hide
  252. End Sub
  253.  
  254.  
  255.  
  256. Private Sub mnuWebErrori_Click()
  257.     X = ShellExecute(hWnd, "Open", "http://otrebor6.altervista.org/bug.html", vbNullString, vbNullString, SW_NORMAL)
  258. End Sub
  259.  
  260. Private Sub mnuWebHomepage_Click()
  261.     X = ShellExecute(hWnd, "Open", "http://otrebor6.altervista.org/chat.html", vbNullString, vbNullString, SW_NORMAL)
  262. End Sub
  263.  
  264. Private Sub mnuWebPierotofy_Click()
  265.     X = ShellExecute(hWnd, "Open", "http://www.pierotofy.it", vbNullString, vbNullString, SW_NORMAL)
  266. End Sub
  267.  
  268. Private Sub mnuWebShowIP_Click()
  269.     X = ShellExecute(hWnd, "Open", "http://www.ilmioip.it", vbNullString, vbNullString, SW_NORMAL)
  270. End Sub
  271.  
  272. Private Sub TCP_Close()
  273.     TCP.Close
  274.     PlaySound App.Path & "\ir_inter.wav", 0, SND_FILENAME Or SND_SYNC
  275.     StatusBar1.Panels(1) = "Stato: " & "Disconnesso"
  276.     cmdInvia.Enabled = False
  277.     cmdTrillo.Enabled = False
  278.     txtInvia.Enabled = False
  279.     'Azzero le textbox dei nick
  280.     txtNick.Text = ""
  281.     txtMioNick.Text = ""
  282. End Sub
  283. Private Sub TCP_Connect()
  284.     StatusBar1.Panels(1) = "Stato: " & "Connesso"
  285.     cmdInvia.Enabled = True
  286.     cmdTrillo.Enabled = True
  287.     txtInvia.Enabled = True
  288.     'Invio un suono per segnalare l'avvenuta connessione
  289.     PlaySound App.Path & "\notify.wav", 0, SND_FILENAME Or SND_SYNC
  290.     ' Richiede il Nickname personale dell'utente
  291.     ' e poi lo invia
  292.     Nick = frmLogin.txtNick
  293.     TCP.SendData "- " & Nick
  294. End Sub
  295. Private Sub TCP_DataArrival(ByVal bytesTotal As Long)
  296. Dim Data As String
  297.     TCP.GetData Data
  298.         'Quando ricevo Data la caption del form cambia
  299.         'in modo che se un utente ha ridotto ad icona il programma
  300.         'possa accorgersi del nuovo messaggio in arrivo.
  301.         'Dopodichč attivo il timer.
  302.         frmClient.Caption = "New message!"
  303.         Timer1.Enabled = True
  304.         ' Se Data č uguale a: "Hai ricevuto un trillo" allora
  305.         ' ricevi un segnale acustico
  306.         If Data = "Hai ricevuto un trillo!" Then Beep
  307.     ' Restituisce i byte ricevuti
  308.     StatusBar1.Panels(1) = "Stato: " & "In arrivo " & bytesTotal & "Bytes"
  309.     txtChat.Text = txtChat.Text & Time$ & txtNick.Text & ":" & vbCrLf & Data & vbCrLf
  310.     txtChat.SelStart = Len(txtChat.Text)
  311.     ' Se Data inizia con "- " allora vuol dire che il client
  312.     ' Ha inviato il suo Nickname, per cui il valore di Data
  313.     ' verrā salvato nella txtNick
  314.     If Left(Data, 2) = "- " Then
  315.         txtNick.Text = Data
  316.         txtMioNick.Text = Nick
  317.     End If
  318. End Sub
  319. Private Sub TCP_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  320.     TCP.Close
  321.     PlaySound App.Path & "\ir_inter.wav", 0, SND_FILENAME Or SND_SYNC
  322.     StatusBar1.Panels(1) = "Stato: " & "Errore IP" & Number
  323. End Sub
  324. Private Sub TCP_SendComplete()
  325.     StatusBar1.Panels(1) = "Nota: " & "Dati inviati con successo"
  326. End Sub
  327.  
  328. Private Sub Timer1_Timer()
  329.     'Inizialmente ho dato ad iConta il valore di 5
  330.     'Ogni secondo il suo valore diminuisce.
  331.     'Una volta raggiunto il valore 0:
  332.     'La caption del form cambia
  333.     'iConta ritorna al suo valore iniziale
  334.     'e il timer viene disattivato
  335.     iConta = iConta - 1
  336.     If iConta = 0 Then
  337.         frmClient.Caption = ""
  338.         iConta = 5
  339.         Timer1.Enabled = False
  340.     End If
  341.     'In caso la textbox non si aggiorna, ci pensa il timer
  342.     txtMioNick.Text = Nick
  343. End Sub