隐藏 MFC 对话窗口

2022-01-12 00:00:00 winapi visual-c++ mfc

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?

解决方案

Solution to the above issue. The InitInstance code should be as follows:

BOOL CMyApp::InitInstance()
{
    CWinApp::InitInstance();
    AfxEnableControlContainer();

    CMyAppDlg dlg;
    dlg.Create(IDD_MyAppUI_DIALOG,NULL);
    dlg.ShowWindow(SW_HIDE);
    dlg.UpdateWindow();
    m_pMainWnd = &dlg;

    return TRUE;
}

相关文章