|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by feaci in Delphi Programming, Delphi Components
Delphi 6 in Windows Xp.
I have a TWebBrowser control in a form, and I would like to get the keys pressed when the focus in on the TWebBrowser (for example: control keys, or ESC key, or other keys).
I tried to use KeyPreview in association with OnKey*** events, unsuccesfully.
I tried to put an event handler in my form (as I read in many places, for example
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10225776.html), unsuccessfully (see code in code section).
Can you help me, please?
Many thanks in advance.
Federico.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
|
This is the message handler code I added to my form:
Tdlg_DOC_edit = class(TForm)
...
wb: TWebBrowser;
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
SaveMessageHandler: TMessageEvent;
procedure message_handler(var Msg: TMsg; var Handled: Boolean);
end;
procedure Tdlg_DOC_edit.FormCreate(Sender: TObject);
begin
SaveMessagehandler := Application.OnMessage;
Application.OnMessage := message_handler
end;
procedure Tdlg_DOC_edit.message_handler(var Msg : TMsg;var Handled : Boolean);
const STANDARD_KEYS = [VK_BACK, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT];
var
iOIPAO : IOleInPlaceActiveObject;
Dispatch : IDispatch;
begin
// exit if we don't get back a webbrowser object
if (wb = NIL) then begin Handled := False;Exit end;
Handled := IsDialogMessage(wb.Handle, Msg);
if Handled AND NOT wb.Busy then begin
if (FOleInPlaceActiveObject = NIL) then begin
Dispatch := wb.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 STANDARD_KEYS)
then //nothing - do not pass on Backspace, Left or Right arrows
else FOleInPlaceActiveObject.TranslateAccelerator(Msg)
end
end;
initialization
OleInitialize(NIL)
finalization
OleUnInitialize
end.
|
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625