如何获取MFC应用程序中的命令行参数?
我希望有一个基于对话框的小型应用程序,它传递命令行参数,因此,我使用 VC++6 运行应用程序向导并选择 MFC 对话框应用程序。
这不会自动配备命令行参数。所以我去了 到 MSDN 来刷新我对这些的记忆。 MSDN 指出所有 C++ 程序 有 main() 或 wmain() 函数以及 argc 等参数 去这里。我刚刚创建的应用程序没有这些。
由于显然有一个函数是应用程序的入口点,因此可以 我把论点放在这里?我确实尝试过这个,但我不相信我 实际上正在编辑正确的函数。 (我能找到这个函数吗? 充当项目设置中的 main() 函数或类似函数?)
基本上,我如何让我的程序读取命令行参数。
也当副业。对于一个简单的程序,这就是我真的不 希望使其成为一个 MFC 应用程序,从而使其大小超过 1 MB。是否有应用程序向导模板库允许我制作非 MFC 对话框 应用?
I wish to have a small dialog based application which is passed command line parameters, so, using VC++6 I ran the application wizard and chose an MFC dialog application.
This is not automatically equipped with command-line parameters. So I went
to MSDN to refresh my memory on these. MSDN states that all C++ programs
have either a main() or a wmain() function and that the argc, etc. arguments
go here. The application I just created does not have these.
As there is obviously a function which is the entry point to the application, can
I stick the arguments here? I did try this, but I am not convinced that I
was actually editing the correct function. (Can I find the function which
is acting as the main() function from the project settings or similar?)
Basically, how do I get my program to read command line parameters.
Also as a sideline. For a simple program, which this is, I really do not
want to make it an MFC application, and thereby over a MB in size. Are there application wizard template libraries that will allow me to make a non-MFC dialog
application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 GetCommandLine() ,返回正在执行的文件的名称,
接下来是论据。
应用程序成员m_lpCmdLine(像
yourApp.m_lpCmdLine
一样使用)仅包含参数。还有 CWinApp ::ParseCommandLine() 您可能会发现很有用。
还可以尝试使用 ATL COM 向导创建非 MFC 对话框应用程序(选择 .exe 选项,而不是 .dll)。
Use GetCommandLine(), which returns the name of the file being executed,
followed by the arguments.
The application member m_lpCmdLine (used like
yourApp.m_lpCmdLine
) contains only the arguments.There is also CWinApp::ParseCommandLine() that you may find useful.
Also try the ATL COM wizard to create a non-MFC dialog application (chose the .exe option, not .dll).
是的,请参阅 CWinApp:ParseCommandLine。另请查看 CCommandLineInfo 类。
Yes, see CWinApp:ParseCommandLine. Also take a look at the CCommandLineInfo class.
在 MFC 应用程序中,入口点函数是“initInstance()”,如
main()
或wmain()
。在initInstance()
中使用CWinApp::m_lpCmdLine
访问命令行。In MFC applications, the entry point function is 'initInstance()', like
main()
orwmain()
. UseCWinApp::m_lpCmdLine
ininitInstance()
to access the command line.要获取原始命令行,请使用以下代码(适用于任何 Win32 / MFC 应用程序):
当没有给出参数时,nArgc 应为 1;当有参数时,nArgc 应大于 1。然后,pArgv[1] 将是第一个参数,依此类推......
To get the raw command line use the following code (will work on any Win32 / MFC application):
nArgc should be 1 when no arguments given and larger than 1 when there are. Then, pArgv[1] will be the first argument, and so on...