Like Tree2Likes
  • 1 Post By oogabooga
  • 1 Post By novacain

about transparent STATIC control

This is a discussion on about transparent STATIC control within the Windows Programming forums, part of the Platform Specific Boards category; i know that i can't do a realy transparent control(in windows 7, only above) so theres 3 ways: 1 - ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    121

    about transparent STATIC control

    i know that i can't do a realy transparent control(in windows 7, only above)
    so theres 3 ways:
    1 - the WM_PAINT message: and i can use the hdc parent with BitBlt();
    2 - the Region way(i have the code, but seems not working );
    3 - i can 'hide' the backcolor with WM_CTLCOLORSTATIC message.

    i have 1 question(for now):
    Code:
    case WM_CTLCOLORSTATIC:
                {
                    DeleteObject(g_hbrBackground);
                    HDC hdcStatic = (HDC)wParam;
                    SetTextColor(hdcStatic, inst->clrTextColor);
                    SetBkColor(hdcStatic,inst->clrBackColor);
                    SetBkMode(hdcStatic, TRANSPARENT);
                    g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
                    return (LONG)g_hbrBackground;
                }
                break;
    using the transparent way and with WS_EX_TRANSPARENT extended style, i can 'hide' the backcolor. but i see 1 problem: why the text(every time that it's changed) don't clean the last text?
    (what i see is several texts above others... isn't never clean before show the new text)

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    If there's no better solution and the background is unchanging, you could save it and use it to repaint the area before drawing new text.
    joaquim likes this.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    121
    Quote Originally Posted by oogabooga View Post
    If there's no better solution and the background is unchanging, you could save it and use it to repaint the area before drawing new text.
    sorry, but in these case, i wan't avoid the WM_PAINT
    i can share the Region way, but i need ask: it's a persistente way?

    Code:
    HRGN GetControlRegion(HWND hwnd,color clrColor)
    {
        HDC hDC=GetDC(hwnd);
    
        RECT rect;
        GetWindowRect(hwnd,&rect);
        int w=rect.bottom-rect.top;
        int h=rect.right-rect.left;
    
    
        HRGN hRgn = CreateRectRgn(0,0,0,0);
    
        for (int x = 0; x < w; x++)
        {
            for (int y=0; y<h; y++)
            {
                if(GetPixel(hDC,x,y)!=clrColor)
                {
                    HRGN hRgnTemp = CreateRectRgn(x, y, x, y+1);
                    CombineRgn(hRgn, hRgn, hRgnTemp, RGN_OR);
                    DeleteObject(hRgnTemp);
                }
            }
        }
        ReleaseDC(hwnd,hDC);
        return hRgn;
    }
    when i use an image, with a diferent backcolor, the control backcolor still be the old or it's the new one?
    anotherthing: i read something about InvaliteWindow() but seems not working or i'm not using the right message

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I am not sure what you want to do, so I cannot provide a solution...

    Could you clarify why you want the static to have a transparent background? [A screen shot would be helpful.]

    [Do you want the background of the whole window to be an image and clicking on a static control / area of the image triggers something? ie Hotspots
    or do you want the whole window to be transparent? ie show the window / desktop below]
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    121
    Quote Originally Posted by novacain View Post
    I am not sure what you want to do, so I cannot provide a solution...

    Could you clarify why you want the static to have a transparent background? [A screen shot would be helpful.]

    [Do you want the background of the whole window to be an image and clicking on a static control / area of the image triggers something? ie Hotspots
    or do you want the whole window to be transparent? ie show the window / desktop below]
    (i know do transparent and opacy with main window, but not with child controls... only if i use windows 8 or above)

    imagine the parent have 1 image.. i want see that image too. for these i can use the Region way, but seems that code isn't working. i wanted, too, the opacy, but for that i must use the WM_PAINT message and working with some GUID API functions.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    So the background is an image and the static control acts like a button (ie when the user clicks on an area in the image something happens, just as if the user had clicked a button)?

    If so why not just process mouse clicks?
    Set the static to not visible (remove the WS_VISIBLE style or use ShowWindow(hStaticControl, SW_HIDE) )
    If the mouse was clicked, convert the point from screen to client coordinates and check to see if the point clicked is in the static controls client rect ( PtInRect() ) then call the processing.
    That way you do not have to worry about any drawing of the static (as it is invisble).

    Otherwise you need to replace the code I provided before so it uses an offset in the BitBlt().
    Generally the offset would be the ((top left point of the static controls window rect) - (the top left of the parent's window rect)) ( GetWindowRect() not GetClientRect() )

    If the static just holds text, and that text changes durring run time (and the issue is the remnants of old text) then use double buffering.
    joaquim likes this.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Aug 2013
    Posts
    121
    Quote Originally Posted by novacain View Post
    So the background is an image and the static control acts like a button (ie when the user clicks on an area in the image something happens, just as if the user had clicked a button)?

    If so why not just process mouse clicks?
    Set the static to not visible (remove the WS_VISIBLE style or use ShowWindow(hStaticControl, SW_HIDE) )
    If the mouse was clicked, convert the point from screen to client coordinates and check to see if the point clicked is in the static controls client rect ( PtInRect() ) then call the processing.
    That way you do not have to worry about any drawing of the static (as it is invisble).

    Otherwise you need to replace the code I provided before so it uses an offset in the BitBlt().
    Generally the offset would be the ((top left point of the static controls window rect) - (the top left of the parent's window rect)) ( GetWindowRect() not GetClientRect() )

    If the static just holds text, and that text changes durring run time (and the issue is the remnants of old text) then use double buffering.
    thanks for that.
    let me ask anotherthing: the Region can give a control 1 shape(circule, rectangle or even irregular like an image), right?
    but can you give me a link for see better?

  8. #8
    Registered User
    Join Date
    Aug 2013
    Posts
    121
    finally works what i need for transparent:
    Code:
    case WM_CTLCOLORSTATIC:
                {
                    if ( inst->blnTransparent == true)
                    {
                        SetTextColor((HDC)wParam, inst->clrTextColor);
                        SetBkMode( (HDC)wParam, TRANSPARENT);
                        return (LRESULT) GetStockObject(HOLLOW_BRUSH);
                    }
                    else
                    {
                        DeleteObject(g_hbrBackground);
                        SetTextColor((HDC)wParam, inst->clrTextColor);
                        SetBkColor((HDC)wParam,inst->clrBackColor);
                        SetBkMode((HDC)wParam, TRANSPARENT);
                        g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
                        return (LONG)g_hbrBackground;
                    }
                }
                break;
    inst is the class\class instance pointer
    thanks for all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a "transparent" User Control Background.
    By indigo0086 in forum C# Programming
    Replies: 2
    Last Post: 01-01-2008, 10:50 AM
  2. Using scroll in static control
    By maxorator in forum Windows Programming
    Replies: 0
    Last Post: 10-10-2005, 11:32 AM
  3. Static Control Link?
    By Devil Panther in forum Windows Programming
    Replies: 5
    Last Post: 05-15-2004, 10:45 AM
  4. Transparent Static Controls, Non-MFC
    By X PaYnE X in forum Windows Programming
    Replies: 3
    Last Post: 08-06-2003, 10:32 PM
  5. BMP X/Y on Static control?
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 01-30-2002, 03:16 PM

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