怎样得到程序的绝对路径,以及怎样表示相对路径??

解决方案 »

  1.   

    用GetModuleFileName()可以得到程序的绝对路径。
      

  2.   


    //得到当前工作路径
        char Path[512];
        CString RunPath;
        GetCurrentDirectory(512, Path);
        RunPath.Format("%s", Path);//得到可执行文件目录(可得到当前工作路径及可执行文件名)
        CString RunPath;
        int PathLength;
        ::GetModuleFileName(::AfxGetInstanceHandle(), RunPath.GetBuffer(1024), 1024);
        RunPath.ReleaseBuffer(-1);    for (PathLength=RunPath.GetLength()-1; PathLength>=0; PathLength--)
        {
         if (RunPath.GetAt(PathLength) == '\\')
         break;
        }
        CString FileName, CurPath;
        CurPath = RunPath.Left(PathLength);
        FileName = RunPath.Mid(PathLength+1);
        
        //AfxMessageBox(RunPath+_T("--")+CurPath+_T("--")+FileName, MB_ICONINFORMATION);