|
-
Sep 29th, 2005, 12:57 AM
#1
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
-
Sep 29th, 2005, 08:27 AM
#2
New Member
Re: Create "Toast" Popup Notification Windows
Wow, this is great, thanks!
-
Sep 29th, 2005, 09:59 PM
#3
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.
-
Sep 29th, 2005, 10:40 PM
#4
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.
-
Sep 29th, 2005, 11:34 PM
#5
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.
-
Sep 30th, 2005, 07:19 AM
#6
Frenzied Member
Re: Create "Toast" Popup Notification Windows
-
Sep 30th, 2005, 08:49 AM
#7
Frenzied Member
-
Oct 4th, 2005, 07:18 AM
#8
Frenzied Member
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?
-
Oct 4th, 2005, 07:27 AM
#9
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.
-
Oct 4th, 2005, 07:46 AM
#10
Frenzied Member
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.
-
Oct 4th, 2005, 07:59 AM
#11
Frenzied Member
Re: Create "Toast" Popup Notification Windows
Just tried it on a XP SP2 and it worked ok.
-
Oct 4th, 2005, 08:14 AM
#12
Member
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....
-
Oct 4th, 2005, 08:20 AM
#13
Member
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.
-
Oct 4th, 2005, 08:43 AM
#14
Frenzied Member
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.
-
Oct 4th, 2005, 09:16 AM
#15
Re: Create "Toast" Popup Notification Windows
And all was well with the world. Good stuff folks. It would appear that updates are good.
-
Oct 4th, 2005, 10:46 AM
#16
Hyperactive Member
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.
-
Oct 4th, 2005, 07:20 PM
#17
Re: Create "Toast" Popup Notification Windows
Doesn't the SP1 comes with the installation of VS2003?
-
Oct 4th, 2005, 07:31 PM
#18
Re: Create "Toast" Popup Notification Windows
 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...
-
Oct 4th, 2005, 07:36 PM
#19
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...
-
Oct 6th, 2005, 07:45 PM
#20
Re: Create "Toast" Popup Notification Windows
 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.
-
Oct 6th, 2005, 07:55 PM
#21
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.
-
Nov 30th, 2007, 01:33 PM
#22
Addicted Member
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:
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newToastThread As New Threading.Thread(AddressOf ToastShow)
newToastThread.Start()
End Sub
Private Sub ToastShow()
Dim toasted As New ToastForm(4000, "Hello, we have a new Popup!")
toasted.Show()
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:
Public Delegate Sub openFormInvokeDelegate(ByVal value As Integer)
Public Class ToastForm
'...
Private Sub ToastForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Display the form just above the system tray.
Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width - 5, _
Screen.PrimaryScreen.WorkingArea.Height - Me.Height - 5)
'Move each open form upwards to make room for this one.
For Each openForm As ToastForm In ToastForm.openForms
'openForm.Top -= Me.Height + 5
openForm.SetTopInvoked(Me.Height + 5)
Next
'Add this form from the open form list.
ToastForm.openForms.Add(Me)
'Start counting down the form's liftime.
Me.lifeTimer.Start()
End Sub
Public Sub SetTopInvoked(ByVal value As Integer)
If Me.InvokeRequired Then
Me.Invoke(New openFormInvokeDelegate(AddressOf SetTopInvoked), value)
Else
Me.Top = Me.Top - value
End If
End Sub
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:
Public Delegate Sub FormCloseDelegate()
Public Class ToastForm
'...
'...
Public Sub FormClose()
If Me.InvokeRequired Then
Me.Invoke(New FormCloseDelegate(AddressOf FormClose)) 'Throws NullReferenceException: "Object reference not set to an instance of an object"
Else
Me.Close()
End If
End Sub
End Class
Even Threading.Timer using the TimerCallback throws the same exception.
VB Code:
Private LifeTimerCallback as New TimerCallback(AddressOf lifeTimer_CallbackMethod)
Private Sub ToastForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'...
Me.lifetimer = New Threading.Timer(Me.lifeTimerCallback, Nothing, lifetime, 0)
End Sub
'...
Private Sub lifeTimer_CallbackMethod(obj as Object)
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."
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|