Click here to Skip to main content
12,547,321 members (59,771 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked

Simple Way to Make Transparent Dialog

, 5 Aug 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Enable user to make a dialog transparent without making its child control transparent


This is my first tip. I am writing a simple block of code to make a dialog transparent. I have seen many articles which make a dialog completely transparent with its child control too.

This tip uses a simple trick to make a transparent dialog without making its child controls transparent.

Using the Code

The idea behind making a transparent dialog is:

We can set the opacity and transparency color key of a layered window.

I used SetLayeredWindowAttributes with LWA_COLORKEY to replace a color with transparency, in order to achieve a transparent background.

The code that makes dialog is:

  1. Set the background color of the dialog which is not used in the application. I selected a color (e.g., RGB(1,11,21)) that is not present anywhere except in the dialog background.
  2. Set that color transparent using SetLayeredWindowAttributes with the LWA_COLORKEY flag.
LONG ExtendedStyle = GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE );
SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,ExtendedStyle | WS_EX_LAYERED );

Paste the above code in the OnInitDialog() function of your dialog class. Use Visual Studio 2010 and derive your dialog class from the CDialogEx class.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gautam Agrawal (Programming Expert)
Software Developer Retina Software Pvt Ltd
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
GOLDENPrinciple11-Sep-13 5:39
memberGOLDENPrinciple11-Sep-13 5:39 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161018.1 | Last Updated 6 Aug 2013
Article Copyright 2013 by Gautam Agrawal (Programming Expert)
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid