Click here to Skip to main content
12,697,178 members (25,577 online)
Click here to Skip to main content
Add your own
alternative version


112 bookmarked

CDialogSK - A Skinnable Dialog Class

, 7 Jul 2003
Rate this:
Please Sign up or sign in to vote.
This article discusses the CDialogSK class that extends the CDialog MFC class and can be used to create dialogs that can be skinned.


This class is derived from the MFC CDialog. It supports the following features :-

  1. If running on Windows 2000 or Windows XP, make any one color transparent so that you can see through regions of the dialog
  2. If running on Windows 2000 or Windows XP, make the whole dialog translucent
  3. Adding a bitmap to the back ground. The bitmap can be a resource, a BMP file, or a HBITMAP
  4. Set style for background : Tile, Center, Stretch, resize dialog to the size of the bitmap
  5. Can enable/disable moving the dialog by clicking anywhere in it

Previous to Windows 2000 creating skinned dialogs were a bit difficult. You needed to write functions that could parse through the back ground image and create a CRgn that defined the shape of the skin. This could be done using repetitive calls to CRgn::CombineRgn for part of the image you wanted to see on the dialog. After creating the whole region you need to call CWnd::SetWindowRgn with a handle to the combined CRgn object.

From Windows 2000 a new API SetLayeredWindowAttributes  has been added to User32.dll. This class uses that to create skinned dialogs. However the background bitmap feature is not dependent on OS version and can be used on any version of Windows.

Using The Code

<!-- start a block of source code -->The class can be used using the following steps

  1. Add the files CDialogSK.h and CDialogSK.cpp to your project.

  2. Include CDialogSK.h in the .h file for your dialog class

  3. Replace all occurrences of "CDialog" with "CDialogSK" in the .h and .cpp files for your dialog class

  4. If you plan to use a background image (bitmap) go to dialog properties, styles tab and make Style=Popup, Border=None, and uncheck the "Title Bar" check box.

  5. At the end of OnInitDialog of your dialog class add calls to the appropriate methods in CDialogSK

    BOOL CSkinDialog_DemoDlg::OnInitDialog()
        EnableEasyMove();  // enable moving of the dialog 
                           // by clicking anywhere in the dialog
        SetBitmap (IDB_BACKGROUND); // set background bitmap
        SetStyle (LO_RESIZE); // resize dialog to the size of the bitmap
        SetTransparentColor(RGB(0, 255, 0)); // set green as the 
                                             // transparent color
        return TRUE;
  6. If you want to change the window style later you can call any of these method anywhere in your code at run time.
  7. If for example you want to make a circular dialog. Create a image which has a blue circle on a green background. Then call SetBitmap with the path to the image and call SetTransparentColor passing the color of background (green). This will remove the background from view and you will get a circular window.


The following methods are present in CDialogSK class

  1. DWORD SetBitmap (HBITMAP hBitmap); Sets a background bitmap based on a HBITMAP.
  2. DWORD SetBitmap (int nBitmap); Sets a background bitmap based on a resource ID.
  3. DWORD SetBitmap (LPCTSTR lpszFileName); Sets a background bitmap based on a Windows bitmap (.bmp) file.
  4. void SetStyle (LayOutStyle style); Sets the bitmap layout style. Can be any of LO_DEFAULT, LO_TILE (tile image), LO_CENTER (center image), LO_STRETCH (stretch image to fit dialog), LO_RESIZE (resize dialog to fit the image).
  5. void EnableEasyMove (BOOL pEnable = TRUE); If called with TRUE then you can move the dialog by clicking anywhere in the client area of the dialog.
  6. BOOL SetTransparent (BYTE bAlpha); Make the dialog as a whole transparent. Range is 0(transparent) - 255 (opaque). This works only on Windows2000 and above (WinXP).
  7. BOOL SetTransparentColor (COLORREF col, BOOL bTrans = TRUE); Make a particular color transparent. This works only on Windows2000 and above (WinXP). This can be used to create dialog in which you can see through parts of the dialog. 


  • This is the initial version. Date Posted: July 01, 2003


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I just love coding. I started programming in 1995 with BASIC and then moved through Cobol, Pascal, Prolog, C, C++, VB, VC++ and now C#/.NET.

I received a Bachelor of Technology degree in Computer Science from University of Calcutta in 2001.

I worked for some time in Texas Instruments, Adobe Systems and now in Microsoft India Development Center in the Visual Studio Team Systems.

I am from the City of Joy, Kolkata in India, but now live and code Hyderabad.

You may also be interested in...

Comments and Discussions

GeneralI need to use jpeg from resource Pin
kcselvaraj2-Aug-06 5:11
memberkcselvaraj2-Aug-06 5:11 
GeneralJust what I needed Pin
Stan Alex26-Mar-06 9:38
memberStan Alex26-Mar-06 9:38 
GeneralRe: Just what I needed Pin
abhinaba26-Mar-06 19:54
memberabhinaba26-Mar-06 19:54 
GeneralThank you! Pin
Late24-Jan-06 22:29
memberLate24-Jan-06 22:29 
QuestionProblem I am facing while trying with Windows Media Player Control Pin
ProgramVinod17-Oct-05 15:27
memberProgramVinod17-Oct-05 15:27 
GeneralPb with SMS Remote tools Pin
adk1-Aug-05 3:14
memberadk1-Aug-05 3:14 
GeneralImpossible to chage dialog image Pin
AnneVis3421-Jun-05 0:08
memberAnneVis3421-Jun-05 0:08 
QuestionDoes not work with directShow ? Pin
Yossef22-May-05 1:06
memberYossef22-May-05 1:06 
QuestionCan I use JPEG instead? Pin
tcitci18-Apr-05 11:31
membertcitci18-Apr-05 11:31 
AnswerRe: Can I use JPEG instead? Pin
<font color=#3399ff>ThatsAlok19-Apr-05 19:56
memberThatsAlok19-Apr-05 19:56 
GeneralFundu Code Pin
<font color=#3399ff>ThatsAlok18-Feb-05 21:24
memberThatsAlok18-Feb-05 21:24 
GeneralDotted-rectangle border!! Pin
nangluc10-Nov-04 18:08
membernangluc10-Nov-04 18:08 
GeneralLittle Bug ;) Pin
.: LegoLas :.6-Oct-04 7:51
member.: LegoLas :.6-Oct-04 7:51 
GeneralRe: Little Bug ;) Pin
abhinaba6-Oct-04 20:25
memberabhinaba6-Oct-04 20:25 
GeneralRe: Little Bug ;) Pin
.: LegoLas :.6-Oct-04 21:31
member.: LegoLas :.6-Oct-04 21:31 
QuestionChange Skin Dynamically? Pin
Arsalan Malik14-Sep-04 20:55
memberArsalan Malik14-Sep-04 20:55 
AnswerRe: Change Skin Dynamically? Pin
abhinaba14-Sep-04 21:20
memberabhinaba14-Sep-04 21:20 
GeneralRe: Change Skin Dynamically? Pin
Arsalan Malik15-Sep-04 1:07
memberArsalan Malik15-Sep-04 1:07 
GeneralRe: Change Skin Dynamically? Pin
abhinaba15-Sep-04 3:26
memberabhinaba15-Sep-04 3:26 
GeneralSkinnable class Pin
skinney4621-Jun-04 0:14
memberskinney4621-Jun-04 0:14 
GeneralWin 98 Solution Pin
skallestad23-May-04 1:04
memberskallestad23-May-04 1:04 
GeneralRe: Win 98 Solution Pin
abhinaba23-May-04 20:16
memberabhinaba23-May-04 20:16 
GeneralTransparent Child Dialog Pin
Calder30-Jan-04 15:30
memberCalder30-Jan-04 15:30 
GeneralRe: Transparent Child Dialog Pin
abhinaba1-Feb-04 21:07
memberabhinaba1-Feb-04 21:07 
GeneralRe: Transparent Child Dialog Pin
Calder2-Feb-04 1:51
memberCalder2-Feb-04 1:51 
QuestionWindows 98? Pin
JayDoggett3-Oct-03 12:04
memberJayDoggett3-Oct-03 12:04 
AnswerRe: Windows 98? Pin
abhinaba9-Dec-03 22:13
memberabhinaba9-Dec-03 22:13 
GeneralMaking the dialog resizable... Pin
WolfSupernova1-Oct-03 9:12
memberWolfSupernova1-Oct-03 9:12 
GeneralToo bad there's a copyright. Pin
WolfSupernova12-Sep-03 10:21
memberWolfSupernova12-Sep-03 10:21 
GeneralRe: Too bad there's a copyright. Pin
abhinaba9-Dec-03 22:08
memberabhinaba9-Dec-03 22:08 
GeneralWonderful!!! Pin
leonbourassa28-Jul-03 6:36
memberleonbourassa28-Jul-03 6:36 
GeneralBug in code Pin
abhinaba27-Jul-03 18:58
memberabhinaba27-Jul-03 18:58 
QuestionHow do you get rid of it? Pin
WREY14-Jul-03 18:22
memberWREY14-Jul-03 18:22 
AnswerRe: How do you get rid of it? Pin
abhinaba14-Jul-03 18:27
memberabhinaba14-Jul-03 18:27 
GeneralVery Neat Pin
Chopper9-Jul-03 3:29
memberChopper9-Jul-03 3:29 

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.170118.1 | Last Updated 8 Jul 2003
Article Copyright 2003 by abhinaba
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid