How to create a shortcut in the Quick Launch bar
Last Update:2017-02-27
Source: Internet
Author: User
#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 * *) &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!"); }