Qt之創建桌面和開始菜單快捷方式


將安裝好的酷狗拷貝到C:\data目錄中

1.創建桌面快捷方式

 

[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. QFile::link("C:/data/KuGou.exe", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append("KuGou.lnk"));  

2.創建開始菜單快捷方式

 

 

[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. #include <shlobj.h>  
  2. WCHAR   startMenuPath[MAX_PATH];  
  3. bool isOK = SHGetSpecialFolderPath(NULL, startMenuPath, CSIDL_PROGRAMS, FALSE);  
  4. if(isOK)  
  5. {  
  6.   
  7.     QString myMenuDirPath=QString::fromWCharArray(startMenuPath).append("/").append(QStringLiteral("酷狗"));  
  8.     QDir dir(myMenuDirPath);  
  9.     if(!dir.exists())  
  10.     {  
  11.         dir.mkdir(myMenuDirPath);  
  12.     }  
  13.     QFile::link("C:/data/KuGou.exe", myMenuDirPath.append("/").append("KuGou.lnk"));  
  14. }  

 

3.將快捷方式鎖定到任務欄

Win7、Win8有效

 

[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. //快捷方式必須存在,才能鎖定到任務欄  
  2. QFile::link("C:/data/KuGou.exe", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append("KuGou.lnk"));  
  3. QString strTemp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append("KuGou.lnk");  
  4.   
  5. //鎖定到任務欄  
  6. int nRet = (int)::ShellExecute(NULL, QString("taskbarpin").toStdWString().c_str(), strTemp.toStdWString().c_str(), NULL, NULL, SW_SHOW);  
  7. //返回值大於32表示成功  
  8. if (nRet <= 32)  
  9. {  
  10.     qDebug() << "無法將快捷方式鎖定到任務欄!";  
  11. }  
  12. //解鎖  
  13. nRet = (int)::ShellExecute(NULL, QString("taskbarunpin").toStdWString().c_str(), strTemp.toStdWString().c_str(), NULL, NULL, SW_SHOW);  
  14. if (nRet <= 32)  
  15. {  
  16.      qDebug() << "解鎖失敗!";  
  17. }  

 

http://blog.csdn.net/caoshangpa/article/details/53981650


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM