在VC中如何通过一条命令调用外部程序?(除了system之外的)

crazysoft 2001-09-08 10:26:47
同标题,谢谢各位指点。
曾经试过system,但是老是出现一个DOS 窗口后再出现程序界面,比较讨厌。
...全文
131 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
DXD 2001-09-08
  • 打赏
  • 举报
回复
1.
UINT WinExec(
LPCSTR lpCmdLine, // command line
UINT uCmdShow // window style
);
2.
BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);
3.

int _execv( const char *cmdname, const char *const *argv );

int _wexecv( const wchar_t *cmdname, const wchar_t *const *argv );


crazysoft 2001-09-08
  • 打赏
  • 举报
回复
非常感谢,25分已经送出,不好意思,没办法再送了
以后有机会请大家吃麦当劳:)
Belle 2001-09-08
  • 打赏
  • 举报
回复
ShellExecute()
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
You can use this function to open or explore a shell folder. To open a folder, use either of the following calls
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);

or

ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

To explore a folder, use the following call:

ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

宝_爸 2001-09-08
  • 打赏
  • 举报
回复
很简单啊!
宝_爸 2001-09-08
  • 打赏
  • 举报
回复
再给你一个例子。不过是bcb的例子,调用createprocess的地方和vc是一样的。
PROCESS_INFORMATION pi;
STARTUPINFO si;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;

DWORD dwRes = 0;
if(CreateProcess("c:\\windows\\winmine.exe",NULL,NULL,NULL,false,
CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS,
NULL,NULL,&si,&pi))
//作其它操作。
else
dwRes = GetLastError();
ShowMessage("excute over");
crazysoft 2001-09-08
  • 打赏
  • 举报
回复
没有简单的方发吗?谢谢
宝_爸 2001-09-08
  • 打赏
  • 举报
回复
msdn中的解释
CreateProcess
The CreateProcess function creates a new process and its primary thread. The new process runs the specified executable file.

To create a process that runs in a different security context, use the CreateProcessAsUser or CreateProcessWithLogonW function.

BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);
crazysoft 2001-09-08
  • 打赏
  • 举报
回复
up again!
NowCan 2001-09-08
  • 打赏
  • 举报
回复
CreateProcess
crazysoft 2001-09-08
  • 打赏
  • 举报
回复
up!

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧