将安装好的酷狗拷贝到C:\data目录中
1.创建桌面快捷方式
- QFile::link("C:/data/KuGou.exe", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append("KuGou.lnk"));
2.创建开始菜单快捷方式
- #include <shlobj.h>
- WCHAR startMenuPath[MAX_PATH];
- bool isOK = SHGetSpecialFolderPath(NULL, startMenuPath, CSIDL_PROGRAMS, FALSE);
- if(isOK)
- {
- QString myMenuDirPath=QString::fromWCharArray(startMenuPath).append("/").append(QStringLiteral("酷狗"));
- QDir dir(myMenuDirPath);
- if(!dir.exists())
- {
- dir.mkdir(myMenuDirPath);
- }
- QFile::link("C:/data/KuGou.exe", myMenuDirPath.append("/").append("KuGou.lnk"));
- }
3.将快捷方式锁定到任务栏
Win7、Win8有效
- //快捷方式必须存在,才能锁定到任务栏
- QFile::link("C:/data/KuGou.exe", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append("KuGou.lnk"));
- QString strTemp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append("KuGou.lnk");
- //锁定到任务栏
- int nRet = (int)::ShellExecute(NULL, QString("taskbarpin").toStdWString().c_str(), strTemp.toStdWString().c_str(), NULL, NULL, SW_SHOW);
- //返回值大于32表示成功
- if (nRet <= 32)
- {
- qDebug() << "无法将快捷方式锁定到任务栏!";
- }
- //解锁
- nRet = (int)::ShellExecute(NULL, QString("taskbarunpin").toStdWString().c_str(), strTemp.toStdWString().c_str(), NULL, NULL, SW_SHOW);
- if (nRet <= 32)
- {
- qDebug() << "解锁失败!";
- }
http://blog.****.net/caoshangpa/article/details/53981650