Results 1 to 8 of 8

Thread: [RESOLVED] Systray icon sending notifications

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Resolved [RESOLVED] Systray icon sending notifications

    I have created a small program that sets dates in the registry and then downsizes into the systray / notification area. My program looks at those dates in the registry and if one date is today, popup a notification telling the user. But what I have noticed is my program only works for the first few minutes as the date never gets updated in the app. I can double click the app and it shows but has the today's date as the date I sent it to the systray. I used .refresh() on labels and stuff but not working. How do I get the systray icon to get current date or keep refreshing itself? Once the program gets sent to the systray it starts a timer loop, mainly checking for matching dates. but as I said it appears to keep matching the date when it had when it went to the systray.

    How do I get the program to keep refreshing the date when sent down to systray?

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,792

    Re: Systray icon sending notifications

    Quote Originally Posted by phpman View Post
    I have created a small program that sets dates in the registry and then downsizes into the systray / notification area. My program looks at those dates in the registry and if one date is today, popup a notification telling the user. But what I have noticed is my program only works for the first few minutes as the date never gets updated in the app. I can double click the app and it shows but has the today's date as the date I sent it to the systray. I used .refresh() on labels and stuff but not working. How do I get the systray icon to get current date or keep refreshing itself? Once the program gets sent to the systray it starts a timer loop, mainly checking for matching dates. but as I said it appears to keep matching the date when it had when it went to the systray.

    How do I get the program to keep refreshing the date when sent down to systray?
    Is the timer being triggered when the app is minimized? How are you comparing dates?

    If possible could you post the code that you suspect isn't behaving correctly.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: Systray icon sending notifications

    sure thing

    Code:
      Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
          If Me.WindowState = FormWindowState.Minimized Then
              NotifyIcon1.Visible = True
              Me.ShowInTaskbar = False
              Me.Hide()
              Dim Todayd As Date = Date.Now.ToString("MM/d/yyyy")
              ';NotifyIcon1.BalloonTipText = "Hi from right system tray"
              'NotifyIcon1.Text = Date.Now.ToString("MM/d/yyyy H:mm:ss") ' doesn't update on each mouse over
              If My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing).length > 0 Then
                  MarchResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing)
                  Dim TDiffm = DateDiff(DateInterval.Day, Todayd, MarchResDate)
                  'Dim TDiff As TimeSpan = MarchResDate.Subtract(Today)
                  'MessageBox.Show(TDiff.Minutes.ToString)
                  If TDiffm <= 0 Then
                      NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
                      NotifyIcon1.ShowBalloonTip(500)
                      MessageBox.Show("Time to Reserve For March")
                  End If
              End If
    
              If My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing).length > 0 Then
                  MayResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing)
                  Dim TDiffmay = DateDiff(DateInterval.Day, Todayd, MayResDate)
                  ' Dim TDiffmay As TimeSpan = MayResDate.Subtract(Today)
                  ' MessageBox.Show(TDiffmay.ToString)
                  If TDiffmay <= 0 Then
                      NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
                      NotifyIcon1.ShowBalloonTip(500)
                      MessageBox.Show("Time to Reserve For May")
                  End If
              End If
    
              If My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing).length > 0 Then
                  JulyResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing)
                  Dim TDiffj = DateDiff(DateInterval.Day, Todayd, JulyResDate)
                  'Dim TDiffj As TimeSpan = JulyResDate.Subtract(Today)
                  'MessageBox.Show(Today.ToString & " - " & JulyResDate.ToString & " - " & TDiff.ToString)
                  If TDiffj <= 0 Then
                      NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
                      NotifyIcon1.ShowBalloonTip(500)
                      MessageBox.Show("Time to Reserve For July")
                  End If
              End If
    
              If My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing).length > 0 Then
                  SeptResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing)
                  Dim TDiffs = DateDiff(DateInterval.Day, Todayd, SeptResDate)
                  'Dim TDiffs As TimeSpan = SeptResDate.Subtract(Today)
                  If TDiffs <= 0 Then
                      NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
                      NotifyIcon1.ShowBalloonTip(500)
                      MessageBox.Show("Time to Reserve For Sept")
                  End If
              End If
    
              If My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing).length > 0 Then
                  NewYearResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing)
                  Dim TDiffd = DateDiff(DateInterval.Day, Todayd, NewYearResDate)
                  'Dim TDiffd As TimeSpan = NewYearResDate.Subtract(Today)
                  If TDiffd <= 0 Then
                      NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
                      NotifyIcon1.ShowBalloonTip(500)
                      MessageBox.Show("Time to Reserve For Dec")
                  End If
              End If
              'NotifyIcon1.ShowBalloonTip(500)
              Timer1.Start()
          End If
      End Sub
    
      Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          'read registry for date
          ' compare to todays date.
          Dim Todayt As Date = Date.Now.ToString("MM/d/yyyy")
    
    
          If My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing).length > 0 Then
              MarchResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing)
              Dim TDiffm = DateDiff(DateInterval.Day, Todayt, MarchResDate)
              'Dim TDiffm As TimeSpan = MarchResDate.Subtract(Today)
              'MessageBox.Show(TDiffm.Minutes.ToString)
              If TDiffm <= 0 Then
                  NotifyIcon1.BalloonTipText = "Time to Reserve For March"
                  NotifyIcon1.ShowBalloonTip(500)
                  Timer1.Stop()
                  MessageBox.Show("Time to Reserve For March")
              End If
          End If
    
          If My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing).length > 0 Then
              MayResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing)
              Dim TDiffmay = DateDiff(DateInterval.Day, Todayt, MayResDate)
              'Dim TDiffmay As TimeSpan = MayResDate.Subtract(Today)
              'MessageBox.Show(TDiffmay.ToString)
              If TDiffmay <= 0 Then
                  NotifyIcon1.BalloonTipText = "Time to Reserve For May"
                  NotifyIcon1.ShowBalloonTip(500)
                  Timer1.Stop()
                  MessageBox.Show("Time to Reserve For May")
              End If
          End If
    
          If My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing).length > 0 Then
              JulyResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing)
              Dim TDiffj = DateDiff(DateInterval.Day, Todayt, JulyResDate)
              'Dim TDiffj As TimeSpan = JulyResDate.Subtract(Today)
              'MessageBox.Show(Today.ToString & " - " & JulyResDate.ToString & " - " & TDiff.ToString)
              If TDiffj <= 0 Then
                  NotifyIcon1.BalloonTipText = "Time to Reserve For July"
                  NotifyIcon1.ShowBalloonTip(500)
                  ' Timer1.Stop()
                  MessageBox.Show("Time to Reserve For July")
              End If
          End If
    
          If My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing).length > 0 Then
              SeptResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing)
              Dim TDiffs = DateDiff(DateInterval.Day, Todayt, SeptResDate)
              'Dim TDiffs As TimeSpan = SeptResDate.Subtract(Today)
              If TDiffs <= 0 Then
                  NotifyIcon1.BalloonTipText = "Time to Reserve For Sept"
                  NotifyIcon1.ShowBalloonTip(500)
                  Timer1.Stop()
                  MessageBox.Show("Time to Reserve For Sept")
              End If
          End If
    
          If My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing).length > 0 Then
              NewYearResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing)
              Dim TDiffd = DateDiff(DateInterval.Day, Todayt, NewYearResDate)
              'Dim TDiffd As TimeSpan = NewYearResDate.Subtract(Today)
              If TDiffd <= 0 Then
                  NotifyIcon1.BalloonTipText = "Time to Reserve For Dec"
                  NotifyIcon1.ShowBalloonTip(500)
                  Timer1.Stop()
                  MessageBox.Show("Time to Reserve For Dec")
              End If
          End If
    
    
      End Sub

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,792

    Re: Systray icon sending notifications

    You might need to consider using a https://learn.microsoft.com/en-us/do...m.timers.timer timer - I have a feeling a minimized form doesn't receive any Windows Messages and therefore a WinForms Timer isn't going to update... Although I could be completely wrong about this.

    Then again the problem could be elsewhere, for starters with code like
    Code:
       Dim Todayt As Date = Date.Now.ToString("MM/d/yyyy")
    You are converting a date, to a string, and back to a date and hoping that the conversion works - if you are after the date but not the time then this should work
    Code:
           Dim today As Date = Date.Today
    I would also avoid DateDiff in VB.Net as this is just a hold over from VB6 and earlier, you can simply subtract one date from another to figure out how far apart they are.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: Systray icon sending notifications

    Thank you. I will update those piece of code. If a winform doesn't get windows messages, how does a icon in the systray able to send messages?

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,840

    Re: Systray icon sending notifications

    Quote Originally Posted by phpman View Post
    Thank you. I will update those piece of code. If a winform doesn't get windows messages, how does a icon in the systray able to send messages?
    It should still receive Timer_Tick messages when minimized

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: Systray icon sending notifications

    Thanks for the info guys. I actually fixed my problem when adding the code to this thread. I had missed a variable that I had changed and didn't update it in all the checks and it was checking on an invalid date.

    Code:
    Dim TDiffm = DateDiff(DateInterval.Day, Todayt, MarchResDate)
    I couldn't be for sure until this morning when the code ran for my test date. It did exactly as I was hoping for.

    I also changed this line

    Code:
    Dim TDiffm = DateDiff(DateInterval.Day, Todayt, MarchResDate)
    To this instead
    Code:
    Dim TDiffm As Integer = DateTime.Compare(MarchResDate, Todayt)
    and took off the ToString on the date.now. I wasn't sure if it would compare correctly if not set in the correct format is the only reason I tried it that way. Thanks for the heads up.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,840

    Re: [RESOLVED] Systray icon sending notifications

    I couldn't be for sure until this morning when the code ran for my test date. It did exactly as I was hoping for.
    You know you can manually change your system clock? Just temporarily of course

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width