|
Borland C ++ Builder FAQ
|
||
| The content | The last update: 12/12/2008 | |
|
How to create a label? The author: trainer #include <objidl.h>
#include <shlobj.h>
...
//---------------------------------------------------------------------
#define HOTKEY (modifier, key) ((((modifier) &0xff) <<8) | ((key) &0xff))
//---------------------------------------------------------------------
//label Creation
//Input parameters:
// pwzShortCutFileName - a way and a label name, for example, "C: \\Bloknot.lnk"
// If the way is not specified, the label will be created in a folder specified in the following parameter.
//the Comment: Windows itself does not add to a name.lnk extension
// pszPathAndFileName - a way and an exe-file name, for example, "C: \\Windows \\NotePad.Exe"
// pszWorkingDirectory - the working directory, for example, "C: \\Windows"
// pszArguments - arguments of a command line, for example, "C: \\Doc \\Text.Txt"
// wHotKey - hot key, for example, for Ctrl+Alt+A HOTKEY (HOTKEYF_ALT|HOTKEYF_CONTROL, ' A ')
// iCmdShow - an initial type, for example, SW_SHOWNORMAL
// pszIconFileName - a way and a name of the file containing an icon, for example, "C: \\Windows \\NotePad.Exe"
// int iIconIndex - the icon index in a file, is numbered with 0
bool __ fastcall CreateShortCut (
LPWSTR pwzShortCutFileName,
LPTSTR pszPathAndFileName,
LPTSTR pszWorkingDirectory,
LPTSTR pszArguments,
WORD wHotKey,
int iCmdShow,
LPTSTR pszIconFileName,
int iIconIndex) {
IShellLink * pSL;
IPersistFile * pPF;
HRESULT hRes;
//Obtaining of a copy of a component "Label"
hRes = CoCreateInstance (CLSID_ShellLink,
0,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(LPVOID *) &pSL);
if (SUCCEEDED (hRes)) {
hRes = pSL-> SetPath (pszPathAndFileName);
if (SUCCEEDED (hRes)) {
hRes = pSL-> SetArguments (pszArguments);
if (SUCCEEDED (hRes)) {
hRes = pSL-> SetWorkingDirectory (pszWorkingDirectory);
if (SUCCEEDED (hRes)) {
hRes = pSL-> SetIconLocation (pszIconFileName, iIconIndex);
if (SUCCEEDED (hRes)) {
hRes = pSL-> SetHotkey (wHotKey);
if (SUCCEEDED (hRes)) {
hRes = pSL-> SetShowCmd (iCmdShow);
if (SUCCEEDED (hRes)) {
//Obtaining of a component of storage of parameters
hRes = pSL-> QueryInterface (IID_IPersistFile, (LPVOID *) &pPF);
if (SUCCEEDED (hRes)) {
//Saving of the created label
hRes = pPF-> Save (pwzShortCutFileName, TRUE);
pPF-> Release ();
}
}
}
}
}
}
}
pSL-> Release ();
}
return SUCCEEDED (hRes);
}
|