5/06/2013

The best way to appear dialog invisibly when dialog is created

For this, 'WM_WINDOWPOSCHANGING' is used.

If we use WM_CREATE or WM_INITDIALOG and then, call ShowWindow(SW_HIDE),
we will firstly see a dialog, after that, it will be disappear.

Below code shows how to use WM_WINDOWPOSCHANGING in WTL.

LRESULT CHideDialog::OnWindowPosChanging(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
 LPWINDOWPOS lpwndpos = (LPWINDOWPOS)lParam;
 if (FALSE == m_isVisible)
 {
  lpwndpos->flags &= ~SWP_SHOWWINDOW;
 }
 else
 {
  lpwndpos->flags |= SWP_SHOWWINDOW;
 }
 return 0;
}

As we see, the value of  m_isVisible decides on whether dialog is visible.
So, if we call below function, after setting the value of m_isVisible to TRUE,
the dialog will be appear again.

::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

No comments:

Post a Comment