?
Solved

Tab and Delete keys don't work with TWebBrowser

Posted on 2002-04-28
3
Medium Priority
?
187 Views
Last Modified: 2010-04-04
Hi,

I would like to make the Tab and Delete keys work with TWebBrowser.  When these keys are pressed and the TWebBrowser has the focus, nothing happens.  I've read in the newsgroups that this is a problem and they say read the FAQs at http://members.home.net/hfournier/.  Unfortunately, this site doesn't seem to be working, so I'm stuck.

Would anyone be able to post any Delphi source code to make these keys work correctly within TWebBrowser?  Also, do you know if any other keys don't work correctly with TWebBrowser, and if so which?

Thanks in Advance,

Richard
0
Comment
Question by:Richard2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6975426
hi,
yes it is a problem ,there are many oher probs with TWebbrowser and it is really better to use the TEmBeddedWb from :
http://www.euromind.com/iedelphi/
it has way better event handling capabilities ..
even cut'n'pate play up with twebbrowser

as for the twebbrowser you can still use t if you wish but it will need an event handler similar to below:
(also similar to what you would find at henry fourniers site).

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.
0
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 6975434
ops,
i just got this form my paq:
i think it is the actual one from henrys site but i notice its missing the tab so it needs to be added as i did above.


  procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);

    { Public declarations }
  end;

var
  Form1: TForm1;
  FOleInPlaceActiveObject: IOleInPlaceActiveObject;
  SaveMessageHandler: TMessageEvent;


implementation

{$R *.DFM}

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
var
  iOIPAO: IOleInPlaceActiveObject;
  Dispatch: IDispatch;
begin
  { exit if we don't get back a webbrowser object }
  if WebBrowser1 = nil then
  begin
    Handled := False;
    Exit;
  end;

  Handled:=(IsDialogMessage(WebBrowser1.Handle, Msg) = True);

  if (Handled) and (not WebBrowser1.Busy) then
  begin
    if FOleInPlaceActiveObject = nil then
    begin
      Dispatch := WebBrowser1.Application_;
      if Dispatch <> nil then
      begin
        Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
        if iOIPAO <> nil then
          FOleInPlaceActiveObject := iOIPAO;
      end;
    end;

    if FOleInPlaceActiveObject <> nil then
      if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and
         ((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam = VK_RIGHT)) then
        //nothing - do not pass on Backspace, Left or Right arrows
      else
        FOleInPlaceActiveObject.TranslateAccelerator(Msg);
  end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  SaveMessageHandler := Application.OnMessage;
  Application.OnMessage := MyMessageHandler;

end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
Application.OnMessage := SaveMessageHandler;
end;

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

procedure TForm1.Button1Click(Sender: TObject);
var a,b,c,d:OleVariant;
begin
     WebBrowser1.Navigate(Edit1.Text,a,b,c,d);
end;

initialization
  OleInitialize(nil);

finalization
  OleUninitialize;
0
 

Author Comment

by:Richard2000
ID: 6982919
Hi,

Many thanks for the code.  I'll take a look at EmbeddedWB too.

Richard
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question