Transparent Text

This is a discussion on Transparent Text within the Windows Programming forums, part of the Platform Specific Boards category; I was wondering how do I output text that is transparent. I have a tab control and when I add ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    193

    Transparent Text

    I was wondering how do I output text that is transparent. I have a tab control and when I add a static control with text, the static control has the background color of a dialog box and the tab control has a different background color. I want the static control to have the same background color as the tab control so that text "blends" into the tab control. Any help is greatly appreciated.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    style WS_EX_TRANSPARENT

    Kuphryn

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Either create the static control with the WS_EX_TRANSPARENT (see CreateWindowEx) extended window style or handle the static control parent's WM_CTLCOLORSTATIC message and return the handle of the brush used to paint the tab control.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    WS_EX_TRANSPARENT gives me a black rectangle in the middle of a dialog box color rectangle in the middle of the tab control.

    When I call WM_CTLCOLORSTATIC, no matter what I do afterward, all the colors change. The tab control color, the dialog box color, and the text color. It looks horrible. I think its because in the resource (.rc) file, I use DIALOGEX instead of DIALOG to create the dialog box. I think it attempts to convert the dialog box from a DIALOGEX to a DIALOG and fails.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>When I call WM_CTLCOLORSTATIC<<

    The message should be handled, not called. If you are handling the message, post your handling code.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Well, I use:

    switch(Message) {
    ....
    case WM_CTLCOLORSTATIC:
    ....
    }

    I think I just used the wrong word. Here is the code I use for WM_CTLCOLORSTATIC message:

    Code:
    ....
    case WM_CTLCOLORSTATIC:
         SetBkMode((HDC)wParam, TRANSPARENT);
         return true;
    ....
    If I comment out the SetBkMode line, the same result is given where all the colors are "messed" up.

  7. #7
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Ken Fitlike: "return the handle of the brush used to paint the tab control"

    MSDN: "If an application processes this message, the return value is a handle to a brush that the system uses to paint the background of the static control."

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by msdn WM_CTLCOLORSTATIC
    If a dialog box procedure handles this message, it should cast the desired return value to a BOOL and return the value directly. If the dialog box procedure returns FALSE, then default message handling is performed.
    The handler expects a brush type returned, if you want a NULL-brush, return GetStockObject(HOLLOW_BRUSH)

    edit: biffed by Dante
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Thanks for the information. Now I have:

    Code:
    ...
    case WM_CTLCOLORSTATIC:
         SetBkMode((HDC)wParam,TRANSPARENT);
         return (bool)GetStockObject(HOLLOW_BRUSH);
    ....
    That gives me the same result if I comment out the entire WM_CTLCOLORSTATIC message handle where the background color of the static control is the same color as the dialog box control where I want it to be the same color of the tab control.

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    I change my code to:

    Code:
    ...
    case WM_CTLCOLORSTATIC:
         return (bool)SetBkMode(GetDlgItem(hWnd, ID_TEXT), TRANSPARENT);
    ...
    That will give me the background color of a dialogex box background color instead of an ordinary dialog box background color. I know I'm close to solving this. Any more suggestions? Thanks for all your help so far.

  11. #11
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    bool and BOOL are different types - cast to BOOL, which I believe, is an unsigned int alias or better, INT_PTR as a DialogProc return type should be (you'll have to change declaration and definition of of your DialogProc to match).

    If that doesn't work, try:
    Code:
    return (INT_PTR)GetClassLongPtr(hTabWnd, HGCL_HBRBACKGROUND);
    where hTabWnd is your tab control handle.
    Last edited by Ken Fitlike; 05-23-2006 at 08:12 PM. Reason: reformat code to remove extraneous spaces inserted by cboard
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Ah, thanks for your help. It is much appreciated. Changing from (bool) to (INT_PTR) worked. I sometimes overlook the simpliest things. I know my dialog proc function's return type is an INT_PTR and not a bool. Thanks again. Here is my final code:

    Code:
    case WM_CTLCOLORSTATIC:
         SetBkMode((HDC)wParam, TRANSPARENT);
         return (INT_PTR)GetStockObject(HOLLOW_BRUSH);
    EDIT:

    Woopsie...Forgot the SetBkMode line...
    Last edited by stickman; 05-23-2006 at 08:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble drawing text xlib.
    By Qui in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2006, 01:07 PM
  2. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 10:52 PM
  3. Text positioning and Text scrolling
    By RealityFusion in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2004, 01:35 AM
  4. Scrolling The Text
    By GaPe in forum C Programming
    Replies: 3
    Last Post: 07-14-2002, 05:33 PM
  5. Replies: 1
    Last Post: 07-13-2002, 06:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21