如何对快捷方式进行操作?

fenex 2002-08-14 09:58:14
如:生成一个快捷方式,读取快捷方式文件所指向的文件的路径等
...全文
66 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
stavck 2002-08-14
  • 打赏
  • 举报
回复
解析快捷方式:
HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
HRESULT hres;
IShellLink* psl;
char szGotPath[MAX_PATH];
char szDescription[MAX_PATH];
WIN32_FIND_DATA wfd;

*lpszPath = 0; // assume failure

// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(&CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;

// Get a pointer to the IPersistFile interface.
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
&ppf);
if (SUCCEEDED(hres)) {
WORD wsz[MAX_PATH];

// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz,
MAX_PATH);

// Load the shortcut.
hres = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
if (SUCCEEDED(hres)) {

// Resolve the link.
hres = psl->lpVtbl->Resolve(psl, hwnd, SLR_ANY_MATCH);
if (SUCCEEDED(hres)) {

// Get the path to the link target.
hres = psl->lpVtbl->GetPath(psl, szGotPath,
MAX_PATH, (WIN32_FIND_DATA *)&wfd,
SLGP_SHORTPATH );
if (!SUCCEEDED(hres)
HandleErr(hres); // application-defined function

// Get the description of the target.
hres = psl->lpVtbl->GetDescription(psl,
szDescription, MAX_PATH);
if (!SUCCEEDED(hres))
HandleErr(hres);
lstrcpy(lpszPath, szGotPath);
}
}
// Release the pointer to the IPersistFile interface.
ppf->lpVtbl->Release(ppf);
}
// Release the pointer to the IShellLink interface.
psl->lpVtbl->Release(psl);
}
return hres;
}
stavck 2002-08-14
  • 打赏
  • 举报
回复
//创建快捷方式

BOOL CreateLink (

LPSTR szPath,//快捷方式的目标应用程序名

LPSTR szLink)//快捷方式的数据文件名(*.lnk)

{

HRESULT hres ;

IShellLink * psl ;

IPersistFile* ppf ;

WORD wsz[ MAX_PATH] ;

//创建一个IShellLink实例

hres = CoCreateInstance( CLSID_ShellLink, NULL,

CLSCTX_INPROC_SERVER, IID_IShellLink,

(void **)&psl) ;

if( FAILED( hres))

return FALSE ;

//设置目标应用程序

psl -> SetPath( szPath) ;

//设置快捷键(此处设为Shift+Ctrl+'R')

psl -> SetHotkey( MAKEWORD( 'R',

HOTKEYF_SHIFT ¦HOTKEYF_CONTROL)) ;

//从IShellLink获取其IPersistFile接口

//用于保存快捷方式的数据文件 (*.lnk)

hres = psl -> QueryInterface( IID_IPersistFile,

(void**)&ppf) ;

if( FAILED( hres))

return FALSE ;

// 确保数据文件名为ANSI格式

MultiByteToWideChar( CP_ACP, 0, szLink, -1,

wsz, MAX_PATH) ;

//调用IPersistFile::Save

//保存快捷方式的数据文件 (*.lnk)

hres = ppf -> Save( wsz, STGM_READWRITE) ;

//释放IPersistFile和IShellLink接口

ppf -> Release( ) ;

psl -> Release( ) ;

return TRUE;

}
stavck 2002-08-14
  • 打赏
  • 举报
回复
http://www.codeguru.com/shell/filelinks.shtml

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧