Click here to Skip to main content
Click here to Skip to main content
Go to top

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 .

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

Share

About the Author

Hirosh
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 Pinmembernirishere31-Aug-09 5:35 
Could you accomplish the same effect using directx ? click-thru that is
GeneralUpdateLayeredWindow !!! Pinmemberxela11-Sep-03 21:00 
GeneralNext challenge... PinmemberOferZad25-Apr-03 3:41 
GeneralSetLayered... don't work with child windows PinsussNicolas Viganotti29-Jan-03 19:44 
GeneralNice Example PinmemberAnonymous3-May-01 1:17 
GeneralCool Example!! PinmemberPeter Yee2-Apr-01 17:04 
Generalper pixel alpha PinmemberMaximilian Hänel30-Mar-01 0:21 
GeneralComilition errors PinmemberAnonymous29-Mar-01 23:41 
GeneralRe: Comilition errors PinmemberRobert Baumann31-Mar-01 1:54 
GeneralRe: Comilition errors PinmemberAnonymous1-Apr-01 2:01 
GeneralRe: Comilition errors PinmemberDavid Hamel2-Apr-01 6:50 
GeneralRe: Comilition errors PinmemberAnonymous2-Apr-01 17:01 
GeneralRe: Comilition errors PinmemberKev Ward28-Jan-02 2:13 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 29 Mar 2001
Article Copyright 2001 by Hirosh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid