Qt/C++调用Windows画图板mspaint,打开指定路径的图片文件,从文件路径中提取目录名和文件名
一、先看完整的源码
#ifdef Q_OS_WIN
#include <Windows.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "shell32.lib")
#endifvoid DistortionCalibWidget::slotToolButtonMspaint()
{//C:\Windows\SysWOW64\mspaint.exe//C:\Windows\System32\mspaint.exestd::string strImage = m_strPathNameImageOrg.toStdString();qDebug() << m_strPathNameImageOrg;//将'/'转'\\',斜杠转反斜杠QString strNat = QDir::toNativeSeparators(m_strPathNameImageOrg);std::string strImageNew = strNat.toStdString();qDebug() << strNat;//已知文件路径全名,求文件所在文件夹的路径std::string directory;const size_t last_slash_idx1 = strImageNew.rfind('\\');const size_t last_slash_idx2 = strImageNew.rfind('/');if (std::string::npos != last_slash_idx1){directory = strImageNew.substr(0, last_slash_idx1);}if (std::string::npos != last_slash_idx2){directory = strImageNew.substr(0, last_slash_idx2);}directory = ("\"") + directory + ("\""); //加引号是为了避免路径有空格,因为cmd命令不认空格std::cout << directory << std::endl;std::string strEnd = ("\"") + strImageNew + ("\""); //加引号是为了避免路径有空格,因为cmd命令不认空格//打开方式1::ShellExecuteA(NULL, "open", "mspaint.exe", strEnd.c_str(), NULL, SW_SHOWMAXIMIZED); //只认'\\'路径//打开方式2//::ShellExecuteA(NULL, "open", "mspaint.exe", strEnd.c_str(), directory.c_str(), SW_SHOWMAXIMIZED);
}
二、注意事项:
1、ShellExecuteA是Windows的函数,只认'\\'的路径方式,不认'/'的方式。
2、Qt得到的路径默认是'/'的方式。
3、所以需要转换路径(/斜杠与\反斜杠转换)
//获取应用程序的目录
QString strCurrentApplicationDirPath=QCoreApplication::applicationDirPath();
qDebug()<<strCurrentApplicationDirPath;/*将/转\(斜杠转反斜杠)*/
QString strPath=QDir::toNativeSeparators(strCurrentApplicationDirPath);
qDebug()<<strPath;/*将\转/(反斜杠转斜杠)*/
QString strPath2=QDir::fromNativeSeparators(strPath);
qDebug()<<strPath2;
输出:
"D:/QT5SourceCode/build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"
"D:\\QT5SourceCode\\build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug\\debug"
"D:/QT5SourceCode/build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"
---
std::string srcPath;
std::string dstPath(srcPath);
dstPath.insert(dstPath.size() - 4, "2dst");
Qt/C++调用Windows画图板mspaint,打开指定路径的图片文件,从文件路径中提取目录名和文件名相关推荐
- 怎样用调用资源管理器explore.exe打开指定的文件夹
怎样用调用资源管理器explore.exe打开指定的文件夹 VCL组件开发及应用 http://www.delphi2007.net/DelphiVCL/html/delphi_20061225173 ...
- Mac技巧之苹果电脑Mac OS X系统上,类似Windows画图板的软件paintbrush介绍与下载
from:http://www.mac52ipod.cn/post/paintbrush-Mac-OS-X-Windows-HuaTu.php PC用户可能经常用Windows自带的画图板做简单的图片 ...
- 仿制Windows画图板程序
仿制Windows画图板程序 控件 代码 效果图 控件 新建一个Windows窗体应用程序,将窗体Form1调整到适当大小,在窗体Form1中分别添加1个Panel.1个PictureBox和1个St ...
- android saf 打开指定目录,并操作相关文件
android saf 打开指定目录,并操作相关文件 saf存储访问框架(android 4.4 引入)全称 Storage Access Framework 用户可轻松在其所有首选文档存储提供程序中 ...
- Python调Windows的资源管理器打开指定目录
2019独角兽企业重金招聘Python工程师标准>>> 使用Python在Windows自定义命令时候遇到一个问题,调用Windows文件选择器打开指定文件目录. 这里介绍两种方式: ...
- 基于MATLAB的仿windows画图板功能的实现
1.仿真预览 2.部分核心代码 % --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObje ...
- windows画图板 ESL转RGB 实现区间渐变色
2021.6.21记载 根据数值确定渐变范围[-1,1] 主要实现红色向绿色的渐变效果 色调(E)调低偏向红色,调高偏向绿色[0-80] 饱和度(S)越高颜色越深,越低颜色越浅[0-240] 亮度(L ...
- Windows 10免费原生打开HEIC格式的图片(无需转换,直接用照片打开)
安装HEIF扩展 在微软应用商店搜索HEIF,第一个就是这个扩展. 安装HEVC解码器 在微软应用商店搜索HEVC,第一个结果就是HEVC视频扩展,但是这个要付费,后面有免费的办法. 这个里面才是图片 ...
- Windows利用bat程序打开指定网址
很简单,只需start空格加网址. start 网址 还可以指定使用哪一个浏览器而非默认浏览器. 比如说我要用IE浏览器打开B站,那么代码如下-- start iexplore.exe https:/ ...
最新文章
- Mysql字段类型选择
- 腾讯的一笔画游戏--巧妙解法
- 优化自定义函数_Pandas常见的性能优化方法
- php 合并数组成父子关系,php - 将电子表格解析为PHP数组并返回具有父子关系的嵌套MLM表 - SO中文参考 - www.soinside.com...
- Centos6的VSFTP服务器配置使用教程
- nodejs 实践项目_NodeJS:最佳生产实践
- mock如何为空_Mockito怎么样Mock返回值为空的方法
- pytorch,onnx和tensorrt 的速度对比
- postgresql-9.6.6主从
- 分享6款国内、国外开源PHP轻论坛CMS程序
- 计算机itunes无法安装,itunes无法安装怎么办 itunes不能安装解决方法
- Android 设置网络代理
- yzl的VSCode使用指南
- Excel PivotTable 使用心得手顺分享(二)
- 软件测试肖sir__010之mysql之总结(8)
- 玩游戏使用云服务器,云服务器可以玩大型游戏吗?
- Largenbsp;Scalenbsp;Dist…
- PostgreSQL集群方案-Postgres-XL
- springboot配置内置tomcat的日志
- 【笔记】效率脑科学:卓有成效地完成每一项工作