zoukankan      html  css  js  c++  java
  • 【转】VC获取当前程序文件的路径,文件名以及路径+文件名

    1.方法1

        TCHAR pBuf[MAX_PATH];                               //存放路径的变量
        GetCurrentDirectory(MAX_PATH, pBuf);                //获取程序的当前目录
        _tcscat_s(pBuf, _T("\"));
        _tcscat_s(pBuf, AfxGetApp()->m_pszExeName);
        _tcscat_s(pBuf, _T(".exe"));                        //获取程序的全文件名

    2.方法2

    //函数返回应用程序所在的路径 
    CString ReturnPath()
    {
        CString    sPath;
        GetModuleFileName(NULL, sPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
        sPath.ReleaseBuffer();
        int    nPos;
        nPos = sPath.ReverseFind(_T('\'));
        sPath = sPath.Left(nPos);
        return    sPath;
    }

     ----------------------------------------------------------------------------------------

    CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("All Files(*.*)|*.*||"));
        if (fileDlg.DoModal() == IDOK){
            m_strPath2 = fileDlg.GetPathName();     // 获取文件路径
            SetDlgItemText(EDIT2, m_strPath2);
            m_strFileName2 = fileDlg.GetFileName();  // 获取文件名
        }
  • 相关阅读:
    数据仓库的一些理解(转)
    常见ETL工具一览,你知多少?
    dhcpv6开源软件配置
    svn
    js原型模式
    combo扩展:禁止手工改变输入框的值
    SQLite错误总结 error code 19: constraint failed
    ntp源码解读(一)
    ntp-keygen.c
    6.2.2认证
  • 原文地址:https://www.cnblogs.com/Lthis/p/4313891.html
Copyright © 2011-2022 走看看