Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / MFC
Article

A simple transparent CStatic-derived class

Rate me:
Please Sign up or sign in to vote.
4.43/5 (31 votes)
16 Dec 2002 231.7K   8.5K   59   47
This class allows you to create transparent static controls. For instance, you can add text on a bitmap in a dialog.

Image 1

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.

License

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


Written By
Web Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: It Does Not Work with Multiple Inheritance Pin
Zorglab14-Feb-03 9:07
Zorglab14-Feb-03 9:07 
GeneralRe: It Does Not Work with Multiple Inheritance Pin
Julio Fabio Chagas17-Feb-03 1:49
Julio Fabio Chagas17-Feb-03 1:49 
GeneralWS_EX_TRANSPARENT Pin
Marc Clifton18-Dec-02 0:52
mvaMarc Clifton18-Dec-02 0:52 
GeneralRe: WS_EX_TRANSPARENT Pin
Zorglab18-Dec-02 1:44
Zorglab18-Dec-02 1:44 
GeneralRe: WS_EX_TRANSPARENT Pin
Marc Clifton18-Dec-02 1:50
mvaMarc Clifton18-Dec-02 1:50 
GeneralRe: WS_EX_TRANSPARENT Pin
Zorglab18-Dec-02 22:54
Zorglab18-Dec-02 22:54 
GeneralRe: WS_EX_TRANSPARENT Pin
Paolo Messina18-Dec-02 14:56
professionalPaolo Messina18-Dec-02 14:56 
GeneralRe: WS_EX_TRANSPARENT Pin
Zorglab18-Dec-02 22:46
Zorglab18-Dec-02 22:46 
I tried this, but it doesn't work. Why ? Confused | :confused:
GeneralRe: WS_EX_TRANSPARENT Pin
Paolo Messina19-Dec-02 0:23
professionalPaolo Messina19-Dec-02 0:23 
GeneralRe: WS_EX_TRANSPARENT Pin
Zorglab2-Apr-03 7:14
Zorglab2-Apr-03 7:14 
GeneralRe: WS_EX_TRANSPARENT Pin
RancidCrabtree29-Sep-05 7:13
RancidCrabtree29-Sep-05 7:13 
GeneralRe: WS_EX_TRANSPARENT Pin
AndrewSmirnov11-Aug-03 16:12
AndrewSmirnov11-Aug-03 16:12 
GeneralRe: WS_EX_TRANSPARENT Pin
lbs7516-Nov-05 18:28
lbs7516-Nov-05 18:28 

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.