Click here to Skip to main content
13,597,485 members
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 28 Mar 2001

Screen Mate

, 28 Mar 2001
Rate this:
Please Sign up or sign in to vote.
Windows 2000 introduces a new extended window style bit WS_EX_LAYERED that can significantly improve performance and add great visual effects.
<!-- Download Links --> 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 .


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.


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


About the Author

Web Developer
United States United States
just like to sh*t all the time now!!!!!dont know why..

You may also be interested in...

Comments and Discussions

GeneralDirectX Pin
nirishere31-Aug-09 5:35
membernirishere31-Aug-09 5:35 
GeneralUpdateLayeredWindow !!! Pin
xela11-Sep-03 21:00
memberxela11-Sep-03 21:00 
GeneralNext challenge... Pin
OferZad25-Apr-03 3:41
memberOferZad25-Apr-03 3:41 
GeneralSetLayered... don't work with child windows Pin
Nicolas Viganotti29-Jan-03 19:44
sussNicolas Viganotti29-Jan-03 19:44 
GeneralNice Example Pin
Anonymous3-May-01 1:17
memberAnonymous3-May-01 1:17 
GeneralCool Example!! Pin
Peter Yee2-Apr-01 17:04
memberPeter Yee2-Apr-01 17:04 
Generalper pixel alpha Pin
Maximilian Hänel30-Mar-01 0:21
memberMaximilian Hänel30-Mar-01 0:21 
GeneralComilition errors Pin
Anonymous29-Mar-01 23:41
memberAnonymous29-Mar-01 23:41 
GeneralRe: Comilition errors Pin
Robert Baumann31-Mar-01 1:54
memberRobert Baumann31-Mar-01 1:54 
GeneralRe: Comilition errors Pin
Anonymous1-Apr-01 2:01
memberAnonymous1-Apr-01 2:01 
GeneralRe: Comilition errors Pin
David Hamel2-Apr-01 6:50
memberDavid Hamel2-Apr-01 6:50 
GeneralRe: Comilition errors Pin
Anonymous2-Apr-01 17:01
memberAnonymous2-Apr-01 17:01 
GeneralRe: Comilition errors Pin
Kev Ward28-Jan-02 2:13
memberKev Ward28-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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02-2016 | 2.8.180621.3 | Last Updated 29 Mar 2001
Article Copyright 2001 by Hirosh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid