Question Notify Icon Balloon Tip To Other Windows User

smallo92

New member
Joined
Sep 28, 2014
Messages
3
Programming Experience
Beginner
I am making a User to User chat system. We have a server that a fair few users access remotely from different sites.

Because everyone's on the one PC with the same IP I made my program read and write to text files to store the chat logs and receive the messages. (Timer to read text file) So it may make this a bit harder :/


So everyone will be running this program from different users at once. So I want to be able to make a Notify Icon Balloon Tip pop up on a specified users computer. Is it possible?
So this is the cource code for my program. So it can show you's how it's done. It's pretty basic.


VB.NET:
Imports System.ComponentModel
Imports Microsoft.Win32
Imports System.IO

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim FILE_NAME As String = "Z:\Sunland Messenger Chat Logs\" & System.Environment.UserName & ListBox1.SelectedItem & ".txt"
    Dim FILE_NAME2 As String = "Z:\Sunland Messenger Chat Logs\" & ListBox1.SelectedItem & System.Environment.UserName & ".txt"
    If ListBox1.SelectedIndex = -1 Then
        MessageBox.Show("Please select a user to message first.")
    Else
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
            objWriter.Write(vbNewLine & System.Environment.UserName & " Says: " & TextBox1.Text)
            objWriter.Close()
            TextBox1.Clear()
        ElseIf System.IO.File.Exists(FILE_NAME2) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME2, True)
            objWriter.Write(vbNewLine & System.Environment.UserName & " Says: " & TextBox1.Text)
            objWriter.Close()
            TextBox1.Clear()
        Else
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
            objWriter.Write(System.Environment.UserName & " Says: " & TextBox1.Text)
            objWriter.Close()
            TextBox1.Clear()
        End If
    End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
    For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
        Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
            Try
                Dim Valid As Integer = DirectCast(SubKey.GetValue("RunLogonScriptSync"), Integer)
                Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
                Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
                If _Users.ToLower.Contains("\users\") Then
                    If _Username = "Administrator" Then
                    Else
                        If _Username = "Toby" Then
                            ListBox1.Items.Add("Admin")
                        End If
                        ListBox1.Items.Add(_Username)
                        ListBox1.Items.Remove("Toby")
                        ListBox1.Items.Remove(System.Environment.UserName)
                    End If
                End If
            Catch ex As Exception
            End Try
        End Using
    Next
    NotifyIcon1.Visible = True
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    e.Cancel = True
    Me.WindowState = FormWindowState.Minimized
    Me.Hide()
End Sub

Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
    Me.Show()
    Me.WindowState = FormWindowState.Normal
End Sub

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
    NotifyIcon1.Visible = False
    Application.Exit()
    End
End Sub

Private Sub ExitToolStripMenuItem1_Click_1(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem1.Click
    NotifyIcon1.Visible = False
    Application.Exit()
    End
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    If ListBox1.SelectedIndex = -1 Then
    Else
        If File.Exists("Z:\Sunland Messenger Chat Logs\" & System.Environment.UserName & ListBox1.SelectedItem & ".txt") Then
            Dim strFile As String = "Z:\Sunland Messenger Chat Logs\" & System.Environment.UserName & ListBox1.SelectedItem & ".txt"
            Dim sr As New IO.StreamReader(strFile)
            TextBox2.Text = sr.ReadToEnd()
            sr.Close()
            TextBox2.Select(TextBox2.TextLength, 0)
            TextBox2.ScrollToCaret()
        ElseIf File.Exists("Z:\Sunland Messenger Chat Logs\" & ListBox1.SelectedItem & System.Environment.UserName & ".txt") Then
            Dim strFile As String = "Z:\Sunland Messenger Chat Logs\" & ListBox1.SelectedItem & System.Environment.UserName & ".txt"
            Dim sr As New IO.StreamReader(strFile)
            TextBox2.Text = sr.ReadToEnd()
            sr.Close()
            TextBox2.Select(TextBox2.TextLength, 0)
            TextBox2.ScrollToCaret()
        Else
            TextBox2.Text = ""
        End If
    End If
End Sub

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox1.KeyDown
    If e.KeyCode = Keys.Enter Then
        Button1.PerformClick()
    End If
End Sub

End Class
 
As you can see form the code above there is already a NotifyIcon. What I'm asking is if I can display the Balloon Tip to different users running different instances of the same program.
 
I didn't actually scroll your code so I didn't see that there was a NotifyIcon, but I do now see that there is no call to ShowBalloonTip. Each application has to show its own balloons. Each instance can send messages to other instances in any number of ways. The balloon has got nothing to do with that. When an instance of the application receives a message, it's up to it what it does with it. If you want a balloon then the app should display a balloon, but each instance shows its own balloons.

Personally, I would absolutely not use files for the communication but rather create a server as a Windows service. Each client can connect to the server and messages can be sent to the server and received from it. If you want to send a message to a specific client you send the message to the server and tell it what client to send it on to.
 
I can't do it that way. Because we are all located on the one server and all have the same IP. So I can't determine who's who.
 
Of course you can determine who's who. Each client makes a distinct connection to the server. Even if there's nothing else to distinguish them, each client can tell the server who they are and the server then stores the connections in a Dictionary keyed on that.

You should check this out:

Asynchronous TcpListener & TcpClient

That uses a WinForms app for the server for simplicity but it would be done for real with a service. The server can send a message to a specific client and it could easily be extended so that the server sent each client a list of all clients and any client could then tell the server to send a message to any other client. Presumably each user logs on with their own account so the application could automatically get the user name and send that to the server to identify each client.

If you want to stick with your (rather dodgy) method of using text files then it's still relatively easy. You could have a root folder for all the text files and each client creates its own folder under that when it starts up. If you want to send a message to all clients then you could save a file in the root folder or save it under a client's own folder to send it to them only. Each client can easily see who else is "online" by checking what folders exist and each client simply deletes their own folder when they exit.
 
Back
Top