获得文件启动位置.txt

来自「可以获得文件执行程序的启动位置。 通过执行程序调用」· 文本 代码 · 共 34 行

TXT
34
字号
CString CFilePath::GetExecPath()
{//获得文件的启动位置
	CString cl = GetCommandLine();
	int count = cl.GetLength();
	int  lastY;//引号的位置
	lastY = cl.Find("\"", 1);
	//获得最后一个"\"的位置
	if(lastY > 0)
		cl = cl.Left(lastY);
	else
	{//找第一个空格的位置
		int space = cl.Find(" ", 0);
		if(space > 0) cl = cl.Left(space);
	}//
	int dash = -1;
	int temp;
	while(TRUE)
	{
		temp = cl.Find("\\", dash + 1);
		if(temp < 0) break;
		dash = temp;
	}
	if(dash == -1) return "";//为当前的路径的启动
	
	if(lastY > 0)
	{//存在引号
		//
		cl = cl.Left(dash);
		cl = cl.Right(cl.GetLength() - 1);//除掉第一个引号
		return cl;
	}
	else
		return cl.Left(dash);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?