如何用MFC打开一个EXE文件? 如何用eclipse打开一个文件

作者&投稿:初净 (若有异议请与网页底部的电邮联系)
打开程序用
WinExec("程序路径",SW_SHOW);
关闭自己用exit(0);
关闭别的程序,首先获得程序的PID,然后

int TerminateProcessFromId(DWORD dwId) //关闭进程
{
BOOL bRet=FALSE;

HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwId);
if(hProcess!=NULL)
{
bRet=::TerminateProcess(hProcess,0);
}

::CloseHandle(hProcess);

if(bRet)
printf("%d 进程结束成功......\n\n\n\n",dwId);
else
printf("%d 进程结束失败......\n\n\n\n",dwId);

return 0;
}

调用这个函数就可以:
UINT WinExec(
LPCSTR lpCmdLine, // 输入你要打开的EXE文件路径
UINT uCmdShow // 可以选择SW_SHOW 或SW_HIDE
);
具体实现:
--------------------------------------------
WinExec("D:\采金子.exe",SW_HIDE);
--------------------------------------------如果你要打开文本文件或是打开一个网络的链接 你可以调用 ShellExecute函数 用法参考MSDN。
最后祝你成功!

TCHAR szCmdLine[512];
HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());
wsprintf(szCmdLine, __TEXT("%s %d"), "c:\采金子.exe", hProcessOrig);
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
if( CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) )
{
}
else
{
}

CloseHandle(hProcessOrig);

ShellExecute( NULL,"open", "D:\采金子.exe ",NULL,NULL,SW_SHOWNORMAL);

WinExec
The WinExec function runs the specified application.

Note This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.

UINT WinExec(
LPCSTR lpCmdLine, // command line
UINT uCmdShow // window style
);
Parameters
lpCmdLine
[in] Pointer to a null-terminated character string that contains the command line (file name plus optional parameters) for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence:
The directory from which the application loaded.
The current directory.
The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
The directories listed in the PATH environment variable.
uCmdShow
[in] Specifies how a Windows-based application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO parameter to the CreateProcess function. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function. For a non-Windows – based application, the PIF file, if any, for the application determines the window state.
Return Values
If the function succeeds, the return value is greater than 31.

If the function fails, the return value is one of the following error values:

Value Meaning
0 The system is out of memory or resources.
ERROR_BAD_FORMAT The .exe file is invalid.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.

Remarks
The WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec.

Security Remarks
The executable name is treated as the first white space-delimited string in lpCmdLine. If the executable or path name has a space in it, there is a risk that a different executable could be run because of the way the function parses spaces. The following example is dangerous because the function will attempt to run "Program.exe", if it exists, instead of "MyApp.exe".

WinExec("C:\Program Files\MyApp", ...)
If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls WinExec using the Program Files directory will run this application instead of the intended application.

To avoid this problem, use CreateProcess rather than WinExec. However, if you must use WinExec for legacy reasons, make sure the application name is enclosed in quotation marks as shown in the example below.

WinExec("\"C:\Program Files\MyApp.exe\" -L -S", ...)
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

====================
装个MSDN比较好点

MFC 如何获取某一个路径下的 .exe 文件是否正在运行?~

/************************************************************************//* 判断进程里是否存在 “xxx软件” 例如(xxx.exe) 返回值为0:软件没运行; 否则:软件已经运行 *//************************************************************************/int CBatteryDlg:: GetProcessCount(const TCHAR* szExeName){ TCHAR sztarget[MAX_PATH]; lstrcpy(sztarget, szExeName); CharLowerBuff(sztarget, MAX_PATH); int count = 0; PROCESSENTRY32 my; HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (((int)l) != -1) { my.dwSize = sizeof(my); if (Process32First(l, &my)) { do { CharLowerBuff(my.szExeFile, MAX_PATH); if (lstrcmp(sztarget, my.szExeFile) == 0) { count++; } } while (Process32Next(l, &my)); } CloseHandle(l); } return count;}

一:要是是一个完整的项目文件,里面包含很多子文件,打开需要用引入的方式。如下:
①运行Eclipse,在菜单栏找到【File】=>【Import】。

②选择【Existing Projects ……】=》【finish】。


③找到要导入的项目的路径,在片【projects】那儿打上勾,点【finish】即可。

二:要是是一个单个文件,则直接file=>打开,找到文件所在路径即可。

如何用MFC打开一个EXE文件?
答:打开程序用 WinExec("程序路径",SW_SHOW);关闭自己用exit(0);关闭别的程序,首先获得程序的PID,然后 int TerminateProcessFromId(DWORD dwId) //关闭进程 { BOOL bRet=FALSE;HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwId);if(hProcess!=NULL){ bRet=::TerminateProcess(hProcess,0...

怎么用mfc运行.exe程序
答://ShellExecute的功能是运行一个外部程序,或者打开一个已注册的文件、打开一个目录,参数如下://参数1:this->m_hWnd为父窗口句柄 //参数2: 用于指定要进行的操作。其中“open”操作表示执行由参数3指定的程序,或打开由参数3指定的文件或文件夹;// “print”操作表示打印由参数3指定的文件;...

MFC中用一个按钮调用一个EXE文件
答:ShellExecute()函数,如下示例 //调用计算器 ShellExecute(NULL,"open","calc.exe",NULL,NULL,SW_SHOWNORMAL);//调用记事本 ShellExecute(NULL,"open","NOTEPAD.EXE",NULL,NULL,SW_SHOWNORMAL);

怎么用MFC的按钮调用一个exe的文件
答:用WinExec函数可打开外部程序,以打开记事本为例: WinExec(_T("c:\\windows\\notepad.exe"),SW_SHOWMAXIMIZED);注意,路径中反斜杠用法。

MFC调用exe程序
答:WinExec("E:\\QQ.EXE",SW_SHOW);字符串改成你的exe路径和名字就可以了,注意反斜杠要转译(必须连续2个)回复 0513zhang:两个函数的参数中,ShowCmd意义和写法是一样的 //ShowCmd 参数可选值:SW_HIDE = 0; {隐藏} SW_SHOWNORMAL = 1; {用最近的大小和位置显示, 激活} 但第四个参数。

MFC调用外部exe
答:ShellExecute(NULL,_T("open"),"文件路径",NULL,NULL,SW_SHOW);

mfc 中如何打开 关闭一个exe文件
答:打开程序用 WinExec("程序路径",SW_SHOW);关闭自己用exit(0);关闭别的程序,首先获得程序的PID,然后 int TerminateProcessFromId(DWORD dwId) //关闭进程 { BOOL bRet=FALSE;HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwId);if(hProcess!=NULL){ bRet=::TerminateProcess(hProcess...

mfc怎么打开第三方exe文件,并调整这个程序的窗口位置
答:通过findwindow获得这个窗口句柄 ,再setwindowpos调整位置

怎样在MFC程序里调用带参数的exe程序?
答:在按钮响应函数里添加 system("cd d:\melp pesq +8000 -a");

MFC中调用外部exe文件
答:就放到你工程生成的对应debug/release下;如果加目录名或者设置了path就随便调用也没有关系了。我不是很确定你调用的意思,我猜测你只是想类似资源管理器中运行那种调用。如果你是调用com组件的话,只要注册了,调用客户是不用管exe组件的目录位置的,是通过唯一的CLSID来调用的 ...