HanDs
管理员

[Delphi文章] delphi控件消息截获处理 





学习中请遵循国家相关法律法规,黑客不作恶。没有网络安全就没有国家安全

本站需要登陆后才能查看

窗体控件:

unit Unit1;
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1
= class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
LowCh: Boolean;
C: Word;
OldWndProc: TWndMethod;
procedure WndProc(var Message: TMessage);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R
*.dfm}

procedure TForm1.WndProc(var Message: TMessage);
var
ch: Word;
begin
if Message.Msg = WM_PASTE then Exit;
if Message.Msg = WM_CHAR then
begin
if Message.LParam = -1 then
Message.LParam :
= 0
else if (Message.WParam and $80) <> 0 then
begin
if not LowCh then
begin
if ((Message.WParam and $7f) xor $20) < $10 then
begin
C :
= Message.WParam;
LowCh :
= True;
Exit;
end;
end
else
begin
LowCh :
= False;
ch :
= (Message.WParam shl 8) or C;
if ((ch and $7f7f) xor $2020) = $0c03 then
PostMessage(Edit1.Handle, WM_CHAR, ch,
-1);
Exit;
end;
end
else if Message.WParam >= 32 then exit;
end;
OldWndProc(Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
OldWndProc :
= Edit1.WindowProc;
Edit1.WindowProc :
=
WndProc;
end;

end.

自定义组件:

unit Unit2;
interface

uses
Windows, Messages, SysUtils, StdCtrls;

type
TEdit
= class(StdCtrls.TEdit)
private
LowCh: Boolean;
C: Word;
procedure WMChar(var Message: TWMChar); message WM_CHAR;
procedure WMPASTE(var Message: TMessage); message WM_PASTE;
end;

implementation

{ TEdit }

procedure TEdit.WMChar(var Message: TWMChar);
var
ch: Word;
begin
if Message.KeyData = -1 then
Message.KeyData :
= 0
else if (Message.CharCode and $80) <> 0 then
begin
if not LowCh then
begin
if ((Message.CharCode and $7f) xor $20) < $10 then
begin
C :
= Message.CharCode;
LowCh :
= True;
Exit;
end;
end
else
begin
LowCh :
= False;
ch :
= (Message.CharCode shl 8) or C;
if ((ch and $7f7f) xor $2020) = $0c03 then
PostMessage(Handle, WM_CHAR, ch,
-1);
Exit;
end;
end
else if Message.CharCode >= 32 then exit;
inherited;
end;

procedure TEdit.WMPASTE(var Message: TMessage);
begin

end;

end.


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
delphi 控件消息截获处理
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复