was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1549)

Dateien (138)
Datenbanken (90)
Drucken (35)
Grafik (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (127)
Strings (83)
System (268)
VCL (243)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

51 Visitors Online


 
...die Enter Taste in HTML Forms eines TWebbrowsers aktivieren?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (43):  
     


 Problem:

  Web forms that have multiline text boxes and/or Submit buttons do not
  
respond to the Enter key when displayed on a TWebbrowser.
  Also when browsing local folders, some keys don't respond.

  How to solve it:


unit Unit1;

interface

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

type
  
TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    
{ Private declarations }
    
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
    procedure MsgHandler(var Msg: TMsg; var Handled: Boolean);
  public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormDestroy(Sender: TObject);
begin
  
FOleInPlaceActiveObject := nil;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
Application.OnMessage := MsgHandler;
end;

procedure TForm1.MsgHandler(var Msg: TMsg; var Handled: Boolean);
const
  
StdKeys = [VK_BACK, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT];
var IOIPAO: IOleInPlaceActiveObject;
  Dispatch: IDispatch;
begin
  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 in StdKeys) then
        
//nothing  -  do not pass on Backspace, Left, Right, Up, Down arrows
      
else FOleInPlaceActiveObject.TranslateAccelerator(Msg);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
Webbrowser1.Navigate('www.SwissDelphiCenter.ch');
end;

initialization
  
OleInitialize(nil);

finalization
  
OleUninitialize
end.






 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners