Par défaut, la touche « entrée » n'est pas prise en compt dans un TWebBrowser : impossibilité de valider un formulaire sans utiliser la souris, impossibilité de faire des retour à la ligne dans les Textarea... voici la solution ! Bien sûr, commencez par ajouter un composant TWebBrowser à la fiche.
Ajoutez la classe ActiveX
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ActiveX;
Ajoutez FOleInPlaceActiveObject: IOleInPlaceActiveObject; dans la partie « public ».
private { Déclarations privées } public FOleInPlaceActiveObject: IOleInPlaceActiveObject; end;
Ajoutez ensuite un composant TApplicationEvent
sur la Form
puis affectez ce code à sa propriété OnMessage :
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); 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 not (((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 FOleInPlaceActiveObject.TranslateAccelerator (Msg); end; end;
Des questions ? Rejoignez nous sur le forum...
Voici le code complet de la fiche en cas de problème :
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, OleCtrls, SHDocVw, ActiveX, AppEvnts; type TForm1 = class(TForm) WebBrowser1: TWebBrowser; ApplicationEvents1: TApplicationEvents; procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: boolean); private { Déclarations privées } public FOleInPlaceActiveObject: IOleInPlaceActiveObject; end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: boolean); 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 not (((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 FOleInPlaceActiveObject.TranslateAccelerator (Msg); end; end; end.