Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / MFC
Article

Screen Mate

Rate me:
Please Sign up or sign in to vote.
3.00/5 (10 votes)
28 Mar 20013 min read 151.2K   2.5K   34   13
Windows 2000 introduces a new extended window style bit WS_EX_LAYERED that can significantly improve performance and add great visual effects.
Below is some introductory information from MSDN

Layered Windows

Windows 2000 introduces a new extended window style bit: WS_EX_LAYERED. When used properly, it can significantly improve performance and visual effects for a window that has a complex shape, animates, or wishes to use alpha-blending effects. The full implementation of layered windows was publicly available for the first time in Windows 2000 Beta 3.

Windows appear as rectangles on the screen clipped by other windows. For a window in an application to look like a circle, it's not enough for the application to simply paint a window as a circle; the system will continue to hit test this window as a rectangle and windows underneath this window will still be clipped by the window's rectangle. So, the window will look and behave like a gray rectangle with a circle in the middle.

Some applications might take a snapshot of the visual bits underneath the window before it was actually shown and later compose those bits with the window bits. This approach doesn't quite work in a multiprocess, multitasking environment, because other windows can paint underneath this window. The application has no way of knowing when such painting occurs or how to somehow retrieve the newly painted bits underneath.

Using Layered Windows

For any layering to take place, the WS_EX_LAYERED bit needs to be set, either at window creation time or by calling SetWindowLong with GWL_EXSTYLE. Next, the developer has a choice: Use the existing Microsoft Win32® painting paradigm by responding to WM_PAINT and/or other paint messages, or make use of a more powerful layering API, UpdateLayeredWindow.

To use UpdateLayeredWindow, the visual bits for a layered window have to be rendered into a compatible bitmap. Then, via a compatible GDI Device Context, the bitmap is provided to the UpdateLayeredWindow API, along with the desired color-key and alpha-blend information. The bitmap can also contain per-pixel alpha information.

Note that when using UpdateLayeredWindow the application doesn't need to respond to WM_PAINT or other painting messages, because it has already provided the visual representation for the window and the system will take care of storing that image, composing it, and rendering it on the screen. UpdateLayeredWindow is quite powerful, but it often requires modifying the way an existing Win32 application draws.

The second way to use layered windows is to continue using the Win32 painting paradigm, but allowing the system to redirect all the drawing for the layered window and its children into an off-screen bitmap. This can be done by calling SetLayeredWindowAttributes with the desired constant alpha value and/or the color-key. Once the API has been called, the system will start redirecting all drawing by the window and automatically apply the specified effects.

Hit Testing

Hit testing of a layered window is based on the shape and transparency of the window. This means that the areas of the window that are color-keyed or whose alpha value is zero will let the mouse messages through.

If the layered window has the WS_EX_TRANSPARENT extended window style, the shape of the layered window will be ignored and the mouse events will be passed to the other windows underneath the layered window

Screen Mate

This Screen Mate is a simple program using the new feature Layered Windows. We can develop very easy and more efficient Screen Mates using this new feature than Windows Regions. I am only a student in VC++ .Anybody wants any  modification in this program i am ready to accept the modifications .

Conclusion

Layered windows present an efficient way to add transparency and translucency to top-level windows. They enable developers to easily incorporate modern UI and cool transition effects into new as well as already existing applications.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
just like to sh*t all the time now!!!!!dont know why..
Homepage- www.hirosh.tk

Comments and Discussions

 
GeneralDirectX Pin
nirishere31-Aug-09 5:35
nirishere31-Aug-09 5:35 
GeneralUpdateLayeredWindow !!! Pin
xela11-Sep-03 21:00
xela11-Sep-03 21:00 
GeneralNext challenge... Pin
OferZad25-Apr-03 3:41
OferZad25-Apr-03 3:41 
GeneralSetLayered... don't work with child windows Pin
NiVigator29-Jan-03 19:44
NiVigator29-Jan-03 19:44 
GeneralNice Example Pin
3-May-01 1:17
suss3-May-01 1:17 
GeneralCool Example!! Pin
Peter Yee2-Apr-01 17:04
Peter Yee2-Apr-01 17:04 
Generalper pixel alpha Pin
Maximilian Hänel30-Mar-01 0:21
Maximilian Hänel30-Mar-01 0:21 
GeneralComilition errors Pin
29-Mar-01 23:41
suss29-Mar-01 23:41 
--------------------Configuration: haiii - Win32 Release--------------------
Linking...
nafxcw.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcw.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Release/haiii.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

haiii.exe - 3 error(s), 0 warning(s)
Cry | :(( Cry | :((
GeneralRe: Comilition errors Pin
Robert Baumann31-Mar-01 1:54
Robert Baumann31-Mar-01 1:54 
GeneralRe: Comilition errors Pin
1-Apr-01 2:01
suss1-Apr-01 2:01 
GeneralRe: Comilition errors Pin
2-Apr-01 6:50
suss2-Apr-01 6:50 
GeneralRe: Comilition errors Pin
2-Apr-01 17:01
suss2-Apr-01 17:01 
GeneralRe: Comilition errors Pin
28-Jan-02 2:13
suss28-Jan-02 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.