Modeless Popup Window - Controls have no functionality

W

woo_derek

Hi everyone,
I'm having a bit of an issue with a popup toast window.

I have an application that starts up as a component application.
I'm doing this because I need it to run in the system tray for most of
the time. And of course, if you double click the icon, a main form
shows up.
My application shows status windows as toast popups, just like
Outlook does for when you get a new mail message.
I first had a problem with the controls not showing up properly.
They were showing up as black rectangles. I read an earlier post that
solved that problem for me. I just needed to call Application.DoEvents
after the Form.Show call.
http://groups.google.com/group/micr...on+form+vb+.net&rnum=1&hl=en#7d007dfc745d0c58
I have a Timer object running that will fire off this form when it
needs to notify the user of the status. The form will come up and
display, but whenever I put my mouse over it, I end up seeing the
Hourglass cursor (Wait cursor). I don't explicitly set the cursor.
Also, I have a link label on the popup form and can't click it, because
of the wait cursor. Any ideas how I can get around this. I have some
code below to show you what I'm doing. This code will pretty much give
you a gist of what I'm doing. I have a message loop running with a
timer. The timer elapses, then if I need to show the status window, I
show it. The status window displays, but I have no functionality of
that status window. It appears that it's on a locked thread. Is there
anyway to get it on another thread? Thanks to anyone who could help.

<System.STAThread()> _
Public Shared Sub Main()
Dim myCmpApp As cmpMain
'Run the message loop
myCmpApp = New cmpMain
System.Windows.Forms.Application.Run()
myCmpApp.Dispose()
End Sub

Private Sub tmrPollQueue_Elapsed(ByVal sender As System.Object, ByVal e
As System.Timers.ElapsedEventArgs) Handles tmrPollQueue.Elapsed
'Stop the timer during the loading period
Me.tmrPollQueue.Stop()

'I run some logic here that determine whether to show the
status window
If showWindow Then
Me.ShowNotificationWindow
End If

'Now that we're done, restart the timer
Me.tmrPollQueue.Start()
End Sub

Private Sub ShowNotificationWindow()
'Pop up the notification window
Dim f As New frmNotify
'Set the location of the form
f.Left = Screen.PrimaryScreen.WorkingArea.Right - f.Width
f.Top = Screen.PrimaryScreen.WorkingArea.Bottom - f.Height
f.Show()
Application.DoEvents()
End Sub

Derek Woo
 
W

woo_derek

In case any of you run into this problem, I figured out how to do it.
Since the standard application message loop runs on a single thread,
firing up another form causes that form to run on that same thread.
This was the problem. I think this only occurs because of the fact the
notification is tied up by the timer. I think this blocks the threaad
from running smoothly. I needed to create a new thread and then run a
new message loop for the notification form. It was a relatively simple
line of code to do.

Dim aThread As Threading.Thread

If showWindow Then
aThread = New Threading.Thread(AddressOf ShowNotificationWindow)
aThread.Start()
End If

That had everything work right. I gained complete functionality of the
notification form without suffering any other type of functionality
loss. In fact, I think the timer runs better too because of this
solution.

Another note, I no longer needed the Application.DoEvents() in the
ShowNotificationWindow function anymore since it runs on a completely
different thread.
The only difference in the ShowNotificationWindow function is that I no
longer call f.Show() but rather, I call Application.Run(f) to start a
brand new message loop.

Hint: I can use the thread and not worry about disposing it because I
know that the notification window closes on its own, therefore
disposing of that application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top