Delphi - объектно-ориентированный язык программирования, разработанный компанией Borland в 1995 году. Он основан на языке программирования Pascal, но имеет более расширенные возможности и добавлены новые функции.
Delphi является интегрированной средой разработки (IDE), которая позволяет разрабатывать программное обеспечение для различных платформ, включая Windows, macOS, Android и iOS. Delphi достигает многоплатформенности с помощью...
// Откройте Delphi, выберите в меню New... Dynamic
link library
// Скопируйте нижеприведенный текст DLL
// Скомпилируйте проект.
// Теперь нужно зарегистрировать полученную
библиотеку.
// Наберите в командной строке regsvr32.exe
sendtoweb.dll
// После этого откройте Windows Explorer и вы
увидите новый
// пункт меню...
Sendtoweb;
Вы можете модернизировать код для большей гибкости.
(TComObjectFactory)
public UpdateRegistry(Register : Boolean);
override ; ; (TComObject, IShellExtInit, IContextMenu)
private ;
function BuildSubMenu(Menu: HMENU; IndexMenu: Integer;
var IDCmdFirst: Integer): HMENU;
protected [0..MAX_PATH] of Char;
IShellExtInit.Initialize =
IShellExtInit_Initialize;
public IShellExtInit_Initialize(pidlFolder:
PItemIDList; lpdobj: ;
QueryContextMenu(Menu: HMENU;
indexMenu, idCmdFirst, idCmdLast, uFlags: UINT):
HResult; stdcall ;
function InvokeCommand(var lpici:
TCMInvokeCommandInfo): HResult; stdcall ;
function GetCommandString(idCmd, uType: UINT;
pwReserved: PUINT; ; ; [0..3] of string = (
'', '&STW Web Upload', '&STW FTPClient', '&STW Setup'
); ReadDefaultPAth: string ;
var ;
Reg: TRegistry; Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
Path :=
'SOFTWAREMicrosoftWindowsCurrentVersionApp Paths';
KeyExists(Path) then
begin
OpenKey(Path + 'sendtoweb.exe',
false ); ;
;
finally ; ; TContextMenuFactory.UpdateRegistry(Register : Boolean);
begin UpdateRegistry(Register );
Register then
begin ; ;
Если Menu = nil, мы создаем новый хэндл меню и возвращаем его как
результат TContextMenu.BuildSubMenu(Menu: HMENU; IndexMenu: Integer;
var IDCmdFirst: Integer): HMENU;
var Menu = 0 then
Result := CreateMenu
else menuitemInfo do
begin MIIM_DATA or
MIIM_ID or MIIM_SUBMENU or
MIIM_TYPE or MIIM_CHECKMARKS;
fType := MFT_STRING;
fState := MFS_ENABLED;
hSubMenu := 0;
hbmpChecked := 0;
hbmpUnchecked := 0;
end ; i := 0 to High(MenuCommandStrings) do
begin i = 0 then
menuitemInfo.fType := MFT_SEPARATOR
else
menuiteminfo.ftype := MFT_String;
if i = 1 then
menuitemInfo.fstate := MFS_ENABLED or
MFS_DEFAULT
menuitemInfo.fstate := MFS_ENABLED;
,
menuItemInfo); ; ; TContextMenu.IShellExtInit_Initialize(pidlFolder: PItemIDList;
lpdobj: IDataObject; hKeyProgID: HKEY): HResult;
var fe do
begin ;
dwAspect := DVASPECT_CONTENT;
lindex := -1;
tymed := TYMED_HGLOBAL;
end ; lpdobj = nil then
begin ; Failed(Result) then
Exit;
DragQueryFile(medium.hGlobal, $FFFFFFFF, nil , 0) = 1
then ; TContextMenu.QueryContextMenu(Menu: HMENU;
indexMenu, idCmdFirst, idCmdLast, uFlags: UINT): HResult;
var ;
I: Integer; ; TContextMenu.InvokeCommand(var lpici:
TCMInvokeCommandInfo): HResult;
var HIWORD(Integer(lpici.lpVerb)) <> 0 then
Result := E_FAIL
else idCmd of
1:
begin
,
Pchar(ExtractFileName(ReadDefaultPath)),
Pchar('Direct' + '"' + szfile + '"'), nil , SW_SHOW);
;
3:
begin
ShellExecute(GetDesktopWindow, nil ,
Pchar(ExtractFileName(ReadDefaultPath)),
Pchar('Path'), nil , SW_SHOW);
;
2:
ShellExecute(GetDesktopWindow, nil ,
Pchar(ExtractFileName(ReadDefaultPath)),
PChar(''), nil ,
SW_SHOW);
Result := E_FAIL;
end ;
end ; ; TContextMenu.GetCommandString(idCmd, uType: UINT;
pwReserved: PUINT; pszName: LPSTR; cchMax: UINT): HResult;
; .
unit
{ Реализация COM объекта расширения оболочки
Windows Explorer. Этот
COM объект способен перенаправлять запросы компоненту TPopupMenu.
Компонент
TPopupMenu должен находиться на форме MenuComponentForm.
Компонент TContextMenu регистрируется как глобальным обработчик
контекстного меню. Это достигается модификацией ключа реестра
HKEY_CLASSES_ROOT*ShellExContextMenuHandlers.
jfl
}
interface
uses
Classes, ComServ, ComObj, ActiveX, Windows, ShlObj, Interfaces, Menus,
ShellAPI, SysUtils, registry;
type
TContextMenuFactory = class
procedure
end
TContextMenu = class
FFileName: string
szFile: array
IDataObject;
hKeyProgID: HKEY): HResult; stdcall
pszName: LPSTR; cchMax: UINT): HResult;
stdcall
end
var
const
MenuCommandStrings: array
implementation
function
path: string
begin
Reg := TRegistry.CReate;
try
with
if
Result := ReadString(#0);
closekey;
end
end
Reg.CloseKey;
Reg.Free;
end
end
procedure
inherited
CreateRegKey('*ShellExContextMenuHandlersSendToWeb', '',
GUIDToString(Class_ContextMenu));
CreateRegKey('CLSID' + GUIDToString(ClassID) + '' +
ComServer.ServerKey, 'ThreadingModel',
'Apartment');
end
else
begin
DeleteRegKey('*ShellExContextMenuHandlersSendToWeb');
end
end
{ Построение контекстного меню с использованием
хэндла существующего меню.
функции. Заметьте, что обработчик не поддерживаетвложенные (рекурсивные)
меню. }
function
i: Integer;
menuItemInfo: TMenuItemInfo;
begin
if
Result := Menu;
cbSize := SizeOf(TMenuItemInfo);
fMask := MIIM_CHECKMARKS or
MIIM_STATE or
for
if
else
menuitemInfo.dwTypeData := PChar(MenuCommandStrings[i]);
menuitemInfo.wID := IDCmdFirst;
InsertMenuItem(Result, IndexMenu + i, True
Inc(IDCmdFirst);
end
end
function
medium: TStgMedium;
fe: TFormatEtc;
begin
with
cfFormat := CF_HDROP;
ptd := nil
Result := E_FAIL;
Exit;
end
Result := lpdobj.GetData(fe, medium);
if
begin
DragQueryFile(medium.hGlobal, 0, szFile, SizeOf(szFile));
Result := NOERROR;
end
else
Result := E_FAIL;
ReleaseStgMedium(medium);
end
function
extension: string
idLastCommand: Integer;
begin
Result := E_FAIL;
idLastCommand := idCmdFirst;
//for i := 0 to GFileExtensions.Count - 1 do
// if Pos(Lowercase(GFileExtensions[
i ]),lowercase(extension))=0 then
// begin
BuildSubMenu(Menu, indexMenu, idLastCommand);
// Return value is number of items added
to context menu
Result := idLastCommand - idCmdFirst;
// Exit;
// end;
end
function
idCmd: UINT;
begin
if
begin
idCmd := LOWORD(lpici.lpVerb);
Result := S_OK;
case
ShellExecute(GetDesktopWindow, nil
end
end
else
end
function
begin
Result := S_OK;
end
initialization
// Инициализируем список расширений
GFileExtensions := TStringList.Create;
// GFileExtensions.Add( 'setup msn' );
finalization
GFileExtensions.Free;
end