当前位置:   article > 正文

C++/Qt中调用函数ShellExecute()打开图片或者word文档的使用方法_shellexecute打开图片

shellexecute打开图片

一、说明

1、本文的测试环境是win764+vs2013+Qt5.6。
2、使用函数shellExecute调用windows图片浏览器或者IE浏览器打开jpg格式的图片。
3、使用函数shellExecute调用windows office打开word文档。
4、使用该函数注意中文路径的问题( 如有中文路径问题,可以参考我的博客,博客地址:http://blog.csdn.net/toby54king)和函数shellExecute中代码内容的书写格式。

二、测试-文件路径写死

测试通过的方法,文件路径没有写死:

string appPath = QApplication::applicationDirPath().toStdString() + "/pictureFile/testShow.jpg";
		int l = MultiByteToWideChar(CP_ACP, 0, appPath.c_str(), -1, NULL, 0);
		LPWSTR filePath = new TCHAR[l];
		MultiByteToWideChar(CP_ACP, 0, appPath.c_str(), -1, filePath, l);
		ShellExecute(NULL, (LPCWSTR)L"open", filePath, (LPCWSTR)L"", (LPCWSTR)L"", SW_SHOW);


		//ShellExecute(NULL, (LPCWSTR)L"open", (LPCWSTR)L"E:/Component/Release_Win32/pictureFile/testShow.jpg", (LPCWSTR)L"", (LPCWSTR)L"", SW_SHOW);

//IE浏览器显示图片
		//ShellExecute(NULL, (LPCWSTR)L"open", (LPCWSTR)L"iexplore", (LPCWSTR)L"E:/work/testShow.jpg", NULL, SW_SHOWNORMAL);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

三、测试-文件路径不写死

测试通过,文件路径写死

ShellExecute(NULL, (LPCWSTR)L"open", (LPCWSTR)L"iexplore", (LPCWSTR)L"E:/work/testShow.jpg", NULL, SW_SHOWNORMAL);

		//ShellExecute(0, (LPCWSTR)L"open", (LPCWSTR)L"CALC.EXE", (LPCWSTR)L"", (LPCWSTR)L"", SW_SHOWNORMAL);

//appPath = QApplication::applicationDirPath().toStdString() + "/pictureFile/testShow5.jpg";
		appPath = QApplication::applicationDirPath().toStdString() + "/wordFile/testword.docx"; //打开word文档方法一样的
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/281845
推荐阅读
相关标签
  

闽ICP备14008679号