手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>C/C++>列表

如何在快速启动栏创建快捷方式

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.hpp>
#include <vcl.h>
// 以上三行放在单元文档最开始
//---------------------------------------------------------------------------
struct TShortcutCfg
{
// 构造函数
TShortcutCfg()
{
nShowCmd = SW_SHOWNORMAL;
wHotKey = 0;
nIconIndex = 0;
}
// 结构成员:
AnsiString strShortcutName; //
AnsiString strLnkDir; //
AnsiString strDestFile; //
AnsiString strArguments; //
AnsiString strIconFile; //
int nIconIndex; //
AnsiString strWorkingDir; //
AnsiString strDescription; //
WORD wHotKey; //
int nShowCmd; //
};
//---------------------------------------------------------------------------
// 在快速启动栏创建快捷方式
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)
// 本文转自 C Builder 研究 - http://www.ccrun.com/article.asp?i=610&d=n1473c
"\\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);

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!