Arsip: Mengaktifkan Return key in a TWebbrowser


by delphi in Articles more 20 years ago 2298
FormWeb yang memiliki 'text-boxes' dan/atau tombol 'Submit' tidak merespon tombol enter ketika dimunculkan di dala TwebBrowser.
Demikian juga ketika melakukan browsing ke folder lokal, beberapa tombol keyboard tidak direspon.
berikut sedikit petikan skrip untuk mengantisipasinya:
unit uDelphiID;
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.delphi-id.com');
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize
end.
ref: SwissDelphiCenter

AI Forward

๐Ÿš€ We're thrilled to partner with Alibaba Cloud for "AI Forward - Alibaba Cloud Global Developer Summit 2025" in Jakarta! Join us and explore the future of AI. Register now: https://int.alibabacloud.com/m/1000400772/
#AlibabaCloud #DeveloperSummit #Jakarta #AIFORWARD

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com