Results 1 to 22 of 22

Thread: Create "Toast" Popup Notification Windows

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Create "Toast" Popup Notification Windows

    For those who are interested, I've added a demo class to my Animated Forms thread in the CodeBank. It use the FormAnimator class to create a popup notification like various apps use, including MSN Messenger I believe.

    http://www.vbforums.com/showthread.php?t=351757
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2
    New Member
    Join Date
    Sep 2005
    Location
    York, PA (work in Baltimore, MD)
    Posts
    5

    Re: Create "Toast" Popup Notification Windows

    Wow, this is great, thanks!

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    I've updated the ToastForm class so that it now will not receive focus when it is displayed. It will still receive focus if you click on it though. You can get the new ToastForm class from the Codebank.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    I've updated the ToastForm class so that existing windows will move up the screen to make way for new ones so that they are not covered.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    I've updated the ToastForm class so that it stacks properly if the Height is changed and/or multiple forms are opened with different lifetimes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Create "Toast" Popup Notification Windows

    This is brilliant.

  7. #7
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up

    I had code to do this in VB6, so it's nice to be able to do it again in .NET. Good stuff, works nice.
    ~Peter


  8. #8
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Create "Toast" Popup Notification Windows

    Damn, I used both the toast effect and the form animator in my app and when installed on my pc it works fine. I have installed it on another PC it it wont work saying the ToastForm is causing an unhandled exception. Can you think of any windows settings updates etc that the Toast and Animation Classes use that could be causing this problem on different machines?

  9. #9

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    I've been having a discussion with dee-u on the CodeBank thread on just that topic. I don't have any real idea what the issue could be. See dee-u's stack trace to see how deep in the Framework the actual exception is thrown. He's having issues on an XP machine that's only at SP1. What about the machine's you're trying to use? My own is SP2 and I've never had an issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Create "Toast" Popup Notification Windows

    My own machine is running Windows 2000 (No Problem), the problem machine windows server 2003. Just installing the latest SP see if that makes a difference.
    Last edited by FishGuy; Oct 4th, 2005 at 08:04 AM.

  11. #11
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Create "Toast" Popup Notification Windows

    Just tried it on a XP SP2 and it worked ok.

  12. #12
    Member
    Join Date
    Oct 2005
    Location
    Plymouth, UK
    Posts
    55

    Re: Create "Toast" Popup Notification Windows

    XP SP2 here, VB.NET 2.0.5 (2005). No problems.

    I'm no expert, but may I politely suggest that if it works on some systems and not others, and that the exception is thrown so far down in the framework, that there are probably DLL variations in between platforms (as you've already guessed).

    Some of those variations probably contain bugs... I don't see how you could fix it as it appears to me to be a problem with the underlying systems. Again, the fact that it works on some systems and not others would suggest that to be the case.

    It also seems silly that an "End If" statement is throwing the exception....

  13. #13
    Member
    Join Date
    Oct 2005
    Location
    Plymouth, UK
    Posts
    55

    Re: Create "Toast" Popup Notification Windows

    Maybe something to do with Labels?
    http://www.desktopsidebar.com/forums...showtopic=3118
    http://weblogs.asp.net/justin_rogers...21/189652.aspx

    Another bloke here suggests it has something to do with the framework version:
    http://www.datadynamics.com/ShowPost.aspx?PostID=72180
    As it turns out, my version of the .Net framework was 'only' 1.1.4322, not 1.1.4322 SP1 (must be fairly new ?!). After I installed the SP1 for the .Net framework, the exception vanished.

  14. #14
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Create "Toast" Popup Notification Windows

    Installing the latest Service packs on the Windows 2003 server fixed the problem. I imagine it is the same for every other platform, just a case of getting the latest updates.

  15. #15

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    And all was well with the world. Good stuff folks. It would appear that updates are good.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    Hyperactive Member
    Join Date
    May 2001
    Posts
    306

    Re: Create "Toast" Popup Notification Windows

    All I did to fix the problem was install .Net Framework 1.1 SP1. I originally had Framework 1.1.4322 and upgrading to 1.1.4322 SP1 fixed the problem.

    This might be a quicker fix then installing the latest Windows SP.

  17. #17
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Create "Toast" Popup Notification Windows

    Doesn't the SP1 comes with the installation of VS2003?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  18. #18

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    Quote Originally Posted by dee-u
    Doesn't the SP1 comes with the installation of VS2003?
    That depends how old your copy of VS is. I had to apply SP1. Hey dee-u, there's this cool site called Windows Update...
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Create "Toast" Popup Notification Windows

    Actually I have already downloaded the SP1 since there was this time when I can't make my app run in this certain machine but it could run in my machine (both are XP) and I tried installing the SP1 in that machine wherein my app couldn't run and fortunately it was able to run after the installation, hence my thinking is I already have the SP1, somebody told me that VS2003 already comes with the SP1... I'll search and post the link here...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  20. #20
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Create "Toast" Popup Notification Windows

    Quote Originally Posted by dee-u
    Actually I have already downloaded the SP1 since there was this time when I can't make my app run in this certain machine but it could run in my machine (both are XP) and I tried installing the SP1 in that machine wherein my app couldn't run and fortunately it was able to run after the installation, hence my thinking is I already have the SP1, somebody told me that VS2003 already comes with the SP1... I'll search and post the link here...
    Sorry, I was actually referring to .Net SDK... Link

    It's working now, I installed the SP1 in my development machine and it worked...
    Last edited by dee-u; Oct 6th, 2005 at 07:59 PM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  21. #21

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Create "Toast" Popup Notification Windows

    Thanks dee-u. From what you and others, particularly FishGuy, have experienced it would seem that there is a bug in version 1.1 of the Framework, which was fixed in SP1, that may affect the AnimateWindow API. I'll add this information to the first post in the Codebank so all can see. Thanks for sharing your experience folks.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  22. #22
    Addicted Member garyjohn_2000's Avatar
    Join Date
    Apr 2005
    Location
    Timbaland
    Posts
    243

    Re: Create "Toast" Popup Notification Windows

    [Sorry for double posting, I have already posted on the CodeBank thread for ToastForm. I thought maybe posting in the VB.NET forum may attract your attention jmc!]

    Great work on the toastform class jmc!


    But theres a little problem that i have encountered using this toastform solution in VBExpress 2005 (.NET 2.0).

    All seems to be well till I declare and Show the form from a new thread.

    VB Code:
    1. Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim newToastThread As New Threading.Thread(AddressOf ToastShow)
    3.     newToastThread.Start()
    4. End Sub
    5.  
    6. Private Sub ToastShow()
    7.     Dim toasted As New ToastForm(4000, "Hello, we have a new Popup!")
    8.     toasted.Show()
    9. End Sub

    After toasted.Show(), the form is visible till the duration of the animation, but after that the form simply disappears. I even tried to debug it while setting a breakpoint at Me.Close() and lifeTimer.Tick, but the breakpoints are never hit! . I have simply no idea where the form goes after it disappears. Two things I know for sure: The form never closes itself,and the lifeTimer.Tick event doesn't fire.

    Secondly, if I click the Button1 again to see if the Toastform stacks, then the compiler throws out an InvalidOperationException at "openForm.Top -= Me.Height + 5" @ Line 178 ToastForm.vb : "Cross-thread operation not valid: Control 'ToastForm' accessed from a thread other than the thread it was created on." Delegation seems to be the solution for this. So I tried:

    VB Code:
    1. Public Delegate Sub openFormInvokeDelegate(ByVal value As Integer)
    2.  
    3. Public Class ToastForm
    4.    '...
    5.  
    6.     Private Sub ToastForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         'Display the form just above the system tray.
    8.         Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width - 5, _
    9.                                 Screen.PrimaryScreen.WorkingArea.Height - Me.Height - 5)
    10.  
    11.         'Move each open form upwards to make room for this one.
    12.         For Each openForm As ToastForm In ToastForm.openForms
    13.             'openForm.Top -= Me.Height + 5
    14.             openForm.SetTopInvoked(Me.Height + 5)
    15.         Next
    16.  
    17.         'Add this form from the open form list.
    18.         ToastForm.openForms.Add(Me)
    19.  
    20.         'Start counting down the form's liftime.
    21.         Me.lifeTimer.Start()
    22.     End Sub
    23.  
    24.     Public Sub SetTopInvoked(ByVal value As Integer)
    25.         If Me.InvokeRequired Then
    26.             Me.Invoke(New openFormInvokeDelegate(AddressOf SetTopInvoked), value)
    27.         Else
    28.             Me.Top = Me.Top - value
    29.         End If
    30.     End Sub
    31. End Class
    Now that throws me a NullReferenceException: "Object reference not set to instance of an object."

    Some threading issue perhaps? or the Timer?

    It seems that the Windows.Forms.Timer sticks to the UI thread only. So, the Timer.Tick event may not fire at all.

    But on the other hand, the System.Timers.Timer is said to raise the Elapsed event on new threads from the ThreadPool every time it is raised. So, it throws an InvalidOperationException: "Cross-thread operation not valid: Control 'PopupNotifierForm' accessed from a thread other than the thread it was created on.", citing the (cross-thread) call to "Me.Close()" as invalid. Delegation didn't help either. That throws a NullReferenceException: "Object reference not set to an instance of an object".

    This is the code I am trying to delegate the Me.Close method.
    VB Code:
    1. Public Delegate Sub FormCloseDelegate()
    2. Public Class ToastForm
    3. '...
    4. '...
    5.     Public Sub FormClose()
    6.         If Me.InvokeRequired Then
    7.             Me.Invoke(New FormCloseDelegate(AddressOf FormClose)) 'Throws NullReferenceException: "Object reference not set to an instance of an object"
    8.         Else
    9.             Me.Close()
    10.         End If
    11.     End Sub
    12. End Class


    Even Threading.Timer using the TimerCallback throws the same exception.
    VB Code:
    1. Private LifeTimerCallback as New TimerCallback(AddressOf lifeTimer_CallbackMethod)
    2.  
    3. Private Sub ToastForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. '...
    5.     Me.lifetimer = New Threading.Timer(Me.lifeTimerCallback, Nothing, lifetime, 0)
    6. End Sub
    7.  
    8. '...
    9.  
    10. Private Sub lifeTimer_CallbackMethod(obj as Object)
    11.     Me.FormClose()    'If I use Me.Close instead, it throws a InvalidOperationException: "Cross-thread operation not valid: Control 'PopupNotifierForm' accessed from a thread other than the thread it was created on."
    12. End Sub

    I must be doing something wrong or is there some other way to make this work? Is there no way to make the form work normally if instantiated and called from new threads?

    Any help will be truly appreciated.
    And jmc, THANX ONCE AGAIN FOR THIS BEAUTIFUL SOLUTION!!!


    Anyone who has never made a mistake has never tried anything new. - Einstein
    Peace!

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