1. The shortcuts of shortcuts are actually a data file with extension LNK, which contains all objects for accessing Windows (ie all objects you can browse in the Explorer, including files, files. Information about the clip, drive and printer, etc.), such as the path and name, working directory, command line parameters of the target object, initial display status, icon, and shortcut keys, etc. of the runtime. These properties of this shortcut can be observed by clicking the right mouse button on the shortcut and selecting "Properties" in the pop-up menu.
2, programming ideas
The shortcuts for the Windows Shell are designed based on the component object model COM (Component ObjectModal) of OLE technology. With the COM model, an application can call some of the functions of another application.
Windows provides a COM interface ishelllink, which can help us create, modify, and delete shortcuts. To use the function provided by the COM interface, you must first call the cocreateInstance () function to create an IID_IDLLLINK instance and get its interface pointer. Use this interface pointer to set it. After creating an instance, by calling the setPath () method to set the path of the source program, the shortcut storage location should be: "program" position program group name shortcut name extension .Lnk; via setDescription Method Setting up a shortcut description, of course, you can also call such as setHotKey () and other methods to set the hotkey, the displayed icon (the icon for the actual program), etc. In order to save this information in a shortcut data file (* .Lnk) format, it is also necessary to get its IID_IPERSISTFILE interface pointer from the IID_ISHELLLINK object to facilitate calling its member function save () saves the previous settings.
It should be noted that: shortcuts should be stored using Unicode, so you must call the WCSCPY () function to convert it. // CreateBOOL CMainDlg :: CreateLink (LPCSTR pszShortcutFile, / * Source * / LPCSTR pszLink, / * lnk name * / LPCSTR pszDesc / * Description * /) {HRESULT hres; CComPtr
hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) & psl); if (FAILED (hres)) {return FALSE;} hres = psl-> QueryInterface (IID_IPersistFile, (void **) & ppf); if (Failed (hres)) {returnaf false;} Word WSZ [MAX_PATH]; hres = psl-> setpath (pszshortcutfile); if (failed (hres)) {returnaf false;}
HRES = PSL-> setDescription (pszdesc); if (failed (hres)) {return false;} #ifndef _unicode multibytetowideChar (CP_ACP, 0, PSZLINK, -1, WSZ, MAX_PATH); # else WCSCPY (WSZ, Szlink); #ndif hres = ppf-> save (wsz, true); if (failed (hres)) {returnaf false;} return true;} string cmaindlg :: getshortcuttarget (lpcstr pszlinkfilename) {HRESULT HRES;
CSTRINKFILENAME; TEMP.MAKELOWER (); if (Temp.Find (". Lnk") == - 1) // Check if the name ends with .lnk {link = pszlinkFileName; link = _ t (" .LNK "); // if not, append it} else {link = pszlinkfilename;
String info; ccomptr
HRES = CocreateInstance (CLSID_SHELLINK, NULL, CLSCTX_INPROC_SERVER, IID_ID_ILLLINK, (LPVOID *) & PSL);
if (SUCCEEDED (hres)) {CComPtr
}}} Return NULL;