调用外部EXE程序 ShellExecuteA与 m_GetCurAppPath的一些使用求纠正一下
我的思路:是想在单机事件里面触发使用外部的EXE文件,自动获取当前mfc文件路径下的其他可执行exe,但是接触mfc并不多,所以虚心请教------下面附上button1的代码,如果有需要我也可以发源文件,求指正
#include "stdafx.h"
#include "YANGSHIQI.h"
#include "YANGSHIQIDlg.h"
#include "stdlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
static bool m_GetCurAppPath(CString* mmstr,CString parm) ;//声明不知道是不是要加在这
#endif
/////////////////////////////////////////////////////////////////////////////
中间是系统自带,没有改动,就不发了
/////////////////////////////////////////////////////////////////////////////
bool m_GetCurAppPath(CString* mmstr,CString parm) //自己加的
{ //首先得到帮助文件的路径
CString strFullName = AfxGetApp()->m_pszHelpFilePath;
char drive[_MAX_DRIVE]; //#include <stdlib.h>
char dir[_MAX_DIR];
_splitpath(strFullName, drive, dir, NULL,NULL);
CString strPath;
strPath.Format("%s%s", drive, dir); //strPath即为得到的当前运行程序所在目录
strPath += parm; *mmstr = strPath;
return false;
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CYANGSHIQIDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CYANGSHIQIDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString cpath;
m_GetCurAppPath(&cpath,"\YANGSHIQI.exe");
ShellExecuteA(NULL,"open","cpath",NULL,NULL,SW_SHOW);
fflush(stdin);
}