Link to home
Start Free TrialLog in
Avatar of yonka
yonka

asked on

Lost focus in an ActiveX form

Hi,

I have an Activex form but when I see it with  the TWebBrowser component the ActiveX losses the focus when I press cursor keys or tab key.

How can I hold the focus inside the ActiveX when I press the cursor keys or Tab key?

Note: If I see the ActiveX in IE the form works fine.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yonka
yonka

ASKER

Hi inthe,

thanks, works, ... at last .. ;)

There is only one problem, tab key seems to work but the tab order is incorrect, in one form the tabkey works backwards, in other form jumps to a control in an incorrect order.
The up and down keys only work inside a control like a combo or a grid but not work simulating tab key in controls like TEdit.

thanks a lot
Diego
these problems seem strange ..are they occurring inside the twebbrowser ?
or are these normal forms?
i know there are trooubles with normal forms and the vk_up/vk_down keys but tab should be ok..
is it possible to send me a demo of this problem so i can see?
Avatar of yonka

ASKER

The problems always are in the TWebBrowser.

If you make a ActiveForm from scrach with some TEdit and a TButton  and you try to see it in IE it works fine, but if you try to see it inside TWebBrowser with the message handler then the tab order is random.

I can't send you a demo because you need several MTS objects to run, but if your probe it from scrach (an activeform with 3 edit controls and a client with with your source code) you will see the tab key is mad.

I have Win NT 4.0 sp 5, Delphi 5, IE5.00.2314.5003.
ok i shall make a demo later today and see if i can find the problem ;-)
hi
please try this ,i think its what we after :


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleCtrls, SHDocVw_TLB,ActiveX;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
   OIPAO  : IOleInPlaceActiveObject;
   OIPAO_Wnd:HWND;

  public
    { Public declarations }
    procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
  end;

var
  Form1: TForm1;
  SaveMessageHandler: TMessageEvent;
implementation

{$R *.DFM}

procedure Tform1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
const
  DuplicatedKeys: set of Byte = [VK_TAB, VK_BACK, VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT];
var
   w:HWND;
begin
     Handled:=False;
     if Msg.message = WM_KEYDOWN then
     begin
          if Msg.wParam in DuplicatedKeys then
         //do nothing let ie take care of it
           end;
     w:=GetFocus;
     if (w=0) {or (w=[].Handle)} then Exit;
     if OIPAO<>nil then
     begin
          if w = OIPAO_Wnd then Handled := IsDialogMessage(w,Msg);
          if not Handled then Handled := (OIPAO.TranslateAccelerator(Msg) = S_OK);
     end;
     if (not Handled) and Assigned(SaveMessageHandler) then SaveMessageHandler(Msg,Handled); end;

procedure TForm1.FormCreate(Sender: TObject);
var
   Dispatch:IDispatch;
begin
    if assigned(WebBrowser1) then
     begin
          Dispatch := WebBrowser1.Application_;
          if Dispatch<>nil then
          begin
               Dispatch.QueryInterface(IOleInPlaceActiveObject, OIPAO);
          end;
          if OIPAO <> nil then OIPAO.GetWindow(OIPAO_Wnd);
     end;
     SaveMessagehandler := Application.OnMessage;
     Application.OnMessage:=MyMessageHandler;
 end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
OIPAO := nil;
Application.OnMessage := SaveMessageHandler;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.execute;
webbrowser1.OleObject.navigate(opendialog1.filename);
end;

initialization
  OleInitialize(nil);

finalization
  OleUninitialize;

end.

let me know if anything still doesnt work
Regards Barry
Avatar of yonka

ASKER

Great!!!
It works great!!

Thanks a million!

Greetings from Spain.
Diego Pulido
diegop@pronet-ise.com



PD: Sorry, I don't have more points ... ;(