WinExec

WinExec、ShellExecute用法详解

小云
139
2023-09-13 07:10:38
栏目: 编程语言

WinExec和ShellExecute是Windows操作系统中的两个函数,用于执行外部程序或打开文件。下面是它们的用法详解:

  1. WinExec函数:
#include <windows.h>
int main()
{
WinExec("notepad.exe", SW_SHOW);
return 0;
}
  1. ShellExecute函数:
#include <windows.h>
int main()
{
ShellExecute(NULL, "open", "notepad.exe", NULL, NULL, SW_SHOW);
return 0;
}

使用WinExec或ShellExecute函数可以执行外部程序或打开文件,具体使用哪个函数取决于具体的需求。如果只需要简单执行一个外部程序,建议使用WinExec函数;如果需要更多的操作选项,比如指定父窗口、传递命令行参数等,可以使用ShellExecute函数。

0
看了该问题的人还看了