MFC-命令行参数用法摘要

#include "windows.h"
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
	CCmdP cmdinfo;
	ParseCommandLine(cmdinfo);
	if (cmdinfo.m_bAFlag) {
		AfxMessageBox(_T("a"));
	}
	if (cmdinfo.m_bBFlag)
	{
		AfxMessageBox(_T("b"));
	}
	if (cmdinfo.m_bCFlag)
	{
		AfxMessageBox(_T("c"));
	}
	vector<CString>::iterator coll;
	for (coll = cmdinfo.m_sArg.begin(); coll != cmdinfo.m_sArg.end();++coll)
	{
		AfxMessageBox(*coll);
	}
	return 0;
}

class CCmdP : public CCommandLineInfo
{
public:
	BOOL m_bAFlag;
	BOOL m_bBFlag;
	BOOL m_bCFlag;
	vector<CString> m_sArg;
	CCmdP();
	virtual void ParseParam(
		const TCHAR* pszParam,
		BOOL bFlag,
		BOOL bLast
		);
	~CCmdP();
};
CCmdP::CCmdP()
{
	m_bAFlag = m_bBFlag = m_bCFlag = FALSE;
}

void CCmdP::ParseParam(
	const TCHAR* pszParam,
	BOOL bFlag,
	BOOL bLast
	) 
{
	CString sArg(pszParam);
	if (bFlag)
	{
		if (!sArg.CompareNoCase(_T("a"))) {
			m_bAFlag = TRUE;
		}
		if (!sArg.CompareNoCase(_T("b"))) {
			m_bBFlag = TRUE;
		}
		if (!sArg.CompareNoCase(_T("c"))) {
			m_bCFlag = TRUE;
		}
	}
	else if(m_strFileName.IsEmpty())
	{
		m_sArg.push_back(sArg);
	}

}


CCmdP::~CCmdP()
{
}

你可能感兴趣的:(MFC-命令行参数用法摘要)