Click here to Skip to main content
Click here to Skip to main content

Cool, Semi-transparent and Shaped Dialogs with Standard Controls for Windows 2000 and Above

, 28 Sep 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
This article tries to find a way to show Windows standard controls on layered windows. Provides both Native MFC and WinForms source code.


First, let me show you some screenshots captured from the demo program.



The program demonstrates semi-transparent dialogs which are compatible with Windows 2000 and higher.


Layered windows, supported from Windows NT 5.0, provide a way to create windows that have a complex shape with alpha blending effects. The major challenge is how to show standard controls on layered windows.

The following shows the mechanism:


When the dialog is being created, a fake window is created by CreateWindowEx with the styles WS_EX_LAYERED, WS_EX_TRANSPARENT, and WS_EX_NOACTIVATE. The alpha value of the real window will be modified to 5 by SetLayeredWindowAttributes so that the real window is almost transparent.

The real window is in charge of processing user input events and Windows messages; the fake one is in charge of the presentation. The fake window is always kept the same size / position as the real one.

How do we show standard controls on the fake window? When the presentation needs to be refreshed, the background image is painted first. Then, all the child controls will be captured by sending the WM_PRINT message, and painted at the same position on the fake window. Especially, for EDIT controls, EditBox / Editable ComboBox / etc., we need to draw the caret by ourselves.

When should we refresh the presentation? We need to refresh the fake window when there is an update on the UI. In the demo, it hooks into all the child controls recursively, and changes the WNDPROC address by SetWindowLongPtr with the parameter GWLP_WNDPROC.

You can get more details by looking into the source code.

Using the Code in Native C++ / MFC

First Step

Copy all the files in /Src/*.* to your project.

Second Step

You need an image file to be the dialog background. You'd better choose PNG or TIFF which support the alpha channel. The image file can be embedded into a resource or placed on disk, judged by yourself.

Final Step

Replace the dialog base class from CDialog to CImgDialogBase.

// Load from disk file
CDemo2Dlg::CDemo2Dlg(CWnd* pParent /*=NULL*/)
    : CImgDialogBase( CDemo2Dlg::IDD
    , CUtility::GetModulePath() + _T("background.png")
    , pParent


// Or load from resource
CDemo3Dlg::CDemo3Dlg(CWnd* pParent /*=NULL*/)
    : CImgDialogBase(CDemo3Dlg::IDD
    , IDB_PNG_DLG2
    , _T("PNG")
    , AfxGetResourceHandle()
    , pParent


Using the Code in WinForms/.NET

First Step

Copy files in the /Src/*.* directory to your project.

Second Step

You need an image file to be the dialog background. You'd better choose PNG or TIFF which support alpha channel.

Final Step

Replace the dialog base class from Form to ImageDlgBase.

public partial class Form2 : CoolImageDlg.ImageDlgBase
    public Form2()
        base.DlgBgImg = ImgDlgSample.Properties.Resources.DemoDlgBg2;

Something Important

The dialog works in a way that if there is one pixel that needs to be updated, the whole window will be refreshed. Therefore, if the dialog is very large and complex, or has a lot of child controls, it may cause performance issues.

Some of the controls cannot work with WM_PRINT; in that case, the control won't display correctly. In other words, not all controls are supported.

The sample code uses the GDI+ helper class from Zoltan Csizmadia. For those who do not want to use GDIPlus.dll, CxImage is another choice.

Most of the machines use 96 DPI as their monitor setting. For those machines which use an unusual DPI setting, please note the demo is not meant for such settings and the child controls will be misplaced. You need to add your own code to re-layout the child controls if you do need to support unusual DPIs.


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


About the Author

Team Leader
China China
Jerry is from China. He was captivated by computer programming since 13 years old when first time played with Q-Basic.

  • Windows / Linux & C++
  • iOS & Obj-C
  • .Net & C#
  • Flex/Flash & ActionScript
  • HTML / CSS / Javascript
  • Gaming Server programming / video, audio processing / image & graphics

Contact: vcer(at)
Chinese Blog:

Comments and Discussions

QuestionHow can I make CStatic controls background transparent?? [modified] PinmemberMember 114229713-Feb-15 7:35 
Generalreply PinmemberMember 1111221627-Sep-14 5:13 
QuestionGreat Work !!, But Any solution to make something similar with a WebBrowser control inside ? Pinmemberwzbn3-Jun-14 7:04 
GeneralGood work! PinmemberMember 1062363021-May-14 22:50 
QuestionMy vote of 5 PinmemberManikandan1021-May-14 19:35 
GeneralMy vote of 5 PinprofessionalCaptain Price28-Dec-13 7:05 
Question厉害 Pinmemberkk501127-Sep-13 22:35 
QuestionWM_KEYDOWN PinmemberVladimir Popov5-Jul-13 3:26 
GeneralMy vote of 5 Pinmemberfredatcodeproject28-Apr-13 4:43 
Questionwhat if we need to add a fade in and fade out option ? PinmemberFiras Kudsy14-Jul-12 20:50 
QuestionHello! I have a question to ask 【你好 我有个问题想问 】 [modified] PinmemberMember 84836733-Apr-12 21:17 
QuestionHow to show Transparent Static Control Pinmemberreplyam30-Aug-11 1:19 
GeneralMy vote of 5 Pinmemberlimitswen23-Aug-11 21:14 
GeneralMy vote of 5 PinmemberNowBie27-Jul-11 7:05 
GeneralMy vote of 5 PinmemberJamming117-Jun-11 12:40 
Very nice! Job well-done
GeneralMy vote of 5 Pinmemberrahulrcn30-May-11 2:19 
GeneralMy vote of 5 Pinmemberwild23-Mar-11 22:34 
GeneralWhen I added the slider control, it would not be print on fake windows Pinmemberxujingyu7-Oct-10 19:19 
Generalgood. win7's glass to xp Pinmemberwave82612-Aug-10 4:32 
GeneralGreatJob Pinmembergyrtenudre9-Aug-10 3:30 
GeneralMy vote of 5 PinmemberAzadar.H17-Jul-10 8:00 
QuestionAdd Panel control PinmemberYoni923-Jun-10 5:13 
Generalfake windows and real windows PinmemberGlen Hadi30-Mar-10 17:27 
GeneralA Question Pinmemberzhaoxy28506-Mar-10 20:58 
GeneralTransparent controls PinmemberMickael124-Feb-10 22:10 
GeneralRe: Transparent controls PinmemberJerry.Wang8-Mar-10 17:37 
GeneralWM_PAINT Pinmemberdima_kdl7-Nov-09 6:22 
GeneralRe: WM_PAINT PinmemberJerry.Wang7-Nov-09 14:28 
Generalgood job,good boy! Pinmemberhuangzongwu16-Oct-09 2:45 
GeneralCode is slow to execute PinmemberDiamonddrake3-Sep-09 6:44 
GeneralRe: Code is slow to execute PinmemberD.K.Wang5-Sep-09 0:20 
GeneralAnother Good Article, goto PinmemberD.K.Wang2-Sep-09 5:11 
GeneralRe: Another Good Article, goto PinmemberJerry.Wang3-Nov-09 9:30 
QuestionSDI/MDI PinmemberGwanho31-Aug-09 17:11 
QuestionI got a problem of string conversion Pinmemberbluespeed00129-Jul-09 17:46 
AnswerRe: I got a problem of string conversion PinmemberJerry.Wang29-Jul-09 21:39 
GeneralRe: I got a problem of string conversion Pinmemberbluespeed00130-Jul-09 4:37 
GeneralGood Article Pinmemberzdlhm6-Jul-09 0:01 
GeneralSupport for Property Page based dialog applications PinmemberMember 45690375-Jul-09 21:33 
GeneralLayered Window without fake window Pinmemberit_fly29-Jun-09 21:13 
GeneralRe: Layered Window without fake window PinmemberMartial Spirit12-Jul-09 4:04 
GeneralRe: Layered Window without fake window Pinmembersashoalm10-Sep-10 7:20 
GeneralGood Job ! PinmemberCr4zyC0de29-Jun-09 0:26 
Questionsubclass controls PinmemberRay Guan9-Jun-09 18:15 
AnswerRe: subclass controls PinmemberRay Guan10-Jun-09 17:53 
GeneralRe: subclass controls PinmemberJerry.Wang11-Jun-09 17:30 
GeneralRe: subclass controls PinmemberRay Guan14-Jun-09 7:27 
QuestionSupported controls PinmemberMember 456903727-May-09 18:22 
Questionwhere is the problem? Pinmemberdinggen26-May-09 6:26 
QuestionHi PinmemberApoorv Kalra20-May-09 17:18 

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 | Terms of Use | Mobile
Web03 | 2.8.150414.1 | Last Updated 28 Sep 2012
Article Copyright 2009 by Jerry.Wang
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid