如何在MFC应用程序中获取命令行参数? [英] How to get the command line arguments in MFC applications?
问题描述
我希望有一个小型的基于对话框的应用程序,该应用程序传递了命令行参数,因此,使用VC ++ 6,我运行了应用程序向导并选择了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.
这不会自动配备命令行参数.所以我去了 MSDN来刷新我的记忆. MSDN指出所有C ++程序 具有main()或wmain()函数以及argc等参数 到这里.我刚刚创建的应用程序没有这些.
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.
因为显然有一个功能是应用程序的入口,所以可以 我在这里坚持论点吗?我确实尝试过,但是我不相信我 实际上是在编辑正确的功能. (我能找到哪个功能 是从项目设置或类似设置中充当main()函数?)
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.
也作为副业.对于一个简单的程序,我真的不知道 希望使其成为MFC应用程序,因此大小超过MB.是否有应用程序向导模板库可让我创建非MFC对话框 申请吗?
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?
推荐答案
Use GetCommandLine(), which returns the name of the file being executed, followed by the arguments.
应用程序成员 m_lpCmdLine (与yourApp.m_lpCmdLine
一样使用)仅包含参数.
The application member m_lpCmdLine (used like yourApp.m_lpCmdLine
) contains only the arguments.
还有也可以尝试使用ATL COM向导来创建非MFC对话框应用程序(选择.exe选项,而不是.dll).
Also try the ATL COM wizard to create a non-MFC dialog application (chose the .exe option, not .dll).
这篇关于如何在MFC应用程序中获取命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!