uses
ComObj, MSHTML,
ActiveX, ShlObj, IeConst;
function TForm1.EmbeddedWB1ShowContextMenu(
const dwID: Cardinal;
const ppt: PPoint;
const pcmdtReserved: IInterface;
const pdispReserved: IDispatch): HRESULT;
const
CContextMenuID = 24641;
CGetMimeSubMenuCommandID = 27;
CAddMenuExtensionsCommandID = 53;
var
ShDocLcHandle: THandle;
MustFreeLibrary: Boolean;
OleCommandTarget: IOleCommandTarget;
OleWindow: IOleWindow;
WindowHandle: HWND;
ParentMenu: HMENU;
ChildMenu: HMENU;
EncodingSubMenu: OleVariant;
ChildMenuItemInfo: MENUITEMINFO;
InParam, OutParam: OleVariant;
PopupResult: LongBool;
begin
MustFreeLibrary := False;
ShDocLcHandle := GetModuleHandle('
SHDOCLC.DLL');
if ShDocLcHandle = 0
then
begin
ShDocLcHandle := LoadLibrary('
SHDOCLC.DLL');
MustFreeLibrary := ShDocLcHandle <> 0;
end;
OleCommandTarget := pcmdtReserved
as IOleCommandTarget;
OleWindow := pcmdtReserved
as IOleWindow;
WindowHandle := 0;
if SUCCEEDED(OleWindow.GetWindow(WindowHandle))
then
begin
ParentMenu := LoadMenu(ShDocLcHandle, MAKEINTRESOURCE(CContextMenuID));
if ParentMenu <> 0
then
begin
ChildMenu := GetSubMenu(ParentMenu, dwID);
if SUCCEEDED(OleCommandTarget.Exec(@CGID_ShellDocView,
CGetMimeSubMenuCommandID,
OLECMDEXECOPT_DODEFAULT, null, EncodingSubMenu))
then
begin
FillChar(ChildMenuItemInfo, SizeOf(ChildMenuItemInfo), 0);
ChildMenuItemInfo.cbSize := sizeof(MENUITEMINFO);
ChildMenuItemInfo.fMask := MIIM_SUBMENU;
ChildMenuItemInfo.hSubMenu := HMENU(@EncodingSubMenu);
SetMenuItemInfo(ChildMenu, IDM_LANGUAGE, FALSE, ChildMenuItemInfo);
InParam := ChildMenu;
OutParam := dwID;
end;
DeleteMenu(ChildMenu, IDM_VIEWSOURCE, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PROPERTIES, MF_BYCOMMAND);
PopupResult := TrackPopupMenuEx(ChildMenu, TPM_LEFTALIGN
or
TPM_TOPALIGN
or TPM_RETURNCMD
or TPM_RIGHTBUTTON
or
TPM_HORPOSANIMATION
or TPM_VERPOSANIMATION,
ppt^.x, ppt^.y, WindowHandle,
nil);
if PopupResult
then
SendMessage(WindowHandle, WM_COMMAND, MAKEWPARAM(LOWORD(PopupResult), 0), 0);
DestroyMenu(ParentMenu);
end;
end;
OleWindow :=
nil;
OleCommandTarget :=
nil;
if MustFreeLibrary
and (ShDocLcHandle <> 0)
then
FreeLibrary(ShDocLcHandle);
Result := S_OK;
end;