Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#1

EmbeddedWB & ShowContextMenu -> EVariantInvalidOpErro

  Alt 28. Mai 2006, 19:05
Hallo

Moechte das Kontektmenu des Webbrowsers (TEmbeddedWB) anpassen.
Funktioniert soweit, nur dass es beim Schliessen eine Fehlermedlung gibt. (D 6.02)

Zitat:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EVariantInvalidOpError with message 'Invalid variant operation'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Wo liegt der Fehler?

Delphi-Quellcode:
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;
Thomas
  Mit Zitat antworten Zitat