How to create a shortcut in the Quick Launch bar

Source: Internet
Author: User
Tags bool
#define No_win32_lean_and_mean
#include <shlobj.hpp>
#include <vcl.h>
The above three lines are placed at the beginning of the cell file
//---------------------------------------------------------------------------
struct TSHORTCUTCFG
{
Constructors
Tshortcutcfg ()
{
nShowCmd = Sw_shownormal;
Whotkey = 0;
Niconindex = 0;
}
Structure Members:
Ansistring Strshortcutname; //
Ansistring Strlnkdir; //
Ansistring strDestFile; //
Ansistring strarguments; //
Ansistring Striconfile; //
int niconindex; //
Ansistring Strworkingdir; //
Ansistring strdescription; //
WORD Whotkey; //
int nshowcmd; //
};
//---------------------------------------------------------------------------
Create a shortcut in the Quick Launch bar
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 * *) &AMP;PPF) >= 0;
if (Breturn)
{
Destination file
if (scconfig->strdestfile!= emptystr)
Breturn = Pshelllink->setpath (Scconfig->strdestfile.c_str ()) >= 0;
Parameters
if (Breturn && scconfig->strarguments!= emptystr)
Breturn = Pshelllink->setarguments (Scconfig->strarguments.c_str ()) >= 0;
Display icon
if (Breturn && scconfig->striconfile!=
Emptystr && fileexists (scconfig->striconfile))
Pshelllink->seticonlocation (Scconfig->striconfile.c_str (),
Scconfig->niconindex);
Starting position
if (Breturn && scconfig->strworkingdir!= emptystr)
Pshelllink->setworkingdirectory (Scconfig->strworkingdir.c_str ());
Note
if (Breturn && scconfig->strdescription!= emptystr)
Pshelllink->setdescription (Scconfig->strdescription.c_str ());
Shortcut keys
if (breturn && scconfig->whotkey!= 0)
Pshelllink->sethotkey (Scconfig->whotkey);
Operation mode
if (breturn && scconfig->nshowcmd!= 0)
Pshelllink->setshowcmd (Scconfig->nshowcmd);
if (Breturn)
Breturn = (Ppf->save (wszbuf, TRUE) >= 0);
Ppf->release ();
}
Pshelllink->release ();
}
}
return breturn;
}
Call code Example:
//---------------------------------------------------------------------------
void __fastcall Tform1::button1click (tobject *sender)
{
Tshortcutcfg Scshortcut;
Scshortcut.strdestfile = "C:\\123\\123.exe";
Scshortcut.strshortcutname = "Test";
if (Createquicklaunchshortcut (&scshortcut))
ShowMessage ("Create shortcut in Quick Launch bar success!");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.