本文整理汇总了C++中IShellLink::SetDescription方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellLink::SetDescription方法的具体用法?C++ IShellLink::SetDescription怎么用?C++ IShellLink::SetDescription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellLink
的用法示例。
在下文中一共展示了IShellLink::SetDescription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wprintf
HRESULT
CreateLink(LPCWSTR aTargetPath, LPCWSTR aShortcutPath, LPCWSTR aDescription)
{
HRESULT hres;
IShellLink* psl;
wprintf(L"creating shortcut: '%s'\n", aShortcutPath);
CoInitialize(nullptr);
hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (FAILED(hres)) {
CoUninitialize();
return hres;
}
psl->SetPath(aTargetPath);
if (aDescription) {
psl->SetDescription(aDescription);
} else {
psl->SetDescription(L"");
}
IPersistFile* ppf = nullptr;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres)) {
hres = ppf->Save(aShortcutPath, TRUE);
ppf->Release();
}
psl->Release();
CoUninitialize();
return hres;
}
示例2: CreateLink
long CreateLink(LPCSTR lpszPathObj,LPSTR lpszPathLink,LPSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink,(void**)&psl);
if (SUCCEEDED(hres))
{
IPersistFile *ppf;
hres = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
ZeroMemory(wsz,sizeof(WORD)*MAX_PATH);
hres = psl->SetPath(lpszPathObj);
hres = psl->SetDescription(lpszDesc);
hres = psl->SetIconLocation(lpszPathObj,0);
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
hres = ppf->Save(wsz, TRUE);
ppf->Release();
if(!SUCCEEDED(hres))
return false;
}
else
return false;
psl->Release();
}
else
return false;
CoUninitialize();
return true;
}
示例3: CreateLink
HRESULT CSysDialog::CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
hres = CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
if (SUCCEEDED(hres)) {
IPersistFile *ppf;
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres)) {
WCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
示例4: Create
bool CShortCut::Create(void)
{
bool results;
HRESULT hres;
IShellLink *psl;
IPersistFile *ppf;
wchar_t wsz[MAX_PATH];
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
results=false;
if (SUCCEEDED(hres))
{
psl->SetPath(LinkFile.c_str());
psl->SetWorkingDirectory(LinkPath.c_str());
psl->SetDescription(LinkDescription.c_str());
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres))
{
MultiByteToWideChar(CP_ACP, 0, FileName.c_str(), -1,
wsz, MAX_PATH);
hres = ppf->Save(wsz, true);
ppf->Release();
results=true;
}
psl->Release();
}
CoUninitialize();
return results;
}
示例5: CreateLink
static HRESULT CreateLink(LPCTSTR lpszPathObj, LPCTSTR lpszPathLink,
LPCTSTR pszArgs, LPCTSTR lpszDesc, LPCTSTR lpszWdir)
{
HRESULT h_result;
IShellLink* psl;
CoInitialize( NULL );
h_result = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(LPVOID *) &psl);
if (SUCCEEDED(h_result))
{
IPersistFile* ppf;
psl->SetPath(lpszPathObj);
psl->SetArguments(pszArgs);
psl->SetDescription(lpszDesc);
psl->SetWorkingDirectory(lpszWdir);
h_result = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(h_result))
{
h_result = ppf->Save(lpszPathLink, TRUE);
ppf->Release();
}
psl->Release();
}
return h_result;
}
示例6: my_createshortcut
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
bool my_createshortcut(const TCHAR *source, const TCHAR *target, const TCHAR *description)
{
HRESULT hres;
IShellLink* psl;
TCHAR tmp[MAX_DPATH];
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(target);
psl->SetDescription(description);
// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
// Save the link by calling IPersistFile::Save.
_tcscpy (tmp, source);
const TCHAR *ext = _tcsrchr (tmp, '.');
if (!ext || _tcsicmp (ext, _T(".lnk")) != 0)
_tcscat (tmp, _T(".lnk"));
hres = ppf->Save(tmp, TRUE);
ppf->Release();
}
psl->Release();
}
return SUCCEEDED(hres);
}
示例7: CreateLinkToFile
HRESULT CreateLinkToFile(TCHAR *PathToFile,TCHAR *PathToLink,TCHAR *LinkDescription)
{
IShellLink *pShellLink = NULL;
IPersistFile *pPersistFile = NULL;
WCHAR PathToLinkW[MAX_PATH];
HRESULT hr;
hr = CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,
IID_IShellLink,(LPVOID*)&pShellLink);
if(SUCCEEDED(hr))
{
pShellLink->SetPath(PathToFile);
pShellLink->SetDescription(LinkDescription);
hr = pShellLink->QueryInterface(IID_IPersistFile,(LPVOID*)&pPersistFile);
if(SUCCEEDED(hr))
{
#ifndef UNICODE
MultiByteToWideChar(CP_ACP,0,PathToLink,-1,PathToLinkW,MAX_PATH);
#else
StringCchCopy(PathToLinkW,SIZEOF_ARRAY(PathToLinkW),PathToLink);
#endif
pPersistFile->Save(PathToLinkW,TRUE);
pPersistFile->Release();
}
pShellLink->Release();
}
return hr;
}
示例8: CreateLink
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc) {
HRESULT hres;
IShellLink* psl;
CoInitialize(0);
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetArguments(lpszArguments);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres)) {
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(lpszPathLink, TRUE);
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return hres;
}
示例9: CreateShellLink
bool CreateShellLink(const char *filepath, const char *linkpath, const char *desc, int icon)
{
HRESULT hres;
IShellLink* psl;
IPersistFile* ppf;
hres = CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
(PVOID *) &psl);
if(SUCCEEDED(hres)) {
psl->SetPath(filepath);
psl->SetDescription(desc);
if(icon >= 0)
psl->SetIconLocation(filepath, icon);
hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf);
if (SUCCEEDED(hres)) {
WCHAR szPath[_MAX_PATH] = { 0 };
MultiByteToWideChar(CP_ACP, 0, linkpath, strlen(linkpath), szPath, _MAX_PATH);
hres = ppf->Save(szPath, TRUE);
ppf->Release();
}
}
psl->Release();
CoUninitialize();
return SUCCEEDED(hres);
}
示例10: CreateLink
bool CreateLink(std::string& path, std::string& linkPath, std::string& description)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
wstring pathW = KrollUtils::UTF8ToWide(path);
wstring linkPathW = KrollUtils::UTF8ToWide(linkPath);
wstring descriptionW = KrollUtils::UTF8ToWide(description);
// Set the path to the shortcut target and add the description.
psl->SetPath(pathW.c_str());
psl->SetDescription(descriptionW.c_str());
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf);
if (SUCCEEDED(hres))
{
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(linkPathW.c_str(), TRUE);
ppf->Release();
return true;
}
psl->Release();
}
return false;
}
示例11: createShortcut
void FileSystemManager::createShortcut(QString shortcutFilePath, QString pathToTarget, QString desc)
{
HRESULT hres = NULL;
IShellLink * psl = NULL;
IPersistFile * ppf = NULL;
QDir workingDirectory = scnManager->getWorkingDirectory();
QDir linkPath = workingDirectory / shortcutFilePath;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl);
if (SUCCEEDED(hres))
{
// Set the path to the shortcut target
psl->SetPath((LPCWSTR) pathToTarget.utf16());
psl->SetDescription((LPCWSTR) desc.utf16());
// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (void **) &ppf);
if (SUCCEEDED(hres))
{
// Save the link by calling IPersistFile::Save.
hres = ppf->Save((LPCOLESTR) native(linkPath).utf16(), TRUE);
ppf->Release();
}
psl->Release();
}
}
示例12: CreateFileShortcut
BOOL CreateFileShortcut(LPCWSTR lpszFileName, LPCWSTR lpszLnkFileDir, LPCWSTR lpszLnkFileName, LPCWSTR lpszWorkDir, WORD wHotkey, LPCTSTR lpszDescription, int iShowCmd)
{
if (lpszLnkFileDir == NULL)
return FALSE;
HRESULT hr;
IShellLink *pLink; //IShellLink对象指针
IPersistFile *ppf; //IPersisFil对象指针
//创建IShellLink对象
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pLink);
if (FAILED(hr))
return FALSE;
//从IShellLink对象中获取IPersistFile接口
hr = pLink->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (FAILED(hr))
{
pLink->Release();
return FALSE;
}
//目标
if (lpszFileName == NULL)
pLink->SetPath(_wpgmptr);
else
pLink->SetPath(lpszFileName);
//工作目录
if (lpszWorkDir != NULL)
pLink->SetWorkingDirectory(lpszWorkDir);
//快捷键
if (wHotkey != 0)
pLink->SetHotkey(wHotkey);
//备注
if (lpszDescription != NULL)
pLink->SetDescription(lpszDescription);
//显示方式
pLink->SetShowCmd(iShowCmd);
//快捷方式的路径 + 名称
wchar_t szBuffer[MAX_PATH];
if (lpszLnkFileName != NULL) //指定了快捷方式的名称
wsprintf(szBuffer, L"%s\\%s", lpszLnkFileDir, lpszLnkFileName);
//保存快捷方式到指定目录下
hr = ppf->Save(szBuffer, TRUE);
ppf->Release();
pLink->Release();
return SUCCEEDED(hr);
}
示例13: _CreateShellLink
HRESULT _CreateShellLink(PCSTR pszArguments, PCWSTR pszTitle, LPCSTR szDescription, IShellLink **ppsl)
{
IShellLink *psl;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
if (SUCCEEDED(hr))
{
// Determine our executable's file path so the task will execute this application
CHAR szAppPath[MAX_PATH];
if (GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath)))
{
hr = psl->SetPath(szAppPath);
if (SUCCEEDED(hr))
{
hr = psl->SetArguments(pszArguments);
if (SUCCEEDED(hr))
{
hr = psl->SetDescription( szDescription );
if (SUCCEEDED(hr))
{
// The title property is required on Jump List items provided as an IShellLink
// instance. This value is used as the display name in the Jump List.
IPropertyStore *pps;
hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
if (SUCCEEDED(hr))
{
PROPVARIANT propvar;
hr = InitPropVariantFromString(pszTitle, &propvar);
if (SUCCEEDED(hr))
{
hr = pps->SetValue(PKEY_Title, propvar);
if (SUCCEEDED(hr))
{
hr = pps->Commit();
if (SUCCEEDED(hr))
{
hr = psl->QueryInterface(IID_PPV_ARGS(ppsl));
}
}
PropVariantClear(&propvar);
}
pps->Release();
}
}
}
}
}
else
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
psl->Release();
}
return hr;
}
示例14: onFileCreateProjectShortcut
void UiPlayer::onFileCreateProjectShortcut(void)
{
WCHAR shortcutPathBuff[MAX_PATH + 1] = {0};
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = L"Shortcut (*.lnk)\0*.lnk\0";
ofn.lpstrTitle = L"Create Project Shortcut";
ofn.Flags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
ofn.lpstrFile = shortcutPathBuff;
ofn.nMaxFile = MAX_PATH;
if (!GetSaveFileName(&ofn)) return;
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
IShellLink* psl;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// args
string args = m_project.makeCommandLine();
// Set the path to the shortcut target and add the description.
psl->SetPath(__wargv[0]);
wstring wargs;
wargs.assign(args.begin(), args.end());
psl->SetArguments(wargs.c_str());
psl->SetDescription(L"UiPlayer");
// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
// Save the link by calling IPersistFile::Save.
size_t len = wcslen(shortcutPathBuff);
if (_wcsicmp(shortcutPathBuff + len - 4, L".lnk") != 0)
{
wcscat_s(shortcutPathBuff, L".lnk");
}
hres = ppf->Save(shortcutPathBuff, TRUE);
ppf->Release();
}
psl->Release();
}
}
示例15: createLinks
void createLinks(const std::string name, const std::string &exe)
{
CoInitialize(NULL);
HRESULT res;
IShellLink *lnk = NULL;
res = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, reinterpret_cast<void**>(&lnk));
if(!SUCCEEDED(res))
fail("Couldn't create shortcut links");
lnk->SetPath(exe.c_str());
lnk->SetDescription(name.c_str());
//lnk->SetIconLocation("where", 0);
IPersistFile *pf = NULL;
res = lnk->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&pf));
if(!SUCCEEDED(res))
{
lnk->Release();
fail("Couldn't create shortcut links");
}
// Use this for links you don't want to highlight, ie. everything
// except the main program link. May need some rewriting.
/*
PROPVARIANT pvar;
pvar.vt = VT_BOOL;
pvar.boolVal = VARIANT_TRUE;
pf->SetValue(PKEY_AppUserModel_ExcludeFromShowInNewInstall, pvar);
*/
std::string lname = name + ".lnk";
// Save desktop link
fs::path link = getPathCSIDL(CSIDL_DESKTOPDIRECTORY) / lname;
pf->Save(toWide(link.string()), TRUE);
// Create start menu directory
link = getPathCSIDL(CSIDL_PROGRAMS) / name;
fs::create_directories(link);
// Save the start menu link
link /= lname;
pf->Save(toWide(link.string()), TRUE);
pf->Release();
lnk->Release();
}