2010-06-24 3 views
2

편집 : VCL은 오른쪽 드래그를해도 문제가 없으며 아래의 샘플 프로그램은 완벽하게 작동합니다. 마우스 제스처 유틸리티로 문제가 발생합니다. 내가 끝 컨트롤을 마우스 오른쪽 버튼으로 드래그의을 감지 할TControl의 오른쪽 드래그 끝을 감지하는 방법은 무엇입니까?

(아마도 그것은 & 요격 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. 
+1

왜 컨트롤/양식의 OnDrag ... 이벤트를 사용하지 않습니까? –

+0

실제 상황에서 3D 공간의 시점을 회전 및 변환하고 싶습니다. 단순한 샘플 일뿐입니다. – benok

답변

1

D2007을 사용하여 테스트 프로그램을 시험해 보았습니다. 모든 것은 예상대로 작동합니다. 마우스 오른쪽 버튼을 놓을 때 FormMouseUpWMRButtonUp이 트리거됩니다.

다른 컴퓨터에서 테스트 할 수 있습니까? 나는 당신이 델파이에 "나쁜"것을 설치했거나 시스템에 어떤 종류의 고리가 있다고 생각합니다. 그러나 당신의 근원은 정확하고 효과가 있어야합니다.

+0

답장을 보내 주셔서 감사합니다. 다른 환경을 확인하겠습니다. – benok

+0

다른 환경에서는 모든 것이 완벽하게 작동합니다. 귀찮은 컴퓨터를 조사한 결과 설치 한 것을 잊어 버린 마우스 제스처 유틸리티를 발견했습니다. 어쨌든, 고마워요! – benok

0

문제는 Delphi의 해석을 사용하지 않고 마우스 이벤트를 직접 감지해야한다는 것입니다.

관련 문제