开发者

How do I bypass GUI in MFC app if command line options exist?

I've got an existing simple MFC app that the user sp开发者_Python百科ecifies the input file, output file, and then a "Process" button. I'd like to just add the capability so that the input/output files are command line parameters. But, if they exist, I don't want the GUI to show up. I just want the "Process" to execute. I see where I can get the command line parameters (m_lpCmdLine) but how can I bypass the displaying of the GUI? If I step into the app, it goes directly to winmain.cpp and displays the GUI without stepping into any of my code.


MFC sets up a class that will be called C[Your App Name]App (e.g CExampleApp) store in [Your App Name].h/.cpp (e.g Example.h/.cpp) In here you will have a function called "InitInstance" (again auto generated by MFC). If you have created a Dialog based app then you'll have a bit of code that looks like this in the function:

CExampleDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
}

Specifically the "dlg.DoModal()" call will call your dialog window. If you avoid that then the GUI will never start.

If you are using an MDI app then you'll have some code like this:

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
    return FALSE;
m_pMainWnd = pMainFrame;

pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();

This creates and shows your main window. Avoid this and no window will be created. You MUST however return FALSE from the InitInstance function, though or it will enter the application message pump.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜