title: Hiding an MFC dialog box
body: <p>Ok so I am using this code to hide the taskbar icon of a dialog based MFC application(VC++). The taskbar icon and the dialog box hide whenever I click on the cross or the close buttons. But I can’t get this one thing right. Whenever I hit the close or the cross button from title bar, the dialog box first flickers and shows a sort of intermediate dialog box and then hides. This is very annoying. I am posting my code here after two days of vain effort. So guys please help me. Thanks in advance.</p>
  
  <pre><code>void CMyAppDlg::OnBnClickedCancel()
  {
    // TODO: Add your control notification handler code here
    CWnd* pWnd;
    pWnd = AfxGetMainWnd();
  
    RemoveTaskbarIcon(pWnd);
    pWnd-&gt;ModifyStyle(WS_VISIBLE, 0);
    mVisible = FALSE;
  }
  
  BOOL CMyAppDlg::RemoveTaskbarIcon(CWnd* pWnd)
  {
    LPCTSTR pstrOwnerClass = AfxRegisterWndClass(0);
  
    // Create static invisible window
    if (!::IsWindow(mWndInvisible.m_hWnd))
     {
      if (!mWndInvisible.CreateEx(0, pstrOwnerClass, _T(""),
               WS_POPUP,
               CW_USEDEFAULT,
               CW_USEDEFAULT, 
               CW_USEDEFAULT, 
              CW_USEDEFAULT,
               NULL, 0))
        return FALSE;
     }
  
     pWnd-&gt;SetParent(&amp;mWndInvisible);
  
    return TRUE;
  }
  </code></pre>
  
  <p>Here are the screen shots of dialog box. When I press the close or cross button, the dialog box which looks like <a href="http://i.imgur.com/doFdK.png" rel="noreferrer">this</a>  in the first place turns into <a href="http://i.imgur.com/JUoFY.png" rel="noreferrer">this</a>  for like less than half a second and then disappears (hides).</p>