CDialogSK, A Skinnable Dialog Class

Environment: VC6 SP4, Windows 2000, WindowsXP

Introduction

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

  1. If running on Windows2000 or Windows XP, makes any one color transparent so that you can see through regions of the dialog.
  2. If running on Windows2000 or Windows XP, makes the whole dialog translucent.
  3. Adds a bitmap to the background. 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.

Usage

The class can be used by using the following steps:

  1. Add the CDialogSK.h and CDialogSK.cpp files 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 the dialog Properties, Styles tab and make it 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:
  6. 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;
    }
    
  7. 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.

Methods

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 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).
  5. void EnableEasyMove (BOOL pEnable = TRUE);
    If called with TRUE, 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 a dialog in which you can see through parts of the dialog.

Downloads

Download demo project - 33 Kb
Download source - 4 Kb


About the Author

Abhinaba Basu

Abhinaba loves coding for the sheer fun of it. He started programming in 1995 with BASIC and then moved through Cobol, Pascal, Prolog, C, C++, VisualBasic and VC++. He received a Bachelor of Technology degree from University of Calcutta in 2001. Abhinaba is originally from the City of Joy, Kolkata in India, but now codes and lives in Noida close to Delhi. His hobby is coding which also happens to be his job. Besides coding he loves traveling.

Comments

  • good stuff

    Posted by Saeed on 03/07/2008 12:32am

    Well done

    Reply
  • AnimateWindow Question

    Posted by jsimon on 03/19/2007 11:31am

    Has 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?

    Reply
  • Bg

    Posted by huanbn on 11/03/2005 05:44am

    judsffrgh

    Reply
  • GreatWork

    Posted by saiprabhur on 10/01/2004 07:36am

    Nice job, Keep it up, This type of work more will be welcomed. Expecting more from you.

    Reply
  • A little bug...

    Posted by Dmetri B on 03/03/2004 09:03am

    CDialogSK.cpp line 253: ::SelectObject(dc.m_hDC, m_hBitmap); should be: ::SelectObject(dc.m_hDC, pbmpOldBmp);

    • does not compile in VS.Net

      Posted by belarbi on 04/21/2006 05:34am

      error "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!

      Reply
    • does not compile in VS.Net

      Posted by gap001 on 10/08/2005 08:12am

      CDialogSK.cpp(121): error C2491: 'CDialogSK::_messageEntries' : definition of dllimport static data member not allowed

      Reply
    Reply
  • Additional features possible

    Posted by Legacy on 10/18/2003 12:00am

    Originally posted by: Sasha Goldshtein

    For completeness, it should be easy to add the following interface features:
    
    

    HBITMAP GetBackgroundBitmap();
    void SetBackgroundColor(COLORREF);
    COLORREF GetBackgroundColor();
    void SetBackgroundHatchStyle(...);

    ... and similar things.

    Reply
  • nice work

    Posted by Legacy on 07/10/2003 12:00am

    Originally posted by: programmer

    nice work

    Reply
  • Very neat

    Posted by Legacy on 07/09/2003 12:00am

    Originally posted by: Vitaly

    Nice piece of code, neat interface.

    Reply
  • Coool

    Posted by Legacy on 07/08/2003 12:00am

    Originally posted by: Aisha Ikram

    Cool. I liked it :)

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Remember getting your first box of LEGOS as a kid? How fun it was putting the pieces together, collaborating with your friends to create something new? Now, as an IT professional, assembling and maintaining a Lego-like collaboration infrastructure isn't what you signed up for. Piecing together disparate systems of record for email, web meetings and other applications is about as painful as stepping on a pile of Legos. Download the e-book to learn how implementing a collaboration system connects systems of …

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date