如何在快速启动栏创建快捷方式 #define NO_WIN32_LEAN_AND_MEAN #include <shlobj.hpp> #include <vcl.h> // 以上三行放在单元文件最开始
//--------------------------------------------------------------------------- struct TShortcutCfg { // 构造函数 TShortcutCfg() { nShowCmd = SW_SHOWNORMAL; wHotKey = 0; nIconIndex = 0; } // 结构成员: AnsiStringstrShortcutName; // AnsiStringstrLnkDir;// AnsiStringstrDestFile;// AnsiStringstrArguments;// AnsiStringstrIconFile;// intnIconIndex;// AnsiStringstrWorkingDir;// AnsiStringstrDescription;// WORDwHotKey;// intnShowCmd;// }; //--------------------------------------------------------------------------- // 在快速启动栏创建快捷方式 bool CreateQuickLaunchShortcut(TShortcutCfg *scConfig) { char szBuf[MAX_PATH]; bool bReturn = true; wchar_t wszBuf[MAX_PATH]; IShellLink *pShellLink; AnsiString strShortcutFile;
LPITEMIDLIST lpItemIdList; SHGetSpecialFolderLocation(0, CSIDL_APPDATA, &lpItemIdList); SHGetPathFromIDList(lpItemIdList, szBuf); if(DirectoryExists(AnsiString(szBuf))) { strShortcutFile = AnsiString(szBuf) + "\\Microsoft\\Internet Explorer\\Quick Launch\\" + scConfig->strShortcutName + ".lnk"; strShortcutFile.WideChar(wszBuf, MAX_PATH); } else bReturn = false;
if(bReturn) { bReturn = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&pShellLink) >= 0;
if(bReturn) { IPersistFile *ppf; bReturn = pShellLink->QueryInterface(IID_IPersistFile, (void **)&ppf) >= 0; if(bReturn) { // 目标文件 if(scConfig->strDestFile != EmptyStr) bReturn = pShellLink->SetPath(scConfig->strDestFile.c_str()) >= 0; // 参数 if(bReturn && scConfig->strArguments != EmptyStr) bReturn = pShellLink->SetArguments(scConfig->strArguments.c_str()) >= 0; // 显示图标 if(bReturn && scConfig->strIconFile != EmptyStr && FileExists(scConfig->strIconFile)) pShellLink->SetIconLocation(scConfig->strIconFile.c_str(), scConfig->nIconIndex); // 起始位置 if(bReturn && scConfig->strWorkingDir != EmptyStr) pShellLink->SetWorkingDirectory(scConfig->strWorkingDir.c_str()); // 备注 if(bReturn && scConfig->strDescription != EmptyStr) pShellLink->SetDescription(scConfig->strDescription.c_str()); // 快捷键 if(bReturn && scConfig->wHotKey != 0) pShellLink->SetHotkey(scConfig->wHotKey); // 运行方式 if(bReturn && scConfig->nShowCmd != 0) pShellLink->SetShowCmd(scConfig->nShowCmd);
if(bReturn) bReturn = (ppf->Save(wszBuf, TRUE) >= 0);
ppf->Release (); } pShellLink->Release (); } } return bReturn; } // 调用代码举例: //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { TShortcutCfg scShortcut; scShortcut.strDestFile = "C:\\123\\123.exe"; scShortcut.strShortcutName = "test";
if(CreateQuickLaunchShortcut(&scShortcut)) ShowMessage("在快速启动栏创建快捷方式成功!"); } //---------------------------------------------------------------------------
|
相关推荐
殿堂级的C++ Builder研究网站(http://ccrun.com/)资料汇总,外加部分其他网站开发教程,共计100篇,都是很经典的文章。一篇篇辛辛苦苦地复制粘贴排版的,本想标价5分,但考虑BCB开发人员很少了,只标2分啦!
TMS.Component.Pack.v5.1.0.2完整代码版 转自老妖网站www.ccrun.com
Almdev.SmartFlash.v1.5.Full.Source.Delphi.BCB.BDS.ccrun.rar
VirtualPrinter.v1.0.Source.Code.ccrun.360181.rar 虚拟打印机源码
IPWorks.v6.1.3022.BCB.BDS.CRS.ccrun.486255.rar
1stClass.Studio.2009.v6.0.1.Full.Source.CRS2009.ccrun.622751
TPNGImage.v1.564.Full.Source.Delphi.BCB.ccrun.282267 让BCB和Delphi支持PNG格式图片的控件
InfoPowerStudio2009.v6.0.1.5.Full.Source.Delphi12.CBuilder12.ccrun.608746
FastReport.v4.2.Full.Source.Delphi.BCB.BDS.ccrun.370761.rar,进行报表设计的第三方组件
TMS.Component.Pack.v4.4.Full.Source.D5-11.C5-11.ccrun.599528.rar
Crlab.Oracle.Data.Access.Components.v6.10.Full.Source.Delphi.BCB.BDS.CDS.ccrun.126803
一个实用的皮肤控件,自带皮肤设计器 自带了很多皮肤文件,直接使用
小霸王平机模拟器源码
一个学习C++Builder的好网站http://www.ccrun.com/index.asp
VC 简单实现汉字转换拼音小程序,把输入框内用户输入的中文汉字全部转换成拼音来显示,如演示截图所示。程序原理是使用IFELanguage接口分隔中文语句并对单词加注拼音的演示,作者为ccrun。
读取QQ IP数据库(QQWry.dat)文件格式,并将数据库转换成MDB格式。
用VC++编写的扫雷游戏源代码,附有生成的EXE文件,这个是基于BCB版的扫雷游戏。
delphi 的第三方控件, 是一个有自动收起,打开的控件, 希望对你有用
很老的资源, 现在几乎找不到了。 支持Delphi/BCB系列到2007版,维护老程序,没有的时候很麻烦。