MFC对话框程序中的命令行参数有关问题
MFC对话框程序中的命令行参数问题
我刚在调一台机器,使用MFC对话框写一个界面来控制机器。
需要调用自带的Aria库函数来实现它于PC的连接。示例代码中需要命令行参数:
我现在使用的方法是,将argc和argv作为CRobotClient类(自己创建的类)中的成员,在构造函数中直接将argc赋值0,argv赋值NULL。
在网上看到,可以使用GetCommandLine()和ParseCommandLine() 之类的函数来获得命令行参数,但是具体的实现方法我看不太懂。
请问,如何使用它们,该把代码放到哪里呢?(新手,勿拍砖)谢谢各位了!
------解决方案--------------------
BOOL CMyWinApp::InitInstance()
{
...
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// DON'T display a new MDI child window during startup!!!
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
...
};
------解决方案--------------------
GetCommandLine()
代码可以放到App类的InitInstance函数中
------解决方案--------------------
GetCommandLineW()得到完整命令行,然后利用CommandLineToArgvW()得到各个参数信息
我刚在调一台机器,使用MFC对话框写一个界面来控制机器。
需要调用自带的Aria库函数来实现它于PC的连接。示例代码中需要命令行参数:
int main(int argc, char **argv)
{
Aria::init();
ArArgumentParser parser(&argc, argv);/*这里需要命令行参数*/
parser.loadDefaultArguments();
ArRobot robot;
// Connect to the robot, get some initial data from it such as type and name,
// and then load parameter files for this robot.
ArRobotConnector robotConnector(&parser, &robot);
if(!robotConnector.connectRobot())
/*以下代码省略*/
...
...
}
我现在使用的方法是,将argc和argv作为CRobotClient类(自己创建的类)中的成员,在构造函数中直接将argc赋值0,argv赋值NULL。
在网上看到,可以使用GetCommandLine()和ParseCommandLine() 之类的函数来获得命令行参数,但是具体的实现方法我看不太懂。
请问,如何使用它们,该把代码放到哪里呢?(新手,勿拍砖)谢谢各位了!
mfc
命令行参数
------解决方案--------------------
BOOL CMyWinApp::InitInstance()
{
...
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// DON'T display a new MDI child window during startup!!!
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
...
};
------解决方案--------------------
GetCommandLine()
代码可以放到App类的InitInstance函数中
------解决方案--------------------
GetCommandLineW()得到完整命令行,然后利用CommandLineToArgvW()得到各个参数信息