CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 1999
    Posts
    66

    Angry Black painted if SetLayeredWindowAttributes is called.

    Hi,

    well I have a usual dialog based application with a resizable dialog. Because I have some regions which gonna be transparent, I make in the OnInitDialog the following call:

    Code:
      const COLORREF crTransparent  = RGB( 255,   0,   0 );
      LONG dwNewLong = GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED;
      SetWindowLong(m_hWnd, GWL_EXSTYLE, dwNewLong);
      SetLayeredWindowAttributes( crTransparent, 0, LWA_COLORKEY);
    The MFC (or whoever) makes a not so funny black painting of the region which will be bigger then the initial dialog. Without calling 'SetLayeredWindowAttributes' the black painting is not happend.

    I tried to override the erase of background like this:

    Code:
    BOOL CBlaBlaTestDlg::OnEraseBkgnd(CDC* pDC)
    {
          CRect rect;
          GetWindowRect(&rect);     // Erase the area needed
          ScreenToClient(&rect);
          pDC->FillSolidRect(&rect, RGB(0,255,0));
          return TRUE;
    }
    but ... no chance, they are ... almighty. First apears the black painting, then my green solid rect.
    Has anyone, any idea how can I avoid this black painting ???
    Thanks in advance!

    Best regards,
    Emil
    Last edited by ovidiucucu; May 9th, 2006 at 06:48 AM. Reason: added [code]...[/code] tags

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Black painted if SetLayeredWindowAttributes is called.

    You mean you see the window temporary being drawn in black and then in the right color? If so, I'm afraid there is not much you can do. Are you calling SetLayeredWindowAttributes before the window is shown?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Aug 2004
    Location
    Bucharest, Romania... sometimes
    Posts
    1,039

    Re: Black painted if SetLayeredWindowAttributes is called.

    Try:
    Code:
    SetWindowLong(m_hWnd, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
    const COLORREF crTransparent = RGB( 0,   0,   0 );
    SetLayeredWindowAttributes(crTransparent, 0, LWA_COLORKEY);
    Also in OnEraseBkgnd, make sure you paint your "transparent" region of the window with "crTransparent". Still, you may repaint the client area in OnPaint, or parts of it if you have child windows (ex: MDI client is also a child of MDI frame), but otherwise, you should get transparency wherever your window has pixel values equal to crTransparent.
    Bogdan Apostol
    ESRI Developer Network

    Compilers demystified - Function pointers in Visual Basic 6.0
    Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.

    Customize your R2H
    The unofficial board dedicated to ASUS R2H UMPC owners.

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