Invoking Webbrowser ContextMenu

前端 未结 1 1325
再見小時候
再見小時候 2021-01-15 23:09

I\'m working on a project, a Web Bot, that makes use of a WebBrowser control.

My aim is to programmably open the webBrowsers ContextMenu on a desired element in the

相关标签:
1条回答
  • 2021-01-15 23:27

    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.

    0 讨论(0)
提交回复
热议问题