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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
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.
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(va r 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.TranslateAccelerato r(Msg) = S_OK);
end;
if (not Handled) and Assigned(SaveMessageHandle r) then SaveMessageHandler(Msg,Han dled); 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(IO leInPlaceA ctiveObjec t, OIPAO);
end;
if OIPAO <> nil then OIPAO.GetWindow(OIPAO_Wnd) ;
end;
SaveMessagehandler := Application.OnMessage;
Application.OnMessage:=MyM essageHand ler;
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.navi gate(opend ialog1.fil ename);
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;
end.
let me know if anything still doesnt work
Regards Barry
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(va
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.TranslateAccelerato
end;
if (not Handled) and Assigned(SaveMessageHandle
procedure TForm1.FormCreate(Sender: TObject);
var
Dispatch:IDispatch;
begin
if assigned(WebBrowser1) then
begin
Dispatch := WebBrowser1.Application_;
if Dispatch<>nil then
begin
Dispatch.QueryInterface(IO
end;
if OIPAO <> nil then OIPAO.GetWindow(OIPAO_Wnd)
end;
SaveMessagehandler := Application.OnMessage;
Application.OnMessage:=MyM
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
OIPAO := nil;
Application.OnMessage := SaveMessageHandler;
end;
procedure TForm1.Button1Click(Sender
begin
opendialog1.execute;
webbrowser1.OleObject.navi
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;
end.
let me know if anything still doesnt work
Regards Barry
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 ... ;(
It works great!!
Thanks a million!
Greetings from Spain.
Diego Pulido
diegop@pronet-ise.com
PD: Sorry, I don't have more points ... ;(
ASKER
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