Invoking Webbrowser ContextMenu

只愿长相守 提交于 2019-12-01 11:44:47

It depends on your concrete requirement. If you want to operate particular HTML element, you can access it via DOM. IMO, you can do everything that WebBrowser can do.

If you want to use the context menu (to avoid writing extra code or to pretend an user operation), you can send a mouse click at desired position and then block context menu popup temporary. Here is my sample code in Delphi for your reference.

function TTrident.ShowContextMenu(const dwID: DWORD; const ppt: PPOINT; const pcmdtReserved: IUnknown;
  const pdispReserved: IDispatch): HRESULT;
begin
  if FDontShowContextMenuThisTime then
  begin
    FDontShowContextMenuThisTime := False;
    Exit(S_OK);
  end
  else
    Exit(S_FALSE);
end;

ShowContextMenu is one method of the interface IDocHostUIHandler. In other words, you have to extend the WebBrowser control by implementing at least IDocHostUIHandler. See also MSDN.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!