How to create shortcuts in the fast boot bar
#DEFINE NO_WIN32_LEAN_AND_MEAN # include
#include
// The above three rows are placed in unit files.
/ / -------------------------------------------------------------------------------------------- ---------------------------
Struct Tshortcutcfg
{
// Constructor
Tshortcutcfg ()
{
nshowcmd = sw_shownormal;
WhotKey = 0;
NiconIndex = 0;
}
// Structural member:
ANSISTRING STRSHORTCUTNAME; //
ANSISSIING STRLNKDIR; //
Ansistring strdestfile; //
Ansistring strarguments; //
Ansistring striconfile; //
Int niconindex; //
Ansistring strworkingdir; //
ANSISTRING STRDESCRIPTION; //
Word whoY; //
INT nshowcmd; //
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
// Create a shortcut in the fast start bar
Bool CreatequickLaunchShortcut (Tshortcutcfg * Scconfig)
{
Char szbuf [MAX_PATH];
Bool Breturn = True;
Wchar_t wszbuf [max_path];
IShelllink * pshelllink;
ANSISUTRING 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_ID1ELLINK, (void **) & pshelllink> = 0;
IF (Breturn)
{
IPERSISTFILE * PPF;
Breturn = pshelllink-> queryinterface (IID_IPERSISTFILE, (VOID **) & PPF)> = 0;
IF (Breturn)
{
// Target file
IF (Scconfig-> strDestFile! = EMPTYSTR)
Breturn = pshelllink-> setpath (scconfig-> strDestfile.c_str ())> = 0; // parameter
IF (Breturn && Scconfig-> Strarguments! = EMPTYSTR)
Breturn = pshelllink-> setarguments (scconfig-> stratageguments.c_str ())> = 0;
// Display icon
IF (Breturn && Scconfig-> StriconFile! = Emptystr && FileExists (Scconfig-> StriconFile))
pshelllink-> seticonlocation (scconfig-> striconfile.c_str (),
Scconfig-> niconindex;
// starting point
IF (Breturn && Scconfig-> strWorkingDir! = EMPTYSTR)
Pshelllink-> setworkingdirectory (scconfig-> strworkingdir.c_str ());
// Remarks
IF (Breturn && Scconfig-> strDescription! = EMPTYSTR)
PshellLink-> setdescription (scconfig-> strdescription.c_str ());
// hot key
IF (Breturn && Scconfig-> WhotKey! = 0)
Pshelllink-> sethotkey (scconfig-> whiley);
// 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 the code example:
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: button1click (Tobject * Sender)
{
Tshortcutcfg scshortcut;
SCSHORTCUT.STRDESTFILE = "C: //123//123.exe";
Scshortcut.STRSHORTCUTNAME = "Test";
CreatequickLaunchShortcut (& scshortcut))
ShowMessage ("" Create a quick start box! ");
}
/ / -------------------------------------------------------------------------------------------- ---------------------------