我用CFileDialog打开一个文件,现在需要得到这个文件的相对路径,vc中有没有现成的函数?
如果没有,那么CFileDialog::GetPathName()只能返回完整的绝对路径,怎么转成相对路径?

解决方案 »

  1.   

    GetModuleFileName这个好象是,具体方法楼主可查阅msdn
      

  2.   

    相对于 project的工作目录 的路径。要用到的文件都和project在同一根目录下的。
    这些路径要写到配置文件中,用相对路径是为了程序便于在其他机器上运行。
      

  3.   

    借花献佛:(MSDN上有)
    #include <windows.h>
    #include <iostream.h>
    #include "Shlwapi.h"void main(void)
    {
        char szOut[MAX_PATH] = "";
        char szFrom[ ] = "c:\\a\\b\\path";
        char szTo[ ] = "c:\\a\\x\\y\\file";    cout  <<  "The relative path is relative from: ";
        cout  <<  szFrom;
        cout  <<  "\n";    cout  <<  "The relative path is relative to: ";
        cout  <<  szTo;
        cout  <<  "\n";    PathRelativePathTo(szOut,
                           szFrom,
                           FILE_ATTRIBUTE_DIRECTORY,
                           szTo,
                           FILE_ATTRIBUTE_NORMAL);    cout  <<  "The relative path is: ";
        cout  <<  szOut;
        cout  <<  "\n";
    }OUTPUT:
    ==================
    The relative path is relative from: c:\a\b\path
    The relative path is relative to: c:\a\x\y\file
    The relative path is: ..\..\x\y\file
      

  4.   

    GetCurrentWorkDirectory  你应该是在找这个函数吧。
      

  5.   

    To WangK
    PathRelativePathTo! Thanks~