#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;
LP99vEMIDLIST lpItemIdList;
SHGetSpecialFolderLocation(0, CSIDL_APPDATA, &lpItemIdList);
SHGetPathFromIDList(lpItemIdList, szBuf);
if(DirectoryExists(AnsiString(szBuf)))
{
strShortcutFile = AnsiString(szBuf)
+ "MicrosoftInternet EXPlorerQuick 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)
pShe