步骤如下
1,在使用TwebBrowser控件的窗体(例如MainForm)中创建一个函数
procedure TfrmMain.MsgHandler(var Msg: TMsg; var Handled: Boolean);
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) = True);
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 = 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;
2,在该窗体的FormCreate事件中,
oldHandler := Application.OnMessage;//oldHandler 全局变量
Application.OnMessage := MsgHandler;
3,在该Form的private中声明
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
OK啦,这是我现有程序中正在使用的,如果有问题再找我.
[8D]