Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi EmbeddedWB & ShowContextMenu -> EVariantInvalidOpError (https://www.delphipraxis.net/70327-embeddedwb-showcontextmenu-evariantinvalidoperror.html)

toms 28. Mai 2006 19:05


EmbeddedWB & ShowContextMenu -> EVariantInvalidOpErro
 
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;

toms 28. Mai 2006 19:31

Re: EmbeddedWB & ShowContextMenu -> EVariantInvalidOp
 
Habe underdessen herausgefunden, wo der Fehler entsteht. Und zwar bei OleCommandTarget.Exec(...)

Wenn ich den EncodingSubMenu durch POleVariant(nil)^) ersetze, kommt der Fehler nicht mehr.
Wie kann ich aber EncodingSubMenu richtig als Parameter einsetzen?

Delphi-Quellcode:
      if SUCCEEDED(OleCommandTarget.Exec(@CGID_ShellDocView,
        CGetMimeSubMenuCommandID,
        OLECMDEXECOPT_DODEFAULT, null, POleVariant(nil)^)) then

toms 28. Mai 2006 20:07

Re: EmbeddedWB & ShowContextMenu -> EVariantInvalidOp
 
So scheint's nun zu funktionieren:
Delphi-Quellcode:
EmbeddedWB1.ExecWB(CGetMimeSubMenuCommandID, null, EncodingSubMenu);


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:56 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz