CString CommandLine = GetCommandLine();
for(i=0;i<CommandLine.GetLength();i++)
{
if(CommandLine[i]=='-')
{
//处理后面的字符
}
}
其他用法
int ParamCount()
{
CString CommandLine = GetCommandLine();
int i, n = 0;
BOOL f = false, v = false;
for (i = 0; i < CommandLine.GetLength(); i++)
{
if (CommandLine[i] == 0x22)
{
f = !f;
if (f) n++;
continue;
}
if (!f) //不在引号之内
{
if (v && (CommandLine[i] == 0x20)) n++;
v = (CommandLine[i] != 0x20); //遇到非空格,认为是有效参数
}
}
return n;
}
CString ParamStr(int Index = 0)
{
CString CommandLine = GetCommandLine(), Param;
int i, n = 0, p1 = -1, p2 = -1;
BOOL f = false, v = false;
for (i = 0; i < CommandLine.GetLength(); i++)
{
if (CommandLine[i] == 0x22)
{
f = !f;
if (f)
{
n++;
p1 = i + 1;
p2 = -1;
}
else
p2 = i;
continue;
}
if (!f) //不在引号之内
{
if (v)
{
if (CommandLine[i] == 0x20)
{
n++;
p2 = i;
}
if (i == CommandLine.GetLength() -1)
{
n++;
p2 = CommandLine.GetLength();
}
}
if (!v && (CommandLine[i] != 0x20))
{
p1 = i;
p2 = -1;
}
v = (CommandLine[i] != 0x20);
}
if ((n == (Index + 1)) && (p1 != -1) && (p2 != -1))
{
Param = CommandLine.Mid(p1, p2 - p1);
break;
}
}
return Param;
}