发信人: finlove (荒野之狼), 信区: BorlandDev
标  题: 使非TWinControl的子类可以响应消息 
发信站: 哈工大紫丁香 (Tue Jan 22 12:24:06 2002) , 转信

宋体 使非TWinControl的子类可以响应消息 
 

宋体 interface 

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

type 
TMyControl = class(TControl) 
private 
{ Private declarations } 
FHandle:THandle; 
protected 
{ Protected declarations } 
procedure WndProc(var Msg:TMessage); 
public 
{ Public declarations } 
Constructor Create(Aowner:TComponent);override; 
Destructor Destroy;override; 
property Handle:THandle read FHandle; 
published 
{ Published declarations } 
end; 

procedure Register; 

implementation 

procedure Register; 
begin 
RegisterComponents('Samples', [TMyControl]); 
end; 

{ TMyControl } 

constructor TMyControl.Create(Aowner: TComponent); 
begin 
inherited; 
FHandle:=AllocateHwnd(WndProc); 
end; 

destructor TMyControl.Destroy; 
begin 
DeallocateHWnd(FHandle); 
inherited; 
end; 

procedure TMyControl.WndProc(var Msg: TMessage); 
begin 
try 
if Msg.Msg=wm_user+1 then 
showmessage('ok') 
else msg.Result:= DefWindowProc(FHandle, Msg.msg, msg.wParam, msg.lParam); 
except 
Application.HandleException(Self); 
end; 
end; 

end. 

可以用postmessage(hwnd_broadcast,wm_user+1,0,0)发消息 




--

※ 来源:.哈工大紫丁香 http://bbs.hit.edu.cn [FROM: 211.97.214.52]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.873毫秒