|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic Projects TransparentBlt: Simulating Microsoft's 'Windows Messenger' Notifications Step 1: Introduction and Layout |
|
Posted: | Wednesday August 14, 2002 |
Updated: | Monday December 26, 2011 |
Applies to: | VB4-32, VB5, VB6 |
Developed with: | VB6, Windows XP |
OS restrictions: | None |
Author: | Pierre Alexis, VBnet - Randy Birch |
Other project pages: |
Step 1: Introduction and Layout Step 2: Building the Calling Form Step 3: Building the Notification Form |
Prerequisites |
None. |
|
From
the VBnet mailbag: A couple of months ago I received an email from
a frequent site and newsgroup visitor indicating he had developed an application
that displayed a Microsoft Windows Messenger-style notification window (msim).
The functionality was pretty cool, and so the code to create the demo app is
republished here with the author's permission, and with a few enhancements over
the original code. For those unfamiliar with the msim notification window, when msim wants to alert that perhaps new email or a contact has come on-line, (on a system with the taskbar at the screen bottom) a notification sound is played and a small rectangular window slides up from behind the systray with the announcement. In some cases the clicking the message invokes an action, and in all cases, when the message had displayed for a few seconds, it slides back behind the systray out of view. (I use the taskbar in the default bottom position so have no idea whether msim notifications always appear at the bottom-right of the screen, or whether they always appear at the systray position). To be 'different', this demo does not position the notification at the lower right corner but rather appears from the screen top, either right-aligned or left-aligned to the edge of the screen through a customizable setting in the project. But because the notification window calculates its display position after acquiring the work area of the screen, as coded the notification window not be obscured by the taskbar if you position it at the top of the window. And unlike the real msim notification window that appears to slide into view, this version unrolls / rolls to reveal and hide itself. The majority of the work takes place in the small notification form - the larger form shown just grabs the notification sound to use from the registry and calls the notification form's ShowMessage routine. The four illustrations above show:
Using a standard label the message displayed is set at runtime and can contain any text, although its length is naturally limited by the size of the notification window. But the notification form can have a gradient background of any colour as well display a bitmap (complete with transparency) or an icon of your choosing. A copy of the msim bitmap is provided below. Here are the key code execution steps of the notification window:
Up to this point a window of 0 height is on screen. Now a single timer takes over to perform the actual reveal/wait/hide:
Because we want to perform an action should any part of the form be clicked, and because we want any mouse movement over the form or the label to cause the label to respond like a hyperlink, the MouseMove event of the label is routed to the MouseMove event of the form, which contains the code to highlight the label. SetCapture / ReleaseCapture ensures that when the cursor leaves the form, the hyperlink is restored to its normal non-hyperlink colour. The form's Form_MouseUp event (or Form_MouseDown if preferred) is used to detect clicks on the label or on the form itself. It would be in this event you would either execute the command desired, or set a return value the calling form could use to invoke a particular action. And regardless of the notify_mode, clicking the label or form instantly dismisses the dialog. This demo shows several interesting techniques:
VBnet thanks Pierre Alexis for providing the basis for this interesting code, and Pierre in turn extends his appreciation to François Picalausa and those in the newsgroups for helping him work through some of the issues in developing his original routine. The layout form below shows the names of the respective controls you must add and their relative positions on the forms. First form is the calling form, while the second is the actual notify window. This project is divided into three pages ... this page with the form design, the second with the calling form's code, and the third containing the actual notify window code. Properties for the calling form can use the default names, including the default form name Form1. Into Image1 - a placeholder for the image in the notify window - load either the image provided below or another of your choosing. Note that the code for this demo sets the transparency colour to the red shown in the bitmap, so if another bitmap is used you will have to adjust the transparency colour appropriately. (You can use GetPixel to retrieve the precise colour of a point within the image if desired).
Properties for the notification form need some design-time adjusting. There is no titlebar, so set the Control Box to False, remove any Caption string, and set the form style to 3 - fixed dialog. ScaleMode can remain as the default Twips. Name the form frmNotify.
|
|
Comments |
Save the project and move on to Step 2: Building the Calling Form |
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |