MFC Dialog: How to start your dialog application in hidden mode?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: MFC Dialog: How to start your dialog application in hidden mode?

Threaded View

  1. #1
    Join Date
    Dec 2001
    Location
    Canada/Montreal
    Posts
    983

    MFC Dialog: How to start your dialog application in hidden mode?

    Q: How to start your dialog application in hidden mode?

    A: If you put the function 'ShowWindow(SW_HIDE)' in your 'OnInitDialog()', it won't have any effect, because 'OnInitDialog()' always finishes with calling 'ShowWindow(SW_SHOW)'. But there is a workaround for that. Create a 'BOOL' member variable into your dialog class and set it to 'FALSE' in the constructor.

    Code:
    class CYourDialog : public CDialog
    {
      ...
    
    private:
      BOOL m_visible;
    };
    
    
    CYourDialog::CYourDialog(CWnd* pParent /*=NULL*/)
      : CDialog(CYourDialog::IDD, pParent)
    {
      //...
      m_visible = FALSE;
    }
    Now override the 'WM_WINDOWPOSCHANGING' message handler. Your code should look something like this to hide the dialog:

    Code:
    void CYourDialog::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
    {
      if(!m_visible)
      {
        lpwndpos->flags &= ~SWP_SHOWWINDOW;
      }
    
      CDialog::OnWindowPosChanging(lpwndpos);
    }
    To make the dialog again visible, use the following code:

    Code:
    //...
    m_visible = TRUE;
    ShowWindow(SW_SHOW);
    //...

    Last edited by Andreas Masur; September 4th, 2005 at 11:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center