Transparent Child WIndow

IDH 21 Reputation points
2021-08-12T16:33:03.623+00:00

Hi,
I have a child CWnd object. Using SetWindowLong I have set WS_EX_LAYERED | WS_EX_TRANSPARENT.

The parent has a map as background. When I create the child I can see the map beneath as expected. When I move the object the initial image is moved within the child. If change the size of the child window the image in the child is refreshed and shows correctly what is beneath. If I just change the size this is redrawn correctly.

Can anyone explain why OnSize appears to work correctly and OnMove doesn't.

many thanks

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,559 questions
{count} votes

2 answers

Sort by: Most helpful
  1. IDH 21 Reputation points
    2021-08-13T13:08:29.667+00:00

    Thank-you for your reply: This is how my Child is created:

    BOOL RTWindRoseGadget::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
    {
    BOOL bCreated = CWnd::Create( lpszClassName, lpszWindowName, dwStyle, m_Rect, pParentWnd, nID, pContext);

    // Here I have a section of code that creates a ChartDirector object. This is commented whilst I investigate the OnMove issue

    return bCreated;

    RTWindRoseGadget::RTWindRoseGadget()
    {
    ........
    .......

    SetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE, GetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED);
    if (m_bTransparent)
    {
        LONG ExtendedStyle = GetWindowLong(this->m_hWnd, GWL_EXSTYLE);
        SetWindowLong(this->m_hWnd, GWL_EXSTYLE, ExtendedStyle | WS_EX_LAYERED | WS_EX_TRANSPARENT);
        ::SetLayeredWindowAttributes(this->m_hWnd, RGB(1, 11, 21), 0, LWA_COLORKEY);
    }
    

    void RTWindRoseGadget::OnMove(int x, int y)
    {
    TRACE("OnMove\r");

    // refresh donor bitmap and force display
    if (IsWindow(m_RTWindRoseViewer.m_hWnd))
    {
        m_RTWindRoseViewer.Invalidate();
    }
    Invalidate();
    UpdateWindow();
    

    }

    void RTWindRoseGadget::OnMove(int x, int y)
    {
    TRACE("OnMove\r");

    // refresh donor bitmap and force display
    if (IsWindow(m_RTWindRoseViewer.m_hWnd))
    {
        m_RTWindRoseViewer.Invalidate();
    }
    Invalidate();
    UpdateWindow();
    

    }

    void RTWindRoseGadget::OnSize(UINT nType, int cx, int cy)
    {
    TRACE("OnSize\r");

    Gadget::OnSize(nType, cx, cy);
    CRect rectC;
    
    GetClientRect(rectC); // get client rect for this gadget
    m_RTWindChart.SetGraphDimensions(rectC.Width(), rectC.Height());
    if (IsWindow(m_RTWindRoseViewer.m_hWnd))
    {
        m_RTWindRoseViewer.Invalidate();
    }
    
    Invalidate();
    UpdateWindow();
    

    }

    As I haven't created the Chart object, the chart viewer invalidate is not called.

    Does the above help?

    Regards


  2. IDH 21 Reputation points
    2021-08-23T12:48:29.927+00:00

    Hi Jeanine,
    Thank-you for your suggestion. I did try the RedrawWindow option, I found that it sometimes worked, it maybe down to choosing the correct options.

    Regards

    0 comments No comments