An MFC application can use member function ParseParam() of class CCommandLineInfo to handle some standard flags. For add our's flag with other flags support,we should derive our class and overlaid ParseParam().
1、create a new CCommandLineInfo class
(1) in the new class, add new member variables for new flags.
(2) overlaid base class member function ParseParam()
(3) ParseParam() implement
(4) more information about CCommandLineInfo list at the end of this article
2、Add the new command class in application
(1) To find ParseCommandLine() in application, and replace CCommandLineInfo by new class
(2) To make these option aviable in whole application, embed cmdInfo to application and access its member variable.
AfxGetApp()->m_cmdInfo.m_bXXFlag;
reference
标准M F C标志如下,真正处理这些标准命令行发生在ProcessShellCommand (cmdInfo)
中,它正好在应用程序类中ParseCommandLine( )之后。
n o t h i n g 使应用程序试图打开一个新文档
f i l e n a m e 使应用程序试图以文档方式打开文件名
/p filename 使应用程序打开并打印给定的文件名到默认的打印机
/pt filename 与上面相同,但输入到指定的打印机
printer driver port
/ d d e 使应用程序开始运行,并等待D D E命令
/ A u t o m a t i o n C O M标志
/ E m b e d d i n g
/ U n r e g i s t e r
/ U n r e g s e r v e r
■ 处理非标准标志(如名字)会有点复杂,我们认为出现的第一个非标准标志是文档文件名。
然而,一旦一个文件名被发现,可以根据目的攫取任何非标准标志,这就是说,除非
遇到/ p t标志,在这种情况下,下面三个非标准标志变量用来初始化打印。为了简化起
见,也可通过不把/ p t标志传递给基类中的ParseParam( )来禁用/ p t标志。
■ 当然,如果不需继续支持前面所示的标准M F C标志,则可以更加自由地行动。只要不
用调用基类的ParseParam( ),可以使用任何标志或非标准标志选项。但是,不要因为能
用非标准标志,而轻易放弃这些标准标志提供的功能。
评论