重载wndproc消息函数,屏蔽掉你不要的鼠标消息,比如edit的下边的代码:procedure tmyedit.wndproc(var message:tmessage); begin if message.msg=wm_mousemove then begin cursor:=crarrow; exit; end; if message.msg=wm_setfocus then exit; if message.Msg=wm_lbuttondown then showmessage('不能输入文字的了'); inherited wndproc(message); end;
// Import BlockInput function form user32.dll: // BlockInput Funktion von user32.dll importieren: function BlockInput (fBlockInput : boolean) : DWord; stdcall; external 'user32.DLL'; {block input/ blockieren} procedure TForm1.Button1Click(Sender: TObject);
begin
BlockInput(true);
end; {unblock input / Blockierung aufheben} procedure TForm1.Button2Click(Sender: TObject);
begin
BlockInput(false);
end; Note: Requires Windows 98/2000 or later. You can unblock input by pressing CTRL+ALT+DEL
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button2: TButton;
Button1: TButton;
Edit1: TEdit;
procedure Memo1Enter(Sender: TObject);
procedure Memo1Exit(Sender: TObject); private
{ Private declarations }
public
{ Public declarations } end;var
Form1: TForm1;
function BlockInput (fBlockInput : boolean) : DWord; stdcall; external 'user32.DLL';
implementation{$R *.DFM}procedure TForm1.Memo1Enter(Sender: TObject);
begin
BlockInput(true)
end;procedure TForm1.Memo1Exit(Sender: TObject);
begin
BlockInput(false)
end;end.
begin
if message.msg=wm_mousemove then
begin
cursor:=crarrow;
exit;
end;
if message.msg=wm_setfocus then
exit;
if message.Msg=wm_lbuttondown then
showmessage('不能输入文字的了');
inherited wndproc(message);
end;
我是初学者,谢谢!我想把memo控件的所有鼠标事件屏蔽掉,但在其中还是可以输入文字的.
我不知道怎么样才能在Delphi中重载你说的这个函数.
(我的窗体命名为form1,所以我把上面的程序中的tmyedit改为Tform1了)。
后来我把tmyedit改为Tmemo或Tmemo1调试时就出错,可以和我说说怎么样才能捕获有关memo控件的
鼠标消息吗?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TMemo = class(StdCtrls.TMemo)
protected
procedure WndProc(var Message: TMessage); override;
end;type
TForm1 = class(TForm)
Memo1: TMemo;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TMemo.WndProc(var Message: TMessage);
begin
if (Message.Msg >= WM_MOUSEFIRST) and (Message.Msg <= WM_MOUSELAST) then Exit;
inherited WndProc(Message);
end;end.