CCommandLineInfo is a MFC class that can be used to parse the command line of the executable. This is a very useful one and is easy to impliment.
If you create a MFC application with the application wizard you will get the lines CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
in the app class´s InitInstance method.
ParseCommandLine will call ParseParam in CCommandLineInfo. To parse your own command line params, derive a class from CCommandLineInfo and override ParseParam method:
void CTestCommandLineInfo::ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast ){
if(bFlag)
{
if(lpszParam .strCompareNoCase('sumtext')
{
//some code to deal with the string value associated with lpszParam )
}
state = _0;
}
}
CCommandLineInfo::ParseParam( lpszParam, bFlag, bLast );
}
If you need to parse flags only, you do not need to invent a state system. Then it is enough to ask for bFlag and set some static variable for the parameter given in lpszParam. But if you want to handle parameters with values, you need to set a private state variable if the parameter name is parsed and set the appropriate static variable if the actual value is parsed .
Tuesday, March 17, 2009
Subscribe to:
Post Comments (Atom)

what's this pal!!!!!!
ReplyDelete