1. 獲得當前進程路徑
CString path = "";
CString Filepath=AfxGetApp()->m_pszHelpFilePath; // ....\Debug\xxxx.HLP
CString Exename=AfxGetApp()->m_pszExeName; //xxxx
path=Filepath.Left(Filepath.GetLength() - Exename.GetLength()-4); //...\Debug\
//減去4的原因是AfxGetApp()->m_pszHelpFilePath獲取的路徑有後綴名.HLP 比AfxGetApp()->m_pszExeName獲取的可執行文件名長度大4
//減去4時path爲 ....\Debug\ (即獲取的是當前進程路徑)
2. ShellExcute用於打開指定路徑的文件與網頁
HINSTANCE ShellExecute(
HWND hwnd, //窗口句柄
LPCTSTR lpOperation,//指定動作,open,print,edit...
LPCTSTR lpFile, //指定要打開的文件或程序
LPCTSTR lpParameters,//給要打開的程序指定參數; 如果打開的是文件這裏應該是NULL
LPCTSTR lpDirectory, //缺省目錄
INT nShowCmd //打開選項 MSDN詳細解釋
)
path += “Hello.exe”;
//執行Hello.exe可執行文件
ShellExecute(NULL,"open",path,NULL,NULL,SW_SHOWNORMAL); //打開由1獲取路徑下的Hello.exe
//打開百度網頁
ShellExecute(NULL,"open","http://www.baidu.com",NULL,NULL,SW_SHOWNORMAL);