您好,登錄后才能下訂單哦!
BOOL CreateLink(LPWSTR szPath, LPCWSTR szLink) { HRESULT hres; IShellLink * psl; IPersistFile* ppf; WORD wsz[MAX_PATH]; CoInitialize(NULL); hres = CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); if (FAILED(hres)) { return FALSE; } psl->SetPath(szPath); psl->SetHotkey(MAKEWORD('M', HOTKEYF_SHIFT | HOTKEYF_CONTROL)); hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); if (FAILED(hres)) return FALSE; //MultiByteToWideChar(CP_ACP, 0, szLink, -1, (LPWSTR)&wsz[0], MAX_PATH); hres = ppf->Save((LPCOLESTR)szLink, STGM_READWRITE); ppf->Release(); psl->Release(); CoUninitialize(); return TRUE; } VOID CreateShortCut(CString strAppName) { TCHAR DeskTopPath[MAX_PATH]; TCHAR currDirPath[MAX_PATH]; LPITEMIDLIST pidl = NULL; if (SUCCEEDED(SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 0, &pidl))) { SHGetPathFromIDList(pidl, DeskTopPath); IMalloc* pMalloc = NULL; ::SHGetMalloc(&pMalloc); pMalloc->Free(pidl); pMalloc->Release(); } CString tmp1 = GetApplicationPath2() + strAppName; TCHAR szFilename[MAX_PATH]; TCHAR szDrive[MAX_PATH]; TCHAR szPath[MAX_PATH]; TCHAR szExt[MAX_PATH]; _wsplitpath_s(tmp1, szDrive,255, szPath,255, szFilename,255, szExt,255); USES_CONVERSION; if (_access(W2A(tmp1), 0) == -1)return; CString tmp; tmp = DeskTopPath; tmp += "\\"; tmp += szFilename; tmp += _T(".lnk"); if (!CreateLink(tmp1.GetBuffer(), tmp)) AfxMessageBox(_T("創建快捷方式出錯!")); tmp1.ReleaseBuffer(); }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。