shellexecute

ShellExecute详细用法

小亿
184
2024-01-05 19:33:46
栏目: 编程语言

ShellExecute是一个Windows API函数,用于打开外部应用程序、打开URL链接或者执行系统命令。

ShellExecute的函数原型如下:

HINSTANCE ShellExecute(
  HWND    hwnd,
  LPCTSTR lpOperation,
  LPCTSTR lpFile,
  LPCTSTR lpParameters,
  LPCTSTR lpDirectory,
  INT     nShowCmd
);

参数说明:

返回值:

使用ShellExecute打开外部应用程序的示例代码:

#include <Windows.h>
#include <ShellAPI.h>

int main() {
    ShellExecute(NULL, _T("open"), _T("C:\\Windows\\notepad.exe"), NULL, NULL, SW_SHOW);
    return 0;
}

使用ShellExecute打开URL链接的示例代码:

#include <Windows.h>
#include <ShellAPI.h>

int main() {
    ShellExecute(NULL, _T("open"), _T("http://www.example.com"), NULL, NULL, SW_SHOW);
    return 0;
}

使用ShellExecute执行系统命令的示例代码:

#include <Windows.h>
#include <ShellAPI.h>

int main() {
    ShellExecute(NULL, _T("open"), _T("cmd.exe"), _T("/c echo Hello World"), NULL, SW_SHOW);
    return 0;
}

需要注意的是,ShellExecute函数是一个异步操作的函数,函数调用会立即返回而不等待应用程序执行完毕。如果需要等待应用程序执行完毕再进行其他操作,可以使用ShellExecuteEx函数。

0
看了该问题的人还看了