What I want is a small notification message that is shown in the lower right corner when there are any messages to be shown. If there are none the notification message will not be shown. The notification message should not steal focus or block the main application.
What I have is an application that runs a Task as a kind of messageservice. This application contains multiple dialogs that opens as modal dialogs.
When a message arrives to the application it is added to a observable list. This fires an eventhandler in the form showing the notification message and it is redrawn to show the first item in the list.
When a message is read/closed it is removed from the list which fires the event again and the form is updated with the information from the first item in the list.
If the list is empty the form is hidden.
My problem is that if i get a message and the notification message form is shown, and before I close it a modal dialog is opened in the main application, my form with the notification message is still on top of everything, even the modal dialog, but it’s not clickable.
I’ve searched and read several forums for an answer but haven’t been able to come up with an answer.
A small testapplication that simulates this behaviour can be found at Github.
https://github.com/Oneleg/NotificationMessage
Some fast info:
The NotificationMessage form has:
- FormBorderStyle = None
- Topmost = False
- Is shown with Show()
- Overloads ShowWithoutActivation()
- Overloads CreateParams with WS_EX_NOACTIVATE WS_EX_TOOLWINDOW WS_EX_TOPMOST
Any ideas on how I could solve this?
Looks like I’ll be able to answer my own question.
The answer is to create the NotificationMessage as an application withs it’s own messagepump.
After some modifications my Main now looks like this:
And the NotificationMessage looks like this:
I now have a notification message that is only visible when there are any messages to show, doesn’t steal focus when a new message arrives, is always on top and is clickable even after a modal form is opened in the main application.