Ovaj kod pravi shortcut i shortcutkey Ctrl+Alt+L
Poziva se sa:
Code:
hResult=CreateShortcut("Source fajl",Destination fajl","shortcut");
Evo i funkcije(ako nesto nije jasno ili ne radi,pitaj)
Code:
HRESULT CreateShortcut(LPCSTR pszShortcutFile,LPSTR pszLink,LPSTR pszDesc)
{
HRESULT hres;
HRESULT hResult;
IShellLink *psl;
hResult=CoInitialize(NULL);
// Create an IShellLink object and get a pointer to the IShellLink
// interface (returned from CoCreateInstance).
hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **)&psl);
if (SUCCEEDED (hres)){
IPersistFile *ppf;
// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
hres = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED (hres)){
WORD wsz [MAX_PATH]; // buffer for Unicode string
// Set the path to the shortcut target.
hres = psl->SetPath (pszShortcutFile);
//Set shortcut key
WORD HotKey;
HotKey=MAKEWORD(76,HOTKEYF_ALT | HOTKEYF_CONTROL);
hres=psl->SetHotkey(HotKey);
// Set the description of the shortcut.
hres = psl->SetDescription (pszDesc);
// Ensure that the string consists of ANSI characters.
MultiByteToWideChar (CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);
// Save the shortcut via the IPersistFile::Save member function.
hres = ppf->Save (wsz, TRUE);
// Release the pointer to IPersistFile.
ppf->Release ();
}
// Release the pointer to IShellLink.
psl->Release ();
}
CoUninitialize();
return hres;
}