1

In DCEF 1 (Delphi Chromium Embedded 1), I've used TChromium.Browser.SetFocus(True); to set focus of a browser window, but in DCEF 3 I can't find a way to set focus of this window.

Does anyone know how to set focus of a TChromium browser window in DCEF 3 ?

Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • Simply call [`SetFocus`](http://docwiki.embarcadero.com/Libraries/XE4/en/Vcl.Controls.TWinControl.SetFocus) method of your `TChromium` object instance. The `TChromium` in [`DCEF 3 listens`](https://code.google.com/p/dcef3/source/browse/src/cefvcl.pas#866) for the `WM_SETFOCUS` which is sent as a consequence of a `SetFocus` method call and in this message handler then partially dispatches the `WM_SETFOCUS` message to the `ICefBrowserHost` window, which finally sets the focus to the browser window. – TLama Sep 23 '13 at 21:30

2 Answers2

2

Thanks for TLama

function CefWndProc(Wnd: HWND; message: UINT; wParam: Integer; lParam: Integer):  Integer; stdcall;
begin
  case message of
    WM_SETFOCUS:
      begin
        if brows <> nil then
          PostMessage(brows.Host.WindowHandle, WM_SETFOCUS, wParam, 0);
        Result := 0;
      end;
    //...
    else
      result := DefWindowProc(Wnd, message, wParam, lParam);
 end;
end;    

//MyChromium.Browser.Host.SetFocus(true);
0
procedure TWinControl.SetFocus;

TCustomChromium = class(TWinControl, IChromiumEvents)

TChromium is a TWinControl.

RAS
  • 8,100
  • 16
  • 64
  • 86
Delhpi
  • 71
  • 1
  • 2