得到運行程序所在路徑:(其實得到的是當前執行程序存放路徑)。
TCHAR szFilePath[MAX_PATH + 1];
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(_tcsrchr(szFilePath, _T('\\')))[1] = 0;
CString strtemp=szFilePath;
函數說明:
GetModuleFileName:The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.
得到程序當前工作路徑:(因為程序在運行過程中,會改變工作路徑)
char pBuf[MAX_PATH]; //存放路徑的變量
GetCurrentDirectory(MAX_PATH,pBuf); //獲取程序的當前目錄
strcat(pBuf,"\\");
CString strtemp=pBuf;
函數說明:
GetCurrentDirectory:The GetCurrentDirectory function retrieves the current directory for the current process