Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide an MFC dialog window

I have written an MFC dialog based application which is launched by some another application. For now, I have not added any code. It is just the default files that I got. The other application can successfully launch my application.

I am trying to hide the window of my application when the other application launches it.

BOOL CMyApp::InitInstance()
{
    CMyAppDlg dlg;
    m_pMainWnd = &dlg;        

    INT_PTR nResponse = dlg.DoModal();

    if (nResponse == IDOK)
    {
    }
    else if (nResponse == IDCANCEL)
    { 
    }

    return FALSE;
}

I tried to use:

dlg.ShowWindow(SW_HIDE) 

but it still does not hide the window.

How can I accomplish this task?

like image 986
chintan s Avatar asked Oct 12 '12 10:10

chintan s


People also ask

How do I display dialog in MFC?

To create a modal dialog box, call either of the two public constructors declared in CDialog. Next, call the dialog object's DoModal member function to display the dialog box and manage interaction with it until the user chooses OK or Cancel. This management by DoModal is what makes the dialog box modal.

How do I resize a dialog box in MFC?

Solution 1. this->SetWindowPos(NULL,0,0,newWidth,newHeight,SWP_NOMOVE | SWP_NOZORDER); This will change the size of the dialog, but you will need to move and resize the control inside the dialog using the same function but with the CWnd of the control.


1 Answers

I'd suggest you have another problem someplace.

If you create a totally new, blank MFC app (Visual Studio 2010) then in App::InitInstance, setting SW_HIDE rather than SW_SHOW does cause the resultant window to be hidden.

BOOL CProj1App::InitInstance()
{

// boilerplate code
      . . . 

// The one and only window has been initialized, so show and update it
m_pMainWnd->ShowWindow(SW_HIDE);   // WORKS!
m_pMainWnd->UpdateWindow();

return TRUE;
}
like image 187
PeteH Avatar answered Oct 17 '22 13:10

PeteH