CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    transparent static control and display icon

    hi, i want to make my static control transparent, so it will draw transsparent background with text.
    and i want to have a transparent static where i can display my icon.

    i can set the WS_EX_TRANSPARENT but that does not make it transparent yet?

  2. #2
    Join Date
    Jan 2009
    Posts
    28

    Re: transparent static control and display icon

    Did you try using SetBkMode?

    http://msdn.microsoft.com/en-us/libr...62(VS.85).aspx

    If you are using MFC you could do something like:

    Code:
    if(CTLCOLOR_STATIC == nCtlColor)
    {
    	pDC->SetBkMode(TRANSPARENT);
    	return (HBRUSH)GetStockObject(NULL_BRUSH);
    }

    http://msdn.microsoft.com/en-us/library/0wwk06hc.aspx

    Best Wishes,
    -David Delaune

  3. #3
    Join Date
    Oct 2005
    Location
    Minnesota, U.S.A.
    Posts
    680

    Re: transparent static control and display icon

    Randor has a start, but there is more to it.

    You need to set the back mode and color, then copy the bitmap to a monochrome. Using that monochrome bitmap as a mask, you then can paint a seemingly transparent background by just painting the rest of the bitmap.

    There are hundreds of threads on this subject in this forum, just do a search.

    -Erik

  4. #4
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: transparent static control and display icon

    i dont use MFC (this is the winapi forum not VC++ forum)

    WS_EX_TRANSPARENT and SetBkMode seems to work fine.

    now i just need to use DrawIcon... should i put it in WM_PAINT

  5. #5
    Join Date
    Jan 2009
    Posts
    28

    Re: transparent static control and display icon

    Quote Originally Posted by cj-wijtmans View Post
    i dont use MFC (this is the winapi forum not VC++ forum)

    WS_EX_TRANSPARENT and SetBkMode seems to work fine.

    now i just need to use DrawIcon... should i put it in WM_PAINT
    My apologies, I am generally on codeproject.com and have only recently signed up here and have not become familiar with the codeguru forum peculiars and layout.

    Yes, the WM_PAINT would be the correct location for calling DrawIcon. If you are concerned with flicker then perhaps you could experiment with disabling the WM_ERASEBKGND message by returning 1 or adding WS_CLIPCHILDREN to the parent window.

    Best Wishes,
    -David Delaune

  6. #6
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: transparent static control and display icon

    i already have the WS_CLIPCHILDREN flag set i wont have to handle the ERASEBKGND msg?

    i tried drawing the icon there but it does not work it does not show up.


    Code:
    			PAINTSTRUCT ps = {0};
    			HDC hdc = ::BeginPaint(Handle(), &ps);
    			::DrawIcon(hdc, 0, 0, Arrow);
                ::EndPaint(Handle(), &ps);

  7. #7
    Join Date
    Jan 2009
    Posts
    28

    Re: transparent static control and display icon

    Quote Originally Posted by cj-wijtmans View Post
    i already have the WS_CLIPCHILDREN flag set i wont have to handle the ERASEBKGND msg?
    WS_CLIPCHILDREN on the parent window will cause it to exclude the child when redrawing. Don't worry about the WM_ERASEBKGND message unless you have flicker issues that you want to resolve.

    Quote Originally Posted by cj-wijtmans View Post
    i tried drawing the icon there but it does not work it does not show up.
    Have you invalidated the area associated with your static control? Try calling InvalidateRect on the client coordinates of the static.

    http://msdn.microsoft.com/en-us/libr...03(VS.85).aspx
    http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx

    Best Wishes,
    -David Delaune

  8. #8
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: transparent static control and display icon

    thanks alot for your help

  9. #9
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: transparent static control and display icon

    Quote Originally Posted by Randor View Post
    WS_CLIPCHILDREN on the parent window will cause it to exclude the child when redrawing.
    Even if control has WS_EX_TRANSPARENT style?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  10. #10
    Join Date
    Jan 2009
    Posts
    28

    Re: transparent static control and display icon

    Quote Originally Posted by VladimirF View Post
    Even if control has WS_EX_TRANSPARENT style?
    Yes, even if the static control has the WS_EX_TRANSPARENT style. When the parent window is redrawn it will clip the child if the parent has the WS_CLIPCHILDREN flag.


    By default, the windows affected by RedrawWindow depend on whether the specified window has the WS_CLIPCHILDREN style. Child windows that are not the WS_CLIPCHILDREN style are unaffected; non-WS_CLIPCHILDREN windows are recursively validated or invalidated until a WS_CLIPCHILDREN window is encountered.


    http://msdn.microsoft.com/en-us/libr...00(VS.85).aspx

    Best Wishes,
    -David Delaune

  11. #11
    Join Date
    Dec 2008
    Posts
    29

    Re: transparent static control and display icon

    If you want all of your static controls be transparent you can use the same method that mentioned in post 2 but for win32 API, especially for dialog box:

    Code:
    case WM_CTLCOLORSTATIC:
        SetBkMode ( (HDC)wParam, TRANSPARENT);
        return (BOOL)hbrush;

  12. #12
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: transparent static control and display icon

    Quote Originally Posted by Randor View Post
    Yes, even if the static control has the WS_EX_TRANSPARENT style. When the parent window is redrawn it will clip the child if the parent has the WS_CLIPCHILDREN flag.
    Then who draws the background under WS_EX_TRANSPARENT controls?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  13. #13
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: transparent static control and display icon

    i think WS_EX_TRANSPARENT will tell the parent window to draw the area behind the child first even if WS_CLIPCHILDREN is set

  14. #14
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: transparent static control and display icon

    Quote Originally Posted by cj-wijtmans View Post
    i think WS_EX_TRANSPARENT will tell the parent window to draw the area behind the child first even if WS_CLIPCHILDREN is set
    That was my point
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  15. #15
    Join Date
    Jan 2009
    Posts
    28

    Re: transparent static control and display icon

    Quote Originally Posted by VladimirF View Post
    Then who draws the background under WS_EX_TRANSPARENT controls?
    You are correct. I knew you were baiting me when you posted the response so I took the bait. The background is painted behind the child window and therefore non-clipped during the parent window painting. However during the recursive invalidation the child window is excluded/clipped.

    Best Wishes,
    -David Delaune

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured