65.9K
CodeProject is changing. Read more.
Home

A simple transparent CStatic-derived class

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.49/5 (30 votes)

Dec 17, 2002

viewsIcon

235148

downloadIcon

8490

This class allows you to create transparent static controls. For instance, you can add text on a bitmap in a dialog.

Description

Sometimes, transparent static controls are very useful. For example, you have a dialog with a bitmap in it and want to add some text in the picture. If you create a static control, your text will appear on an opaque background, even if you've selected the WS_EX_TRANSPARENT style (this style is *very* buggy).

How to implement

To use the class in your application you need to do the following:

  1. Insert the .h and .cpp files into your project.
  2. Add a static control into your dialog resource.
  3. Add a member variable for that static control.
  4. Modify the variable declaration.
    Change this:
    CStatic m_Static
    To this:
    CTransparentStatic m_Static
  5. Don't forget the #include at the top of the include file:
    #include "TransparentStatic.h"

That's it. You should now have a transparent background.

Features

The following Static Styles are implemented:

  • SS_LEFT
  • SS_LEFTNOWORDWRAP
  • SS_RIGHT
  • SS_CENTER
  • SS_CENTERIMAGE (center text vertically)
  • SS_NOPREFIX
  • SS_WORDELLIPSIS
  • SS_ENDELLIPSIS
  • SS_PATHELLIPSIS

The various borders (SS_SUNKEN, WS_EX_CLIENTEDGE, ...) are also supported.