gpt4 book ai didi

delphi - 如何检测 TControl 的右拖动结束?

转载 作者:行者123 更新时间:2023-12-03 18:43:58 24 4
gpt4 key购买 nike

编辑:VCL 在右拖动方面没有问题,下面的示例程序完美运行。鼠标手势实用程序会导致问题。 (也许它会钩住并拦截 WM_RBUTTONUP 事件...)

我想检测控件右拖动的结束。

对于左拖动,我可以使用 MouseUp 事件,但右拖动后不会发生。

在下面的测试程序中(在表格右侧放一个备忘录并拖动表格),
我想在右拖动后重置鼠标光标。

我怎样才能做到这一点? (WM_RBUTTONUP 没有出现。)

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function ShiftStateToStr(Shift: TShiftState): string;
begin
if ssShift in Shift then
Result := Result + 'S-';
if ssCtrl in Shift then
Result := Result + 'C-';
if ssAlt in Shift then
Result := Result + 'A-';
if ssDouble in Shift then
Result := Result + 'D-';
if ssLeft in Shift then
Result := Result + 'L';
if ssRight in Shift then
Result := Result + 'R';
if ssMiddle in Shift then
Result := Result + 'M';
end;

function MouseButtonToStr(Btn: TMouseButton): string;
begin
if Btn = mbLeft then
Result := 'Left'
else if Btn = mbRight then
Result := 'Right'
else if Btn = mbMiddle then
Result := 'Middle';
end;


procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
SetCapture(Handle);
Memo1.Lines.Add(Format('Down(Btn=%s, Shift=[%s])', [MouseButtonToStr(Button), ShiftStateToStr(Shift)]));

if Button = mbLeft then
Screen.Cursor := crDrag
else if Button = mbRight then
Screen.Cursor := crSize;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y:
Integer);
begin
Memo1.Lines.Add(Format('Move(Shift=[%s])', [ShiftStateToStr(Shift)]));
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Memo1.Lines.Add(Format('Up(Btn=%s, Shift=[%s])', [MouseButtonToStr(Button), ShiftStateToStr(Shift)]));

Screen.Cursor := crDefault;
end;

procedure TForm1.WMRButtonUp(var Message: TWMRButtonUp);
begin
Memo1.Lines.Add('WMRbuttonUp');
inherited;
end;

end.

最佳答案

我用 D2007 试过你的测试程序。一切都按预期工作。 FormMouseUpWMRButtonUp当我释放鼠标右键时触发。

你能在另一台机器上测试它吗?我猜你在 Delphi 中安装了一些“坏”的东西,或者你的系统上有某种钩子(Hook)。但是您的来源是正确的,应该可以工作。

关于delphi - 如何检测 TControl 的右拖动结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3107783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com