你可以看看TEmbeddedWB的源代码,它有两个处理办法
对Delphi5(VER130)使用窗口过程TEmbeddedWB.WBWndProc
对其他版本就拦消息:IEMessageHandler
procedure TEmbeddedWB.WBWndProc(var Message: TMessage);
const
StdKeys = [VK_RETURN, VK_BACK]; { standard keys }
ExtKeys = [VK_LEFT, VK_RIGHT]; { extended keys }
fExtended = $01000000; { extended key flag }
var
bClose: Boolean;
{$IFDEF VER130}
WinMsg: TMsg;
{$ENDIF}
begin
with Message do
begin
{$IFDEF VER130}
if (Msg >= (CN_BASE + WM_KEYFIRST)) and (Msg <= (CN_BASE + WM_DEADCHAR)) then
begin
WinMsg.HWND := Handle;
WinMsg.Message := Msg - CN_BASE;
WinMsg.WPARAM := WPARAM;
WinMsg.LPARAM := LPARAM;
WinMsg.Time := GetMessageTime;
WinMsg.pt.X := $115DE1F1;
WinMsg.pt.Y := $115DE1F1;
if not ((WPARAM in StdKeys) or
(WPARAM in ExtKeys) and ((LPARAM and fExtended) = fExtended)) then
with Application as IOleInPlaceActiveObject do
Result := Integer(TranslateAccelerator(WinMsg) = S_OK);
end
else
{$ENDIF}
case Msg of
WM_CLOSE:
begin
bClose := True;
if Assigned(FOnCloseQuery) then
FOnCloseQuery(Self, bClose);
if bClose then
OldWBWndProc(Message);
end;
WM_DDE_EXECUTE:
try
DDEExecute(WPARAM, LPARAM);
except
//
end;
WM_DDE_TERMINATE:
try
DDETerminate(WPARAM, LPARAM);
except
//
end;
else
OldWBWndProc(Message);
end;
end;
end;
{$IFNDEF VER130}
procedure TEmbeddedWB.IEMessageHandler(var Msg: TMsg; var Handled: Boolean);
{ fixes the malfunction of some keys within webbrowser control }
const
StdKeys = [VK_TAB, VK_RETURN]; { standard keys }
ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { extended keys }
fExtended = $01000000; { extended key flag }
begin
Handled := False;
with Msg do
if ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and
((WPARAM in StdKeys) or {$IFDEF VER120}(GetKeyState(VK_CONTROL) < 0) or {$ENDIF}
(WPARAM in ExtKeys) and ((LPARAM and fExtended) = fExtended)) then
try
if IsChild(Handle, HWND) then
{ handles all browser related messages }
begin
with {$IFDEF VER120}Application_{$ELSE}Application{$ENDIF} as IOleInPlaceActiveObject do
Handled := TranslateAccelerator(Msg) = S_OK;
if not Handled then
begin
Handled := True;
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
except
end;
end; // IEMessageHandler
{$ENDIF}