c++查找桌面快捷方式,没有就创建

xiaoxiao2025-06-12  24

bool GetFileList(std::string path) { path += "\\*"; CFileFind finder; BOOL working = finder.FindFile(path.c_str()); while (working) { working = finder.FindNextFile(); if (!finder.IsDirectory() && !finder.IsDots()) { if(finder.GetFileName() == "test.lnk") return true; } } return false; } bool findLink() { char Path[MAX_PATH+1]; std::string strDestDir; LPITEMIDLIST pidl; LPMALLOC pShell; if(SUCCEEDED(SHGetMalloc(&pShell))) { if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOPDIRECTORY,&pidl))) { if(!SHGetPathFromIDList(pidl,Path)) { pShell->Free(pidl); } pShell->Release(); strDestDir = Path; return GetFileList(strDestDir); } } return false; } bool CreateLink2Desktop() { HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { IShellLink *pisl; hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pisl); if (SUCCEEDED(hr)) { IPersistFile* pIPF; TCHAR pszPeFileName[MAX_PATH+1] = {0}; GetModuleFileName(NULL, pszPeFileName, MAX_PATH); pisl->SetPath(pszPeFileName); hr = pisl->QueryInterface(IID_IPersistFile, (void**)&pIPF); if (SUCCEEDED(hr)) { WCHAR szStartPath[MAX_PATH] = {0}; SHGetSpecialFolderPathW(NULL,szStartPath, CSIDL_DESKTOP, 0); PathAppendW(szStartPath,L"test.lnk"); USES_CONVERSION; LPCOLESTR lpOleStr = szStartPath; pIPF->Save(lpOleStr, FALSE); pIPF->Release(); } pisl->Release(); } CoUninitialize(); } return true; }

 

转载请注明原文地址: https://www.6miu.com/read-5031742.html

最新回复(0)