Windows函数 ShellExecuteEx

Posted 胡刚2021

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows函数 ShellExecuteEx相关的知识,希望对你有一定的参考价值。

点击进入视频教程

代码:

#include<windows.h>
#include<tchar.h>
#pragma comment(lib, "Urlmon.lib")
int WINAPI _tWinMain(HINSTANCE hinstance, HINSTANCE hPreInstance, LPTSTR lpCmdLine, int nShowCmd) 
	// 下载图片,并保存为 D:\\123.png
	HRESULT hresult = URLDownloadToFile(NULL, _T("https://att.cctry.com/forum/202003/07/001501qqp1li71b61of99p.png"),
		_T("D:\\\\123.png"), 0, NULL);

	// 打开刚才下载的图片
	SHELLEXECUTEINFO shellInfo = 0;
	shellInfo.cbSize = sizeof(SHELLEXECUTEINFO);
	shellInfo.lpVerb = _T("open");
	shellInfo.lpFile = _T("D:\\\\123.png");
	shellInfo.nShow = SW_SHOW;
	bool bret = ShellExecuteEx(&shellInfo);
	 
	return 0;

点击运行,自动下载并打开了图片

打开记事本

//shellInfo.lpFile = _T("D:\\\\123.png");
// 打开记事本
shellInfo.lpFile = _T("notepad.exe");


打开计算器

// 打开计算器
shellInfo.lpFile = _T("calc.exe");


打开QQ
先找到QQ的路径

// 打开QQ
shellInfo.lpFile = _T("E:\\\\Tencent\\\\QQ\\\\Bin\\\\QQScLauncher.exe");


用默认浏览器打开指定网址

// 用默认浏览器打开指定网址
shellInfo.lpFile = _T("www.cctry.com");

以上是关于Windows函数 ShellExecuteEx的主要内容,如果未能解决你的问题,请参考以下文章

ShellExecuteEx函数的作用

将 unicode 参数传递给 ShellExecuteEx 中的子进程

WinApi ShellExecuteEx - 在文件列表上使用动词“复制”

VC++分别使用WinExecCreateProcessShellExecute和ShellExecuteEx来启动程序(附源码)

用ShellExecuteEx函数执行一个vc写的exe,vc程序的返回函数是return(n)

ShellExecuteEx 并等待文件实际打开