Void policyshell (long weventid, // event flag
Lpstr szpath) // path
{
Shchangenovel (weventid, shcnf_flush | shcnf_path, szpath, 0 );
// Obtain the parent directory of szpath
Char * P;
For (P = szpath + lstrlen (szpath)-1; * P! = '//'; P --);
* P = '/0 ';
Shchangenovel (shcn_updatedir | shcn_interrupt, shcnf_flush | shcnf_path, szpath, 0 );
}
// Create a shortcut
Bool CreateLink (lpstr szpath, lpstr szlink)
/* Target application name of the szpath shortcut
Szlink shortcut data file name (*. lnk )*/
{
Hresult hres;
Ishelllink * PSL;
Ipersistfile * PPF;
Word wsz [max_path];
//// Initialize com
Coinitialize (null );
// Create an ishelllink instance
Hres = cocreateinstance (clsid_shelllink, null, clsctx_inproc_server, iid_ishelllink,
(Void **) & PSL );
If (failed (hres ))
{
Couninitialize ();
Return false;
}
// Set the target application
Psl-> setpath (szpath );
// Set the shortcut key (SHIFT + Ctrl + 'R ')
// PSL-> sethotkey (makeword ('R ',
// Hotkeyf_shift | hotkeyf_control ));
Char * P;
For (P = szpath + lstrlen (szpath)-1; * P! = '//'; P --);
* P = '/0 ';
Psl-> setworkingdirectory (szpath );
// Obtain its ipersistfile interface from ishelllink
// Used to save the shortcut data file (*. lnk)
Hres = PSL-> QueryInterface (iid_ipersistfile, (void **) & PPF );
If (failed (hres ))
{
Couninitialize ();
Return false;
}
// Ensure that the data file name is in ANSI format
Multibytetowidechar (cp_acp, 0, szlink,-1, wsz, max_path );
// Call ipersistfile: Save
// Save the shortcut data file (*. lnk)
Hres = PPF-> Save (wsz, stgm_readwrite );
// Release the ipersistfile and ishelllink Interfaces
PPF-> release ();
Psl-> release ();
Couninitialize ();
Return true;
}
Void createthisappshortcut ()
{
Char szpath [max_path] = ""; // target application name of the shortcut
Char szlink [max_path] = ""; // shortcut data file name
/// Desktop shortcut
Getmodulefilename (null, szpath, max_path );
Getwindowsdirectory (szlink, max_path );
If (szlink [lstrlen (szlink)-1] = '//')
Lstrcat (szlink, "desktop // estk receiving settings. lnk ");
Else
Lstrcat (szlink, "// desktop // estk receiving settings. lnk ");
// Create a shortcut
If (! CreateLink (szpath, szlink ))
Return;
// Notify the shell about changes
Policyshell (shnning_create | shnning_interrupt, szlink );
//// Quick Start
Getmodulefilename (null, szpath, max_path );
Getwindowsdirectory (szlink, max_path );
If (szlink [lstrlen (szlink)-1] = '//')
Lstrcat (szlink, "Application Data // Microsoft // Internet Explorer // Quick Launch // estk receiving settings. lnk ");
Else
Lstrcat (szlink, "// Application Data // Microsoft // Internet Explorer // Quick Launch // estk receiving settings. lnk ");
If (! CreateLink (szpath, szlink ))
Return;
Policyshell (shnning_create | shnning_interrupt, szlink );
}