How to keep Z-order of a control in MFC dialog?


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 ?






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); 

原文地址:https://www.cnblogs.com/hzcya1995/p/13318526.html