How to set Transparent Dialogs?
The secret is Layered windows. For that you’ve to enable WS_EX_LAYERED style and set the alpha of dialog by calling SetLayeredWindowAttributes(). See the code snippet below.
// Enable WS_EX_LAYERED window extended style.
LONG ExtendedStyle = GetWindowLong( GetSafeHwnd(),
GWL_EXSTYLE );
SetWindowLong( GetSafeHwnd(),
GWL_EXSTYLE,
ExtendedStyle | WS_EX_LAYERED );
// Select the transparency percentage.
// The alpha will be calculated accordingly.
double TransparencyPercentage = 50.0;
// Set the alpha for transparency.
// 0 is transparent and 255 is opaque.
double fAlpha = TransparencyPercentage * ( 255.0 /100 );
BYTE byAlpha = static_cast( fAlpha );
SetLayeredWindowAttributes( GetSafeHwnd(),
0,
byAlpha,
LWA_ALPHA );
Layered windows are available from Windows 2000 onwards. So don’t forget to add _WIN32_WINNT=0×0500
to project settings for preparing the dialog invisible portion.

0 comments:
Post a Comment