question

IDH-0162 avatar image
0 Votes"
IDH-0162 asked IDH-0162 answered

Transparent Child WIndow

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++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe your code has some issues.

0 Votes 0 ·

@IDH-0162

Could you please provide a sample to help us reproduce the issue?

0 Votes 0 ·
IDH-0162 avatar image
0 Votes"
IDH-0162 answered JeanineZhang-MSFT commented

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


· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@IDH-0162

According to the doc: Using Layered Windows

In order to use layered child windows, the application has to declare itself Windows 8-aware in the manifest.

I suggest you could refer to the link: https://stackoverflow.com/a/42570249/11872808


0 Votes 0 ·

Hi Jeanine,
Many thanks for your input. I tried the compatability section of the manifest file which had no effect (I was using DEBUG mode), I am running WIn10/VS2015. I thought the idea of the manifest is to ensure the target machine is running >Win8 Windows. My child window (CWnd) is showing what is beneath it but it does not refresh when I move from its initial position. I discovered today that if I just left click outside the child window the image is refreshed as did the OnSize. Is it down to who is processing the message?

Regards

0 Votes 0 ·

@IDH-0162

Could you please provide some screenshots to help us better understand what do you want to achieve?

Do you want the transparent child window displays the image that in the parent window? Whether the image does not refresh when moving the child window?

0 Votes 0 ·

Hi Jeanine,

123899-rtwindrose.pdf



Please find the example of moving the child window. I want the child to show the image behind it on the parent window. The image does not refresh during the move.

Regards

0 Votes 0 ·
rtwindrose.pdf (383.7 KiB)

@IDH-0162

I couldn't reproduce the issue. I suggest you could try to use OnLButtonDown to realize the child window move instead of OnMove.

 void MyChild::OnLButtonDown(UINT nFlags, CPoint point)
 {
     // TODO: Add your message handler code here and/or call default
    
     PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
    
     CDialogEx::OnLButtonDown(nFlags, point);
 }

124140-14-18-56.gif


0 Votes 0 ·
14-18-56.gif (328.0 KiB)

Hi Jeanine,
Thanks for the tip. This didn't seem to work in my application environment. However, I did find that in the OnMove method I preceded Invalidate and UpdateWindow with GetParent()-> and this caused the child to be refreshed. I does, slow down the movement of the object and they flicker.

Regards

0 Votes 0 ·

Hi IDH,

Invalidate just informs the system that the window at this time has become invalid. Forcing the system to call WM_PAINT, and this message is just Post is to put the message into the message queue. The exposure will be redrawn when the WM_PAINT message is executed. UpdateWindow only sends WM_PAINT message to the window. Before sending it, judge GetUpdateRect(hWnd, NULL, TRUE) to see if there is a client area that can be drawn. If not, WM_PAINT is not sent. RedrawWindow() has the dual characteristics of Invalidate() and UpdateWindow(). Declare the status of the window as invalid, update the window immediately, and call WM_PAINT message processing immediately. I suggest you could try to use RedrawWindow.

0 Votes 0 ·
IDH-0162 avatar image
0 Votes"
IDH-0162 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.