2

編集: 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.
4

2 に答える 2

1

D2007であなたのテストプログラムを試しました。すべてが期待どおりに機能します。マウスの右ボタンを離すFormMouseUpとトリガーされます。WMRButtonUp

別のマシンでテストできますか?Delphiに「悪い」ものをインストールしたか、システムに何らかのフックがあると思います。しかし、ソースは正しく、機能するはずです。

于 2010-06-24T07:32:42.190 に答える
0

問題は、Delphi の解釈を使用せずに、マウス イベントを直接検出する必要があることです。

于 2010-06-24T07:20:31.807 に答える