How to set Transparent Dialogs?

7 10 2008

The Invisible Man” by HG Wells. I still remember reading the translated version of that classic, when i was a kid. And even thought to conduct some experiments to become invisible. You could guess, what happened then. 🙂 I couldn’t. But now I feel happy that atleast I could find a magic portion which can make dialogs invisible. 😉  Well, how to change the transparency of 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(),
               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<BYTE>( fAlpha );
SetLayeredWindowAttributes( GetSafeHwnd(),
                            LWA_ALPHA );

Layered windows are available from Windows 2000 onwards. So don’t forget to add _WIN32_WINNT=0x0500 to project settings for preparing the dialog invisible portion. 😉

Targeted Audience – Intermediate.



2 responses

22 10 2008

I am seaching for some idea to write in my blog… somehow come to your blog. best of luck. Eugene

22 10 2008

Hello Eugene,

I think you’re the author of Isn’t it? Well, I’m so glad that my blog was helpful reference to you. All the best for your new blog. If you need any help from me, just ping. Its my pleasure to do so. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: