Click here to Skip to main content
15,900,589 members
Articles / Desktop Programming / MFC
Article

A simple transparent CStatic-derived class

Rate me:
Please Sign up or sign in to vote.
4.49/5 (32 votes)
16 Dec 2002 232.1K   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: Great, but..... (SetWindowText problem) Pin
Erin Loy14-Mar-05 13:30
Erin Loy14-Mar-05 13:30 
GeneralRe: Great, but..... Pin
RancidCrabtree29-Sep-05 7:09
RancidCrabtree29-Sep-05 7:09 
GeneralIt Does Not Work with Multiple Inheritance Pin
Julio Fabio Chagas14-Feb-03 4:59
Julio Fabio Chagas14-Feb-03 4:59 
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 
WTF | :WTF:

Don't you just hate it when this kind of sh*t happens?

Mad | :mad:

Good article.

I am curious about one other thing though. Since you probably would be using this class on top of a window that is already owner drawn, wouldn't you just put the text you want to display into that window, instead of layering a transparent static window on top of it? Or is my assumption about usage wrong?

Marc

Help! I'm an AI running around in someone's f*cked up universe simulator.
Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
Every line of code is a liability - Taka Muraoka

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 
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.