Problems with Delphi - TWebBrowser

Two quick questions

  • How to set focus on TWebBrowser? This means that the mouse wheel scrolls the display without first clicking in the TWebBrwoser display area. It has a setfocus method that does nothing (or seems to do nothing).

  • Inside TWebBrowser, right-click the displayed link and select properties. The OK and Cancel buttons are disabled, and you cannot close the dialog box. You need to complete the task of your application in order to kill it.

Any ideas?

Thanks, Jason.

+3
source share
2 answers

Answer question 1 after much searching on the Internet ....

 with WebBrowser1 do
 if Document <> nil then
 with Application as IOleobject do
 DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle, GetClientRect);
+6
source

, TWebBrowser .

, OnCommandStateChange:

procedure TWebBrowserFrame.CommandStateChange(Sender: TObject;
  Command: Integer; Enable: WordBool);
var
  Doc: IHTMLDocument2;        // document object
  Sel: IHTMLSelectionObject;  // current selection
begin
  // Check we have a valid web browser triggering this event
  if not Assigned(Sender) or not (Sender is TWebBrowser) then
    Exit;
  // Check we have required command
  if TOleEnum(Command) <> CSC_UPDATECOMMANDS then
    Exit;
  // Get ref to document object and check not nil
  Doc := Browser.Document as IHTMLDocument2;
  if not Assigned(Doc) then
    Exit;
  // Get ref to current selection
  Sel := Doc.selection as IHTMLSelectionObject;
  // If selection is of correct type then we have a mouse click
  if Assigned(Sel) and (Sel.type_ = 'Text') then
  begin
    // Make the web browser the form active control
    (Sender as TWebBrowser).SetFocus;
    Doc.parentWindow.focus;
  end;
end;

, , .

0

Source: https://habr.com/ru/post/1709257/


All Articles