アプリケーション起動時のウィンドウ表示処理

CWinApp::InitInstance() の中でアプリケーションを終了させた場合に、一瞬ウィンドウが表示されてしまうのを防ぐ方法。


結論としては

    m_nCmdShow = SW_HIDE;

とする事でウィンドウの表示は行われなくなる。
ただし、ウィンドウの描画処理は ProcessShellCommand() の呼び出しの中で行われるため CWinApp::m_nCmdShow への値の設定は ProcessShellCommand() の前に行う必要がある。


以下、メモ。
呼び出し経路
CWinApp::InitInstance()
CWinApp::ProcessShellCommand()
CWinApp::OnFileNew()
CDocManager::OnFileNew()
CSingleDocTemplate::OpenDocumentFile()
CDocTemplate::InitialUpdateFrame()
CFramewnd::InitialUpdateFrame()
CFrameWnd:: ActivateFrame()


void CFramewnd::InitialUpdateFrame(CDocument* pDoc, BOOL bMakeVisible)
の中で CWinApp クラスから値を取り出している。

CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this) {
    nCmdShow = pApp->m_nCmdshow; // use the parameter from WinMain
    pApp->m_nCmdshow = -1; // set to default after first time
}
ActivateFrame(nCmdShow);


void CFrameWnd:: ActivateFrame(int nCmdShow)
の中で表示処理が行われる。