2014-09-12 1 views
1

내 응용 프로그램이 마우스에서 주로 실행되기 때문에 내 응용 프로그램에서 마우스 휠 이벤트를 캡처해야합니다. OpenGL보기 컨텍스트의 카메라를 이동하려면 현대적인 UI의 과 비슷합니다.마우스 휠의 수직 및 수평 스크롤 캡쳐

나는 Windows 메시지를 살펴 봤는데 TWinControls에서만 상속받은 TWinControls 및 만이 마우스 휠 메시지를 수신 할 수 있습니다.

또한 TApplicationEvent 구성 요소는 이러한 메타 태그를 캡처 할 수 있으므로 사용하고 있습니다.

나는 WM_MOUSEWHEEL 메시지를 처리하려고 시도했지만 수직 스크롤 만 반환합니다.

내가 WM_HSCROLLWM_HSCROLLCLIPBOARD가하지만이 를 캡처되지 않습니다 메시지를 처리 ​​노력했다.

가로 및 세로 마우스 휠 메시지를 모두 캡처하고 내 소프트웨어에서 어떻게 사용합니까?

Windows 8.1에서 Delphi XE2를 사용하고 있습니다.

+0

[WM_MOUSEHWHEEL 메시지] (http://msdn.microsoft.com/en-us/library/windows/desktop/ms645614(v=vs.85).aspx) 처리 방법은 무엇입니까? –

+0

@LURD 나는 그것을보고있다. 답변을 마무리하는 것. – xaid

답변

4

WM_MOUSEHWHEEL 메시지에 응답하면됩니다.

procedure TMyScrollBox.WndProc(var Message: TMessage); 
begin 
    if Message.Msg=WM_MOUSEHWHEEL then begin 
    (* For some reason using a message handler for WM_MOUSEHWHEEL doesn't work. 
     The messages don't always arrive. It seems to occur when both scroll bars 
     are active. Strangely, if we handle the message here, then the messages 
     all get through. Go figure! *) 
    if TWMMouseWheel(Message).Keys=0 then begin 
     HorzScrollBar.Position := HorzScrollBar.Position 
     + TWMMouseWheel(Message).WheelDelta; 
     Message.Result := 0; 
    end else begin 
     Message.Result := 1; 
    end; 
    end else begin 
    inherited; 
    end; 
end; 
0

먼저 메시지를 WM_MOUSEHWHEEL을 처리 할 필요가 : 예를 들어, 여기에 스크롤 상자에 수평 마우스 휠 스크롤을 추가 내 클래스에서 추출입니다.

문자 "H"가 있음을 알아 두십시오 (WM_MOUSE H WHEEL).

은 내가 TApplicationEvent의 componenet을 추가하고,의 onMessage 이벤트에 다음 코드 추가 :

uses VCL.Controls; 

..... 

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); 
    var ctrl: TWinControl; 
begin 
    ctrl := FindVCLWindow(Mouse.CursorPos); //first I need to find the control under the mouse 

    if ctrl is T3DWorldViewerComponent then //then I need to make sure 
              //that the control under the mouse 
              //is the 3D World Viewer contains my graphics 

    if msg.message = WM_MOUSEHWHEEL then //then I need to make sure that I want to scroll Horizontally 
    begin 
     if msg.wParam=4287102976 then //this indicates that I'm scrolling to the left 
     world.CameraMoveTo(MyCamera.Position.X+0.03, MyCamera.Position.Y, MyCamera.Position.Z) 
     else 
     if msg.wParam=7864320 then //and this indicates that I'm scrolling to the right 
     world.CameraMoveTo(MyCamera.Position.X-0.03, MyCamera.Position.Y, MyCamera.Position.Z); 
    end; 
end; 

가 완료!

+0

이것은 옳지 않습니다. 각각의 모든 입력 이벤트에 대해'Mouse.CursorPos'와'FindVCLWindow'를 호출해서는 안됩니다. 그것은 엄청난 성과입니다. 그리고 비동기 적이기 때문에'Mouse.CursorPos'를 호출하면 안됩니다. 오히려'GetMessagePos'를 사용하여 입력 이벤트가 생성되었을 때 마우스 위치를 얻습니다. 적어도 처음에는'WM_MOUSEHWHEEL'을 테스트해야합니다. WM_MOUSEHWHEEL에 대한 핸들러를 컨트롤에 추가하는 것이 훨씬 쉽습니다. –

+0

괜찮습니다. 나는 그것을 소프트웨어에서 변경해야 할 것이다. 데이비드 정보를 제공해 주셔서 감사합니다. – xaid

+1

그러나이 경우 GetMessagePos를 사용하지 않을 것입니다. lParam 값에는 좌표가 있습니다. 그리고 wParam에 대한 해석 역시 나쁘다. –

관련 문제