4

it starts driving me nuts, but I cann't figure out how to keep position of a child control in a z-order. At design time in MFC dialog resource editor I have STATIC control (descendant of CStatic) at the bottom (tab order Nr. 1), ie. it's overlapped by other controls like buttons, listbox etc.

At runtime, dialog handles WM_TIMER message and in OnTimer handler there gets the STATIC control moved:

void CTestMFCDlg::OnTimer(UINT_PTR nIDEvent)
{
  ...
  m_stMyStatic.SetWindowPos(&this->wndBottom, xpos, ypos, 0, 0, SWP_NOSIZE);
  ...
}

After the call of SetWindowPos for the sublassed CStatic control, it's drawed over other controls in a dialog, no matter what I'm passing in the first argument.

Any idea how to keep the control at the bottom of Z-order all the time ?

David Unric
  • 7,421
  • 1
  • 37
  • 65
  • Do you have `WS_CLIPSIBLINGS` style in your dialog? If not, the controls may draw above each other regardless to z-order. Anyway, you should check the **actual** z-order of your windows (by win-spy). – valdo Dec 10 '11 at 15:34
  • Clip siblings property of a dialog is set to true. I did inspected the running app with Spy++ but not found where can I read about control's z-order. – David Unric Dec 10 '11 at 18:06
  • Here : http://stackoverflow.com/questions/160105/how-can-you-bring-a-control-to-front-in-mfc – Software_Designer Dec 10 '11 at 19:50
  • @Michael> Unfortunately this does not covers my issue, ie. ignoring z-order after a control changes its topleft coordinates. – David Unric Dec 10 '11 at 20:26
  • @David Unric - Spy++ orders sibling controls by Z-order in the Windows view. Also, selecting properties, the Prev Window and Next Window indicate Z-order – Ken Richards Aug 15 '13 at 15:46

1 Answers1

2

The answer is plain simple. I did just overlooked one flag in SetWindowPos documentation. To prevent z-order changing just pass SWP_NOZORDER flag, so the function call should look like:

m_stMyStatic.SetWindowPos(NULL, xpos, ypos, 0, 0, SWP_NOSIZE | SWP_NOZORDER); 
David Unric
  • 7,421
  • 1
  • 37
  • 65