home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 August
/
VPR9708A.ISO
/
D3TRIAL
/
INSTALL
/
DATA.Z
/
CONTEXTM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-05-12
|
4KB
|
141 lines
unit ContextM;
interface
uses
Windows, ComObj, ComServ, ShlObj, ActiveX, ShellApi, SysUtils, Registry;
Const
CLSID_ContextMenuShellExtension: TGUID = (
D1:$8e3e0f0a; D2:$0fcc; D3:$11ce; D4:($bc, $b0, $b3, $fd, $0e, $25, $38, $1a));
type
TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
private
szFile: array[0..MAX_PATH] of Char;
public
function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
uFlags: UINT): HResult; stdcall;
function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
function GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
pszName: LPSTR; cchMax: UINT): HResult; stdcall;
function Initialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
hKeyProgID: HKEY): HResult; stdcall;
end;
implementation
function GetCompilerPath: string;
// Returns string containing path to Delphi command line compiler
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('\SOFTWARE\Borland\Delphi\3.0', False);
Result := ReadString('RootDir');
end;
Result := Result + '\bin\dcc32.exe "%s"';
finally
Reg.Free;
end;
end;
function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
idCmdLast, uFlags: UINT): HResult;
begin
// Add one menu item to context menu
InsertMenu (Menu, indexMenu, MF_STRING or MF_BYPOSITION, idCmdFirst,
'コンパイル...');
// Return number of menu items added
Result := 1;
end;
function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
var
H: THandle;
begin
// Make sure we are not being called by an application
if HiWord(Integer(lpici.lpVerb)) <> 0 then
begin
Result := E_FAIL;
Exit;
end;
// Make sure we aren't being passed an invalid argument number
if LoWord(lpici.lpVerb) > 0 then
begin
Result := E_INVALIDARG;
Exit;
end;
// Execute the command specified by lpici.lpVerb.
if LoWord(lpici.lpVerb) = 0 then
begin
// invoke Delphi command line compiler
H := WinExec(PChar(Format(GetCompilerPath, [szFile])), lpici.nShow);
if H < 32 then
MessageBox(lpici.hWnd, 'Error executing Delphi compiler.', 'Error',
MB_ICONERROR or MB_OK);
end;
Result := NOERROR;
end;
function TContextMenu.GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
pszName: LPSTR; cchMax: UINT): HRESULT;
begin
if idCmd = 0 then
begin
// return help string for menu item
strCopy(pszName, 'Compile the selected Delphi project');
Result := NOERROR;
end
else
Result := E_INVALIDARG;
end;
function TContextMenu.Initialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
hKeyProgID: HKEY): HResult;
var
medium: TStgMedium;
fe: TFormatEtc;
begin
with fe do
begin
cfFormat := CF_HDROP;
ptd := Nil;
dwAspect := DVASPECT_CONTENT;
lindex := -1;
tymed := TYMED_HGLOBAL;
end;
// Fail the call if lpdobj is Nil.
if lpdobj = Nil then
begin
Result := E_FAIL;
Exit;
end;
// Render the data referenced by the IDataObject pointer to an HGLOBAL
// storage medium in CF_HDROP format.
Result := lpdobj.GetData(fe, medium);
if Failed(Result) then Exit;
// If only one file is selected, retrieve the file name and store it in
// szFile. Otherwise fail the call.
if DragQueryFile(medium.hGlobal, $FFFFFFFF, Nil, 0) = 1 then
begin
DragQueryFile(medium.hGlobal, 0, szFile, SizeOf(szFile));
Result := NOERROR;
end
else
Result := E_FAIL;
ReleaseStgMedium(medium);
end;
initialization
TComObjectFactory.Create(ComServer, TContextMenu, CLSID_ContextMenuShellExtension,
'', 'Delphi 3.0 ContextMenu Example', ciMultiInstance);
end.