home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip: Shareware for Win 95
/
Chip-Shareware-Win95.bin
/
ostatni
/
delphi
/
delphi2
/
shelink.exe
/
rar
/
SHELINK.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1996-06-19
|
9KB
|
322 lines
//*******************************************************
//* Shell Link Component for Delphi 2.0 *
//* *
//* this is end version *
//* *
//* for new versions send e-mail,s-mail,fax *
//* with you name and e-mail adress to > *
//* *
//* voltr.radek/4600/epr@epr1.ccmail.x400.cez.cz *
//* *
//* (c) 1996 Radek Voltr *
//* Kozeluzska 1523 *
//* Kadan 43201 CZECH Republic Europe *
//* fax. 42 398 2776 *
//* note: this version is free *
//*******************************************************
unit SheLink;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Ole2;
const
SLR_NO_UI = $0001;
SLR_ANY_MATCH = $0002;
SLR_UPDATE = $0004;
SLGP_SHORTPATH = $0001;
SLGP_UNCPRIORITY = $0002;
CLSID_ShellLink: TCLSID = (D1:$00021401; D2:$0; D3:$0; D4:($C0,$0,$0,$0,$0,$0,$0,$46));
IID_IShellLink: TCLSID = (D1:$000214EE; D2:$0; D3:$0; D4:($C0,$0,$0,$0,$0,$0,$0,$46));
type
PShellLink = ^IShellLink;
IShellLink = class(IUnknown)
public
Function GetPath(pszFile:PChar;cchMaxPath:Integer;var pfd:TWin32FindData;fFlags:DWord):HResult; virtual; stdcall; abstract;
Function GetIDList(ppidl:pointer) :HResult; virtual; stdcall; abstract;
Function SetIDList(const pidl:pointer) :HResult; virtual; stdcall; abstract;
Function GetDescription(pszName:PChar;cchMaxName:Integer) :HResult; virtual; stdcall; abstract;
Function SetDescription(Const pszName:PChar) :HResult; virtual; stdcall; abstract;
Function GetWorkingDirectory(pszDir:PChar;cchMaxPath:Integer) :HResult; virtual; stdcall; abstract;
Function SetWorkingDirectory(const pszDir:PChar) :HResult; virtual; stdcall; abstract;
Function GetArguments(pszDir:PChar;cchMaxPath:Integer) :HResult; virtual; stdcall; abstract;
Function SetArguments(const pszArgs:PChar) :HResult; virtual; stdcall; abstract;
Function GetHotkey(pwHotkey:PWord) :HResult; virtual; stdcall; abstract;
Function SetHotkey(wHotkey:Word) :HResult; virtual; stdcall; abstract;
Function GetShowCmd(piShowCmd:PInteger) :HResult; virtual; stdcall; abstract;
Function SetShowCmd(iShowCmd:Integer) :HResult; virtual; stdcall; abstract;
Function GetIconLocation(pszIconPath:PChar;cchIconPath:Integer;piIcon:PInteger) :HResult; virtual; stdcall; abstract;
Function SetIconLocation(const pszIconPath:PChar;iIcon:Integer) :HResult; virtual; stdcall; abstract;
Function SetRelativePath(const pszPathRel:PChar;dwReserved:Dword) :HResult; virtual; stdcall; abstract;
Function Resolve(wnd:hWnd;fFlags:Dword) :HResult; virtual; stdcall; abstract;
Function SetPath(Const pszFile:PChar) :HResult; virtual; stdcall; abstract;
end;
type
TShellLink = class(TComponent)
private
{ Private declarations }
procedure fSetSelfPath(const S:String);
protected
{ Protected declarations }
fUpdate:Boolean;
fPath,
fTarget,
fWorkingDir,
fDescription,
fArguments,
fIconLocation:String;
fIconNumber,
fShowCmd,
fHotKey:Word;
public
{ Public declarations }
// constructor Create;
procedure SetSelfPath(const S:String);
procedure SetUpdate(const S:Boolean);
procedure CreateNew(const Path,Target:String);
procedure SaveToFile(const Path:String);
published
{ Published declarations }
property Path:String read fPath write fSetSelfPath;
property Target:String read fTarget write fTarget;
property WorkingDir:String read fWorkingDir write fWorkingDir;
property Description:String read fDescription write fDescription;
property Arguments:String read fArguments write fArguments;
property IconLocation:String read fIconLocation write fIconLocation;
property HotKey:word read fHotKey write fHotKey;
property ShowCmd:word read fShowCmd write fShowCmd;
property IconNumber:word read fIconNumber write fIconNumber;
property Update:boolean read fUpdate write SetUpdate;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Win95', [TShellLink]);
end;
procedure TShellLink.SetSelfPath(const S:String);
var X3:PChar;
hresx:HResult;
Psl:IShellLink;
Ppf:IPersistFile;
Saver:Array [0..Max_Path] of WideChar;
X1:Array [0..255] Of Char;
Data:TWin32FindData;I,Y:INteger;W:Word;
begin
hresx:=CoCreateInstance(CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER,IID_IShellLink,psl);
If hresx<>0 then Exit;
hresx:=psl.QueryInterface(IID_IPersistFile,ppf);
If hresx<>0 then Exit;
X3:=StrAlloc(255);
StrPCopy(X3,S);
MultiByteToWideChar(CP_ACP,0,X3,-1,Saver,Max_Path);
hresx:=ppf.Load(Saver,STGM_READ);
If hresx<>0 then
begin
MessageBox(0,'File not found (or not link)','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
hresx:=psl.Resolve(0,SLR_ANY_MATCH);
If hresx<>0 then Exit;
hresx:= psl.GetWorkingDirectory(@X1,MAX_PATH );
If hresx<>0 then
begin
MessageBox(0,'Error in get WD','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fWorkingDir:=StrPas(@X1);
hresx:= psl.GetPath( @X1,MAX_PATH,Data,SLGP_UNCPRIORITY);
If hresx<>0 then
begin
MessageBox(0,'Error in get GP','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fTarget:=StrPas(@X1);
hresx:=psl.GetIconLocation(@X1,MAX_PATH,@I);
If hresx<>0 then
begin
MessageBox(0,'Error in get IL','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fIconLocation:=StrPas(@X1);
fIconNumber:=I;
hresx:= psl.GetDescription(@X1,MAX_PATH );
If hresx<>0 then
begin
MessageBox(0,'Error in get DE','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fDescription:=StrPas(@X1);
Y:=0;
hresx:= psl.GetShowCmd(@Y);
If hresx<>0 then
begin
MessageBox(0,'Error in get SC','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fShowCmd:=Y;
W:=0;
hresx:= psl.GetHotKey(@W);
If hresx<>0 then
begin
MessageBox(0,'Error in get HK','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fHotKey:=W;
hresx:= psl.GetArguments(@X1,MAX_PATH );
If hresx<>0 then
begin
MessageBox(0,'Error in get AR','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
fArguments:=StrPas(@X1);
ppf.release;
psl.release;
StrDispose(X3);
fPath:=S;
end;
procedure TShellLink.SetUpdate(const S:Boolean);
begin
SetSelfPath(fPath);
fUpdate:=True;
end;
procedure TShellLink.fSetSelfPath(const S:String);
begin
SetSelfPath(S);
end;
procedure TShellLink.CreateNew(const Path,Target:String);
var X1,X3:PChar;S,S2,S3:String[255];
hresx:HResult;
Psl:IShellLink;
Ppf:IPersistFile;
Saver:Array [0..Max_Path] of WideChar;
begin
hresx:=0;
hresx:=CoCreateInstance(CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER,IID_IShellLink,psl);
If hresx<>0 then
begin
MessageBox(0,'Error in create instance','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
X1:=StrAlloc(255);
X3:=StrAlloc(255);
try
StrPCopy(X1,Target);
hresx:=psl.SetPath(X1);
begin
MessageBox(0,'Error in set path','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
hresx:=psl.QueryInterface(IID_IPersistFile,ppf);
begin
MessageBox(0,'Error in query interface','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
StrPCopy(X3,Path);
MultiByteToWideChar(CP_ACP,0,X3,-1,Saver,Max_Path);
hresx:=ppf.Save(Saver,True);
begin
MessageBox(0,'Error in save','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
finally
ppf.release;
psl.release;
StrDispose(X1);
StrDispose(X3);
end;
End;
procedure TShellLink.SaveToFile(const Path:String);
var X1,X3:PChar;S,S2,S3:String[255];
hresx:HResult;
Psl:IShellLink;
Ppf:IPersistFile;
Saver:Array [0..Max_Path] of WideChar;
begin
hresx:=0;
hresx:=CoCreateInstance(CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER,IID_IShellLink,psl);
If hresx<>0 then
begin
MessageBox(0,'Error in create instance','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
X1:=StrAlloc(255);
X3:=StrAlloc(255);
try
StrPCopy(X1,fTarget);
hresx:=psl.SetPath(PChar(fTarget));
If hresx<>0 then
begin
MessageBox(0,'Error in set path','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
StrPCopy(X1,fDescription);
hresx:=psl.SetDescription(X1);
hresx:=psl.SetWorkingDirectory(PChar(fWorkingDir));
hresx:=psl.SetArguments(PChar(fArguments));
hresx:=psl.SetHotKey(fHotKey);
hresx:=psl.SetShowCmd(fShowCmd);
hresx:=psl.SetIconLocation(PChar(fIconLocation),IconNumber);
hresx:=psl.QueryInterface(IID_IPersistFile,ppf);
If hresx<>0 then
begin
MessageBox(0,'Error in query interface','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
StrPCopy(X3,Path);
MultiByteToWideChar(CP_ACP,0,X3,-1,Saver,Max_Path);
hresx:=ppf.Save(Saver,True);
If hresx<>0 then
begin
MessageBox(0,'Error in save','!! Error !!',mb_IconHand or mb_ok);
Exit;
end;
ppf.release;
finally
psl.release;
StrDispose(X1);
StrDispose(X3);
end;
End;
begin
end.