CDialogSK, A Skinnable Dialog Class
Posted
by Abhinaba Basu
on July 7th, 2003
Environment: VC6 SP4, Windows 2000, WindowsXP
Introduction
This class is derived from the MFC CDialog. It supports the following features:
- If running on Windows2000 or Windows XP, makes any one color transparent so that you can see through regions of the dialog.
- If running on Windows2000 or Windows XP, makes the whole dialog translucent.
- Adds a bitmap to the background. The bitmap can be a resource, a BMP file, or a HBITMAP.
- Set style for background: Tile, Center, Stretch; resize dialog to the size of the bitmap.
- Can enable/disable moving the dialog by clicking anywhere in it.
Usage
The class can be used by using the following steps:
- Add the CDialogSK.h and CDialogSK.cpp files to your project.
- Include CDialogSK.h in the .h file for your dialog class.
- Replace all occurrences of "CDialog" with "CDialogSK" in the .h and .cpp files for your dialog class.
- If you plan to use a background image (bitmap) go to the dialog Properties, Styles tab and make it Style=Popup, Border=None, and uncheck the "Title Bar" check box.
- At the end of OnInitDialog of your dialog class, add calls to the appropriate methods in CDialogSK:
- If, for example, you want to make a circular dialog, create a image that has a blue circle on a green background. Then, call SetBitmap with the path to the image and call SetTransparentColor, passing the color of the background (green). This will remove the background from view and you will get a circular window.
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;
}
Methods
The following methods are present in CDialogSK class:
- DWORD SetBitmap (HBITMAP hBitmap);
Sets a background bitmap based on a HBITMAP - DWORD SetBitmap (int nBitmap);
Sets a background bitmap based on a resource ID - DWORD SetBitmap (LPCTSTR lpszFileName);
Sets a background bitmap based on a Windows bitmap (.bmp) file. - void SetStyle (LayOutStyle style);
Sets the bitmap layout style. Can be any of the following: LO_DEFAULT, LO_TILE (tile image), LO_CENTER (center image), LO_STRETCH (stretch image to fit dialog), or LO_RESIZE (resize dialog to fit the image). - void EnableEasyMove (BOOL pEnable = TRUE);
If called with TRUE, you can move the dialog by clicking anywhere in the client area of the dialog - 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). - 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 a dialog in which you can see through parts of the dialog.
Downloads
Download demo project - 33 KbDownload source - 4 Kb

Comments
good stuff
Posted by Saeed on 03/07/2008 12:32amWell done
ReplyAnimateWindow Question
Posted by jsimon on 03/19/2007 11:31amHas anyone tried this technique with the SDK function AnimateWindow? I have tried this and part of the bitmap placed on top of the dialog is messed up (while sliding). Any suggestions?
ReplyBg
Posted by huanbn on 11/03/2005 05:44amGreatWork
Posted by saiprabhur on 10/01/2004 07:36amNice job, Keep it up, This type of work more will be welcomed. Expecting more from you.
ReplyA little bug...
Posted by Dmetri B on 03/03/2004 09:03amCDialogSK.cpp line 253: ::SelectObject(dc.m_hDC, m_hBitmap); should be: ::SelectObject(dc.m_hDC, pbmpOldBmp);
-
-
Replydoes not compile in VS.Net
Posted by belarbi on 04/21/2006 05:34amerror "definition of dllimport static data member not allowed" This is due to AFX_EXT_CLASS in class definition: class AFX_EXT_CLASS CSkinDialog : public CDialog just remove AFX_EXT_CLASS and then it will work!
Replydoes not compile in VS.Net
Posted by gap001 on 10/08/2005 08:12amCDialogSK.cpp(121): error C2491: 'CDialogSK::_messageEntries' : definition of dllimport static data member not allowed
ReplyAdditional features possible
Posted by Legacy on 10/18/2003 12:00amOriginally posted by: Sasha Goldshtein
Replynice work
Posted by Legacy on 07/10/2003 12:00amOriginally posted by: programmer
nice work
ReplyVery neat
Posted by Legacy on 07/09/2003 12:00amOriginally posted by: Vitaly
Nice piece of code, neat interface.
ReplyCoool
Posted by Legacy on 07/08/2003 12:00amOriginally posted by: Aisha Ikram
Cool. I liked it :)
Reply