|
Question : WS_EX_TRANSPARENT
|
|
How do i get this window style working? As a test i created a simple formview type application, added an edit box to the form and a button on top of it. I set the transparent style on the button, subclassed it, and put in a WM_PAINT handler which does nothing.
But when i run the app the edit control is still hidden by the button: where the button was placed just appears as the grey backround colour of the form.
What am i missing here?
|
|
Answer : WS_EX_TRANSPARENT
|
|
From the MS KB article:
>>> INFO: Transparent Windows ID: Q92526 [snip] WS_EX_TRANSPARENT was designed to be used in very modal situations and the lifetime of a window with this style must be very short. A good use of this style is for drawing tracking points on the top of another window. For example, a dialog editor would use it to draw tracking points around the control that is being selected or moved. >>>
And example of how one would use WS_EX_TRANSPARENT is given in another MS KB article:
>>> HOWTO: Use Win32 API to Draw a Dragging Rectangle on Screen DC ID: Q135865 [snip] Method Two: How to Perform Rubber Banding in Win32-Based Applications
Another way to do rubber banding in win32 consistent with the 16-bit method is to create a popup window that covers the entire desktop and has the WS_EX_TRANSPARENT style bit set. This window can be created with no title bar or borders and is active only for the time period of the rubber banding. It is destroyed upon completion of the rubber banding - when the user releases the mouse button. This popup window becomes the capture window and the rubber banding logic would then simply be applied on the client area DC of the popup window. >>>
Another technical article has more to say on this: >>> Win32 Window Hierarchy and Styles Kyle Marsh Microsoft Developer Network Technology Group [snip] WS_EX_TRANSPARENT The WS_EX_TRANSPARENT style makes a window transparent; that is, the window can be seen through, and anything under the window is still visible. Transparent windows are not transparent to mouse or keyboard events. A transparent window receives paint messages when anything under it changes. Transparent windows are useful for drawing drag handles on top of other windows or for implementing "hot-spot" areas without having to hit test because the transparent window receives click messages. >>>
In other words, it is not really useful for things like making a dialogs transparent etc. Even when it does work, moving it stuffs up (note: you can sort-of fix the stuff up by responding to WM_WINDOWPOSCHAING and using the SWP_NOCOPYBITS to stop it copying the original bacground around with it.
Also, note that: >>> In Windows 2000, specific colors in a window can be made truly transparent by giving the window the WS_EX_LAYERED extended style and calling SetLayeredWindowAttributes. >>> Maybe WinME will have support for this as well when it is released. But if you need to be backward compatible with Win95/98/NT, then proper transparent or translucent are going to involve a lot of work.
|
|
|
|