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

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read