快捷方式(50分)

  • 主题发起人 主题发起人 differ
  • 开始时间 开始时间
D

differ

Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过以下函数得到快捷方式所指向文件的路径.
但当快捷方式无效时,系统将弹出快捷方式无效的对话框。
我想屏蔽此提示框请问如何实现.
Function GetShortcutTarget(ShortcutFileName: string): string;
var
Psl:IShellLink;
Ppf:IPersistFile;
WideName:Array [0..MAX_PATH] of WideChar;
pResult:Array [0..MAX_PATH-1] Of Char;
Data:TWin32FindData;
const
IID_IPersistFile: TGUID = (
D1:$0000010B; D2:$0000; D3:$0000; D4:($C0,$00,$00,$00,$00,$00,$00,$46));
begin
CoCreateInstance(CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER, IID_IShellLinkA ,psl);
psl.QueryInterface(IID_IPersistFile,ppf);
MultiByteToWideChar(CP_ACP, 0, pChar(ShortcutFilename), -1, WideName, Max_Path);
ppf.Load(WideName,STGM_READ);
psl.Resolve(0,SLR_ANY_MATCH);
psl.GetPath( @pResult,MAX_PATH,Data,SLGP_UNCPRIORITY);
Result:=StrPas(@pResult);
end;
 
>>psl.Resolve(0,SLR_ANY_MATCH);
这句话注释掉就OK了。
同时注意,需要uses comobj,否则蹦叉。
psl.Resolve(0, SLR_ANY_MATCH + SLR_NO_UI + SLR_UPDATE + $7FFF0000);
{SLR_ANY_MATCH:如果不存在,就显示系统对话框,提示快捷方式存在问题
SLR_NO_UI: 如果不存在,则查找快捷方式,此时超时设置为该Flag的高位,单位为毫秒,如果为0,则缺省为3秒,最大为7FFF毫秒
SLR_UPDATE: 如果找到,则更新连接}


uses shlobj, comobj, ActiveX;

Function GetShortcutTarget(ShortcutFileName: string): string;
var
Psl: IShellLink;
Ppf: IPersistFile;
WideName: Array[0..MAX_PATH] of WideChar;
pResult: Array[0..MAX_PATH - 1] Of Char;
Data: TWin32FindData;

const
IID_IPersistFile: TGUID = (
D1: $0000010B; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00, $46));
begin
CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IID_IShellLinkA, psl);

psl.QueryInterface(IID_IPersistFile, ppf);
MultiByteToWideChar(CP_ACP, 0, pChar(ShortcutFilename), -1, WideName, Max_Path);
ppf.Load(WideName, STGM_READ);
psl.GetPath(@pResult, MAX_PATH, Data, SLGP_UNCPRIORITY);
Result := StrPas(@pResult);
end;
 
多谢yzhshi指点迷津.
 
后退
顶部