5,927
社区成员




if TImageButton(Sender).Tag = 0 then
begin
TImageButton(Sender).Tag := 1;
TImageButton(Sender).PicNormal.Bitmap.Assign(TImageButton(Sender).PicMouseOn.Bitmap);
TImageButton(Sender).Invalidate;
end;
2. 用timer定时器实时监视鼠标和控件的位置判断.
procedure TActiveMonitorX.tmrBtnTimer(Sender: TObject);
var
i: Integer;
ptScreen, pt: TPoint;
Rc: TRect;
begin
GetCursorPos(pt);
// WriteTxLog('%d, %d', [pt.X, pt.Y]);
for i := 0 to Length(FBtnHandle)-1 do
begin
if FBtnHandle[i].Tag = 0 then Continue;
ptScreen.X := 0;
ptScreen.Y := 0;
Windows.ClientToScreen(FBtnHandle[i].Handle, ptScreen);
Rc := Rect(ptScreen.X, ptScreen.Y, ptScreen.X+ FBtnHandle[i].Width, ptScreen.Y+FBtnHandle[i].Height);
if not PtInRect(Rc, pt) then
begin
FBtnHandle[i].Tag := 0;
FBtnHandle[i].PicNormal.Bitmap.Assign(FBtnHandle[i].PicMouseDown.Bitmap);
FBtnHandle[i].Invalidate;
end;
end;
end;
效果算达到了. 结贴吧.
procedure TWinControl.WndProc(var Message: TMessage);
....
if (FMouseControl <> Target) then
begin
if ((FMouseControl <> nil) and (CaptureControl = nil)) or
((CaptureControl <> nil) and (FMouseControl = CaptureControl)) or
((CaptureControl is TControl) and (CaptureControl.Parent = FMouseControl)) then
FMouseControl.Perform(CM_MOUSELEAVE, 0, 0);
if FMouseControl <> nil then
FMouseControl.RemoveFreeNotification(Self);
FMouseControl := Target;
if FMouseControl <> nil then
FMouseControl.FreeNotification(Self);
if ((FMouseControl <> nil) and (CaptureControl = nil)) or
((CaptureControl <> nil) and (FMouseControl = CaptureControl)) then
FMouseControl.Perform(CM_MOUSEENTER, 0, 0);
end;
..
[/quote]
请问这个要如何使用
procedure TWinControl.WndProc(var Message: TMessage);
....
if (FMouseControl <> Target) then
begin
if ((FMouseControl <> nil) and (CaptureControl = nil)) or
((CaptureControl <> nil) and (FMouseControl = CaptureControl)) or
((CaptureControl is TControl) and (CaptureControl.Parent = FMouseControl)) then
FMouseControl.Perform(CM_MOUSELEAVE, 0, 0);
if FMouseControl <> nil then
FMouseControl.RemoveFreeNotification(Self);
FMouseControl := Target;
if FMouseControl <> nil then
FMouseControl.FreeNotification(Self);
if ((FMouseControl <> nil) and (CaptureControl = nil)) or
((CaptureControl <> nil) and (FMouseControl = CaptureControl)) then
FMouseControl.Perform(CM_MOUSEENTER, 0, 0);
end;
..
procedure THDTYPublicActiveX.Initialize;
begin
inherited Initialize;
OnActivate := ActivateEvent;
OnClick := ClickEvent;
OnCreate := CreateEvent;
OnDblClick := DblClickEvent;
OnDeactivate := DeactivateEvent;
OnDestroy := DestroyEvent;
OnKeyPress := KeyPressEvent;
OnMouseEnter := MouseEnterEvent;
OnMouseLeave := MouseLeaveEvent;
OnPaint := PaintEvent;
end;