1
votes

I have a parent window (MFC dialog) with some controls on it (editbox, button, etc.), which looks like this:

appearance of the initial dialog

At runtime (OnInitDialog), I create another child window which covers and hides all the other controls in the dialog, using this code:

  RECT r;
  GetClientRect(&r);
  m_layer.Create(NULL, NULL, WS_CHILD | WS_VISIBLE, r, this, 0);

The m_layer object is an instance of a class CLaywerWnd inherited from CWnd. In this class I override the following method:

BOOL CLayerWnd::OnEraseBkgnd(CDC* pDC)
{
  CBrush b(RGB(0, 100, 100));
  RECT r;
  GetClientRect(&r);
  pDC->FillRect(&r, &b);
  return TRUE;
}

Now my window looks like this:

parent with child window which covers controls

The problem is that when I move the mouse cursor or click on this new child window the messages are forwarded to the parent window (I checked this using Spy++), and the other child controls are redrawn over the new child window, like bellow.

children redrawn over

I don't understand why this happens and I want to know how to avoid this behavior.

2
What are you really trying to do with this layer window? Hide controls? Change the background color? Something else?BrendanMcK
@BrendanMcK - Actually, in the end, I want the layer window to be transparent and draw some things over it. The undesired behavior is that when I move the mouse, the underneath controls are painted over my layer window, and I don't understand why.Andrei Bozantan

2 Answers

0
votes

I may well be wrong, but I wonder if you've mixed up in your code the handles to the two dialogs, such that you're posting messages to the wrong dialog?

0
votes

One easy way to avoid it takes two steps:

  1. Change the state of all the hidden controls to disabled, so they won't react to any messages.
  2. Make sure the overlay window is at the top of the Z-order. You can do this when you create the window or later using SetWindowPos.