1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
function TContextTools.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
idCmdLast, uFlags: UINT): HResult;
Const
Caption:String='Modifier l''extension';
var
Command_ID,
hSub_Menu : HMenu;
MenuInfo : TMenuItemInfo;
begin
Result:= 0;
if ((uFlags and $0000000F) = CMF_NORMAL) or
((uFlags and CMF_EXPLORE) <> 0) then
begin
MenuIndex1 := indexMenu; // index du sous menu
Command_ID := idCmdFirst;
MenuInfo.cbSize := SizeOf(MenuInfo);
hSub_Menu := CreateMenu;
Inc(Command_ID);
MenuIndex2 := MenuIndex1+1; // index de l'entrée du sous menu
InsertMenu(hSub_Menu,MenuIndex2,MF_BYPOSITION or MF_STRING,Command_ID,'Copier et renommer en 001');
Inc(Command_ID);
MenuIndex3 := MenuIndex2+1;
InsertMenu(hSub_Menu,MenuIndex3,MF_BYPOSITION or MF_STRING,Command_ID,'Renommer en 001');
{
si d'autre entrées :
Inc(Command_ID);
MenuIndex4 := MenuIndex3+1;
InsertMenu(hSub_Menu,MenuIndex4,MF_BYPOSITION or MF_STRING,Command_ID,'Third Memu Itrm');
}
With MenuInfo do
begin
fMask := MIIM_ID or MIIM_SUBMENU or MIIM_TYPE;
fType := MFT_STRING;
fState := 0;
dwTypeData :=Pchar(Caption);
cch := Length(Caption); // 20 :longueur de chaine;
hSubMenu := hSub_Menu;
wID := idCmdFirst;
hbmpChecked := 0;
hbmpUnchecked := 0;
end;
InsertMenuItem(Menu,MenuIndex1,True,MenuInfo);
Result := 3{ 1 sous-Menu +2 entrées};
end;
end;
function TContextTools.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
var
lResult : Byte;
FileName,
MessageString : String;
lMenuIndex : Integer;
begin
Result := E_FAIL;
lResult:=lSuccess;
MessageString:='';
lMenuIndex := Integer(lpici.lpVerb);
// Make sure we are not being called by an application
if HiWord(lMenuIndex) <> 0 then
begin
Exit;
end;
Result := NOERROR;
// Make sure we aren't being passed an invalid argument number
// and
// Execute the command specified by lpici.lpVerb
// by invoking the Delphi command line compiler.
Filename:= string(FFileName);
if LoWord(lMenuIndex) = MenuIndex2
then
begin
lResult:=Operation(lpici.hWnd,ID_COPYBAK,Filename);
if lResult<>lSUCCESS
then Result := E_FAIL;
end
else
if LoWord(lMenuIndex) = MenuIndex3
then
begin
Result:=Operation(lpici.hWnd,ID_BAKNAME,Filename);
if lResult<>lSUCCESS
then Result := E_FAIL;
end
else
begin
Result := E_INVALIDARG;
Exit;
end;
If lResult= lNOFILE
then MessageString:='Fichier introuvable.';
If lResult= lREAD_DIRECTORY_ERROR
then MessageString:='Erreur de lecture du répertoire.';
if MessageString<>''
then MessageBox(lpici.hWnd, Pchar(MessageString),'Erreur',MB_ICONERROR or MB_OK)
end; |
Partager