告诉你了在控件里接管窗口进程,类似如下:
constructor TXXXXComponent.Create(AOwner: TComponent);
var
ptr: Pointer;
begin
inherited;
FForm := TForm(GetParentForm(TControl(AOwner)));
if not (csDesigning in ComponentState) then
begin
FOldWndProc := Pointer(GetWindowLong(FForm.Handle, GWL_WNDPROC));
ptr := MakeObjectInstance(NewWndProc);
SetWindowLong(FForm.Handle, GWL_WNDPROC, Longint(ptr));
end;
end;
接下来设计你的新窗口进程 NewWndProc ,就可以了。
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FMHook: HHOOK;
function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
implementation
{$R *.DFM}
function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
begin
if Msg.Message = WM_MOUSEMOVE then
with form1 do
begin
//可以先判断一下位置
//Edit1.text := inttostr(msg.wParam);//做你要做的事
caption := format('Mouse Pos in the form:%d,%d',[msg.pt.x,msg.pt.y]);
end
else
if (Msg.Message = WM_lBUTTONDOWN)or(Msg.Message = WM_RBUTTONDOWN) then
begin
//如果位置不在Panel范围内,隐藏它。
end;
Result := CallNextHookEx(FMHook, Code, WParam, Longint(@Msg)); //放出消息给下一个.
end;