unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, [red]ActiveX[/red], DHTMLEDLib_TLB;
type
TForm1 = class(TForm)
DHTMLEdit1: TDHTMLEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
aEditWndProc: TWndMethod;
procedure HtmleditWndProc(var Message: TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.HtmleditWndProc(var Message: TMessage);
var
WinMsg: TMsg;
iOIPAO: IOleInPlaceActiveObject;
aDispatch: IDispatch;
begin
with DHTMLEdit1 do //
if (Message.Msg >= CN_BASE + WM_KEYFIRST) and (Message.Msg <= CN_BASE + WM_KEYLAST) then begin
WinMsg.HWnd := Handle;
WinMsg.Message := Message.Msg - CN_BASE;
WinMsg.WParam := Message.WParam;
WinMsg.LParam := Message.LParam;
WinMsg.Time := GetMessageTime;
WinMsg.Pt.X := $115DE1F1;
WinMsg.Pt.Y := $115DE1F1;
if not VarIsEmpty(OleObject) then begin
if (WinMsg.message = wm_keydown) and (WinMsg.wParam = vk_tab) then begin
///deal with tab;
end else begin //解决快捷键冲突问题
aDispatch := OleObject;
aDispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
if iOIPAO.TranslateAccelerator(WinMsg) = s_ok then begin
Message.Result := 1;
Exit;
end else if ((WinMsg.message = wm_keydown) or (WinMsg.message = wm_keyup))
and ((WinMsg.wParam = vk_back) or
(WinMsg.wParam = vk_left) or (WinMsg.wParam = vk_Right) or
(WinMsg.wParam = vk_up) or (WinMsg.wParam = vk_down)) then begin
// nothing
Message.Result := 1;
Exit;
//***************如果输入字符或回车则不作处理
end else if (WinMsg.message = WM_CHAR) or
(((WinMsg.message = wm_keydown) or (WinMsg.message = wm_keyup)) and
(WinMsg.wParam = VK_RETURN)) then
Exit;
//***************
end;
end;
end;
if Assigned(aEditWndProc) then
aEditWndProc(Message);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with DHTMLEdit1 do begin
aEditWndProc := WindowProc;
WindowProc := HtmleditWndProc;
end;
end;
initialization
OleInitialize(nil)
//解决 Ctrl+c、Ctrl+x和拖放 的问题
finalization
try
OleUnInitialize;
except
end;
end.
===============
代码主要来自我的同事sweetgun
htmledit 还是挺烦的,时常会出一些奇怪的问题,呵呵