在快速启动栏和桌面创建快捷方式(代码片段)
来源:互联网 发布:java dom4j生成xml 编辑:程序博客网 时间:2024/06/05 00:25
bool CreateQuickLaunchShortcut(String& destFile,String& shortCutName,String& arguments)
{
char szBuf[MAX_PATH];
LPITEMIDLIST lpItemIdList;
SHGetSpecialFolderLocation(0, CSIDL_APPDATA, &lpItemIdList);
SHGetPathFromIDList(lpItemIdList, szBuf);
String dir = String(szBuf) + "\\Microsoft\\Internet Explorer\\Quick Launch\\";
bool result = CreateShortcut(destFile,shortCutName,dir,arguments);
return result;
}
bool CreateShortcut(String& destFile,String& shortCutName,String& dir,String& arguments)
{
TShortcutCfg scConfig;
scConfig.strDestFile = destFile;
scConfig.strShortcutName = shortCutName;
scConfig.strArguments = arguments;
bool bReturn = true;
wchar_t wszBuf[MAX_PATH];
IShellLink *pShellLink;
AnsiString strShortcutFile;
strShortcutFile = dir + shortCutName + SHORTCUT_SUFFIX;
strShortcutFile.WideChar(wszBuf, MAX_PATH);
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;
}
{
char szBuf[MAX_PATH];
LPITEMIDLIST lpItemIdList;
SHGetSpecialFolderLocation(0, CSIDL_APPDATA, &lpItemIdList);
SHGetPathFromIDList(lpItemIdList, szBuf);
String dir = String(szBuf) + "\\Microsoft\\Internet Explorer\\Quick Launch\\";
bool result = CreateShortcut(destFile,shortCutName,dir,arguments);
return result;
}
bool CreateShortcut(String& destFile,String& shortCutName,String& dir,String& arguments)
{
TShortcutCfg scConfig;
scConfig.strDestFile = destFile;
scConfig.strShortcutName = shortCutName;
scConfig.strArguments = arguments;
bool bReturn = true;
wchar_t wszBuf[MAX_PATH];
IShellLink *pShellLink;
AnsiString strShortcutFile;
strShortcutFile = dir + shortCutName + SHORTCUT_SUFFIX;
strShortcutFile.WideChar(wszBuf, MAX_PATH);
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;
}
- 在快速启动栏和桌面创建快捷方式(代码片段)
- 在桌面和快速启动中创建快捷方式
- 如何在快速启动栏创建快捷方式
- 创建快捷方式 (并添加到快速启动栏 、桌面、开始菜单)
- 恢复快速启动栏和"显示桌面" 快捷方式
- 创建桌面快捷方式和开始启动项
- 如何编程实现在快速启动栏创建快捷方式
- 创建快捷方式到桌面、任务栏、开始菜单、快速启动栏、程序组中
- 创建桌面快捷方式+设置开机启动代码[C#、WinForm]
- 关于如何在启动时创建桌面快捷方式
- InnoSetUp指定桌面快捷方式和快速启动图标
- 怎么在快速启动栏那里放显示桌面的快捷方式
- c#创建快捷方式到快速启动栏
- 在Win桌面创建快捷方式
- 在Windows桌面创建快捷方式
- wince 在桌面创建快捷方式
- Android在桌面创建快捷方式
- WINCE在桌面创建快捷方式
- 安全的服务
- JDBC数据库编程
- 关于linux串口编程的一点总结
- iphone开发学什么
- 对于一个JDBC程序的解读
- 在快速启动栏和桌面创建快捷方式(代码片段)
- 调查服务器响应时间的利器 tcprstat
- Android 资源
- windows快捷键
- windows编程修改IP(代码片段)
- 老兵学Java编程(3):如何发布
- Foxit Reader快捷键
- c语言夜未眠3——如何将自己的c文件做出静态库lib
- Node.js获得企业开发者青睐