The following example can be used to determine whether the -c, -s or -p option is used when the program is running, and everyone can make simple changes in the specific program.
Step 1: Reduce a class CWZDCommandLineInfo from CCommandLineInfo, the implementation is as follows
#if! defined WZDCommandLineInfo_H
#define WzdcommandLineInfo_H
// WZDCommandLineInfo.h: Header File
//
// CWZDCommandLineInfo Window
Class CWZDCommandLineInfo: Public CCommandLineInfo
{
// construction
PUBLIC:
CWZDCommandLineInfo ();
// attributes
PUBLIC:
BOOL M_BCFLAG;
BOOL M_BSFLAG;
BOOL M_BPFLAG;
CSTRING M_SARG;
// Operations
PUBLIC:
Void Param (Const Tchar * Pszparam, Bool Bflag, Bool Blast);
// Overrides
// Implementation
PUBLIC:
Virtual ~ CWZDCommandLineInfo ();
}
//
#ENDIF
The end file is over, the following is a CPP file
// WZDCommandLineInfo.cpp: Implementation File
//
#include "stdafx.h"
#include "wzdcommandlineinfo.h"
#ifdef _Debug
#define new debug_new
#undef this_file
Static char this_file [] = __file__;
#ENDIF
//
// CWZDCommandLineInfo
CWZDCommandLineInfo :: CWZDCommandLineInfo ()
{
m_bcflag = false;
m_bsflag = false;
m_bpflag = false;
m_sarg = _t ("");
}
CWZDCommandLineInfo :: ~ cwzdcommandlineinfo ()
{
}
//
Void CWZDCommandLineInfo :: PaSEPARAM (Const Tchar * Pszparam, Bool Bflag,
Bool Blast)
{
CString Sarg (pszparam);
IF (bflag)
{
m_bcflag =! sarg.comparenocase ("C");
m_bsflag =! sarg.comparenocase ("s");
m_bpflag =! sarg.comparenocase ("P");
}
// m_strfilename Gets the first nonflag name
Else IF (m_strfilename.isempty ())
{
m_sarg = sarg;
}
CCommandLineInfo :: PaSEPARAM (Pszparam, Bflag, Blast);
}
Step 2: Add a member variable in the App class:
PUBLIC:
CWZDCommandLineInfo m_cmdinfo;
Step 3: Modify the following code in the InitInstance () function
// Parse Command Line for Standard Shell Commands, DDE, File OpenParseCommandline (M_CMDInfo);
// Dispatch Commands Specified on The Command Line
IF (! ProcessShellcommand (m_cmdinfo))
Return False;
This can be obtained at other parts of the program to obtain the CWZDCommandLineInfo object through AFXGetApp () -> m_cmdinfo, and then determine which option is running with the member variable m_bcflag, etc.