我如何绕过GUI在MFC应用程序,如果命令行选项存在吗? [英] How do I bypass GUI in MFC app if command line options exist?

查看:265
本文介绍了我如何绕过GUI在MFC应用程序,如果命令行选项存在吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了用户指定的输入文件,输出文件,然后处理按钮现有的简单的MFC应用程序。我想刚才添加的功能使输入/输出文件的命令行参数。但是,如果存在的话,我不希望GUI显示出来。我只是想在过程来执行。我看到那里我能得到的命令行参数(m_lpCmdLine),但我怎么能绕过GUI的显示?如果我步入应用程序,它直接进入winmain.cpp并显示GUI没有踏进我的任何code的。

I've got an existing simple MFC app that the user specifies 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建立了一个将被调用C [您的应用程序名称]应用(如CExampleApp)店[您的应用程序名称] .H /的.cpp(类如example.h文件/的.cpp)在这里,你将有名为InitInstance中由MFC产生的(再次自动)功能。如果您已经创建了一个基于对话框的应用程序,那么你将有一个位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
}

明确了dlg.DoModal()调用会打电话给你的对话窗​​口。如果您避免则GUI将不会开始。

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

如果您使用的是MDI应用程序,然后你就会有一些code是这样的:

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();

这将创建并显示你的主窗口。避免这种情况,将创建任何窗口。然而,你必须返回从InitInstance函数FALSE,但还是将进入应用程序消息泵。

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.

这篇关于我如何绕过GUI在MFC应用程序,如果命令行选项存在吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆