如何创建快捷方式并添加到开始菜单、桌面、任务栏....

创建快捷方式的方法(.lnk)

::CoInitialize(NULL);

IShellLink* pIShellLink;
HRESULT hRes = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pIShellLink);
if (!SUCCEEDED(hRes)) {
return false;
}

pIShellLink->SetPath(L”x:\\xx\\xx.exe”);
pIShellLink->SetDescription(L”这是一个测试的桌面快捷方式”);
pIShellLink->SetHotkey(MAKEWORD(‘R’, HOTKEYF_SHIFT | HOTKEYF_CONTROL));
IPersistFile* pIPersistFile;
hRes = pIShellLink->QueryInterface(IID_IPersistFile, (void**)&pIPersistFile);
if (!SUCCEEDED(hRes)) {
return false;
}

hRes = pIPersistFile->Save(savePath.c_str(), TRUE);
if (!SUCCEEDED(hRes)) {
return false;
}

pIPersistFile->Release();
pIShellLink->Release();

::CoUninitialize();

 

快捷方式(.url)

if (m_sIconFile.length() == 0)
{
return false;
}

IniFile iniFs;
iniFs.setFilename(m_sLnkFile.c_str());
std::string curUrl = iniFs.getStr(“InternetShortcut”, “URL”);

if (curUrl == m_url)
{//一样,则不用重写
return true;
}

std::string str;

str += “[{000214A0-0000-0000-C000-000000000046}]\r\n”;
str += “Prop3=19,2\r\n”;
str += “[InternetShortcut]\r\n”;
str += “URL=”;
str += m_url;
str += “\r\n”;
str += “IDList=\r\n”;
str += “IconFile=”;
str += m_sIconFile;
str += “\r\n”;
str += “IconIndex=0\r\n”;

// 设置文件为正常方式
DWORD dwAttribute = FILE_ATTRIBUTE_NORMAL;
SetFileAttributesA(m_sLnkFile.c_str() , dwAttribute);

FILE* fp = fopen(m_sLnkFile.c_str(), “wb”);
fwrite(str.c_str(), str.length(), 1, fp);
fclose(fp);

 

添加到开始菜单、桌面只需要将快捷方式存储到相应位置就行

 

任务栏则需要调用ShellExecute(NULL, L”taskbarpin”, lnkPath, NULL, NULL, 0);

 

艺文笔记:https://www.xuwenyan.com/archives/89

    原文作者:艺文笔记
    原文地址: https://blog.csdn.net/qq_30135549/article/details/75116605
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞