小
小妖刀
Unregistered / Unconfirmed
GUEST, unregistred user!
我要做一个控件,放到Form上以后就可以拦截到Form上发生的输入焦点改变的事件.
我用替换窗口过程,和Application.OnMessage事件的方法,都拦截不到上述的两个
消息,请问各位大大,我的程序有什么问题,谁能给个示范程序.
我的程序如下:
unit test;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
ListBox1: TListBox;
ComboBox1: TComboBox;
Memo1: TMemo;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ListBox2: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
OldWndProc,WndProcPtr: Pointer;
procedure WndMethod(var Msg: TMessage);
Procedure HandleAppMessage(var Msg: TMsg;var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ColorFoucs;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
fff: TFoucsColor;
begin
fff:=TFoucsColor.Create(self);
fff.Parent:=Form1;
end;
procedure TForm1.HandleAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if ListBox1.Items.Count > 20 then ListBox1.Items.Clear;
if (Msg.message <> 512) and (Msg.message <> 15) and (Msg.message <> 208)
and (Msg.message <> 280)and (Msg.message <> 160) then
ListBox1.Items.Add(IntToStr(Msg.message));
if Msg.message = WM_SETFOCUS then showmessage('true');
end;
procedure TForm1.WndMethod(var Msg: TMessage);
begin
ListBox2.Items.Add(IntToStr(Msg.Msg));
if Msg.Msg = WM_SETFOCUSthen showmessage('true too');
With Msg do
Result:=CallWindowProc(OldWndProc,Application.Handle,Msg,wParam,lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=HandleAppMessage;
WndProcptr:=MakeObjectInstance(WndMethod);
OldWndProc:=Pointer(SetWindowLong(Application.Handle,GWL_WNDPROC,integer(WndProcPtr)));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetWindowLong(Application.Handle,GWL_WNDPROC,Longint(OldWndProc));
FreeObjectInstance(WndProcPtr);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendMessage(Application.Handle,WM_SETFOCUS,0,0);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
PostMessage(Application.Handle,WM_SETFOCUS,0,0);
end;
end.
//程序中用SendMessage和postMessage发送的WM_SETFOCUS消息可以拦截到,但是在form上
//随意点击EDIT,LISTBOX等都监测不到,难道输入焦点改变的时候,没有WM_SETFOCUS消息
//发出???
//
我用替换窗口过程,和Application.OnMessage事件的方法,都拦截不到上述的两个
消息,请问各位大大,我的程序有什么问题,谁能给个示范程序.
我的程序如下:
unit test;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
ListBox1: TListBox;
ComboBox1: TComboBox;
Memo1: TMemo;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ListBox2: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
OldWndProc,WndProcPtr: Pointer;
procedure WndMethod(var Msg: TMessage);
Procedure HandleAppMessage(var Msg: TMsg;var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ColorFoucs;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
fff: TFoucsColor;
begin
fff:=TFoucsColor.Create(self);
fff.Parent:=Form1;
end;
procedure TForm1.HandleAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if ListBox1.Items.Count > 20 then ListBox1.Items.Clear;
if (Msg.message <> 512) and (Msg.message <> 15) and (Msg.message <> 208)
and (Msg.message <> 280)and (Msg.message <> 160) then
ListBox1.Items.Add(IntToStr(Msg.message));
if Msg.message = WM_SETFOCUS then showmessage('true');
end;
procedure TForm1.WndMethod(var Msg: TMessage);
begin
ListBox2.Items.Add(IntToStr(Msg.Msg));
if Msg.Msg = WM_SETFOCUSthen showmessage('true too');
With Msg do
Result:=CallWindowProc(OldWndProc,Application.Handle,Msg,wParam,lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=HandleAppMessage;
WndProcptr:=MakeObjectInstance(WndMethod);
OldWndProc:=Pointer(SetWindowLong(Application.Handle,GWL_WNDPROC,integer(WndProcPtr)));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetWindowLong(Application.Handle,GWL_WNDPROC,Longint(OldWndProc));
FreeObjectInstance(WndProcPtr);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendMessage(Application.Handle,WM_SETFOCUS,0,0);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
PostMessage(Application.Handle,WM_SETFOCUS,0,0);
end;
end.
//程序中用SendMessage和postMessage发送的WM_SETFOCUS消息可以拦截到,但是在form上
//随意点击EDIT,LISTBOX等都监测不到,难道输入焦点改变的时候,没有WM_SETFOCUS消息
//发出???
//