본문 바로가기

Delphi

[Delphi] 델파이에서 휠마우스의 휠 사용해서 스크롤 움직이기.

1. ApplicationEvent콤포넌트를 이용해서 사용하기.
Form에 
ApplicationEvent콤포넌트를 올려놓고, 해당 콤포넌트의 OnMessage이벤트에 다음처럼 작성한다.
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
var
  wc: TWinControl;
begin
  if Msg.message = WM_MOUSEWHEEL then
  begin
    wc := FindVCLWindow(Mouse.CursorPos);
    if wc.Handle = 사용할Control.Handle then
      begin
        if Msg.wParam > 0 then
        begin
          ScrollBarCallFlowV.Position := ScrollBarCallFlowV.Position - 20;
        end
        else if Msg.wParam < 0 then
        begin
          ScrollBarCallFlowV.Position := ScrollBarCallFlowV.Position + 20;
        end;
      end
      else
        SendMessage(wc.Handle, WM_MOUSEWHEEL, Msg.wParam, Msg.lParam);
        Handled := True;
      end;
   end;
end;



2. dbGrid 에서 마우스 휠 버튼 사용하기.

procedure MouseWheelHandler(var Message: TMessage); override;
//맨 위에 프로시저 선언을 한후.


procedure TForm1.MouseWheelHandler(var Message: TMessage);
begin
  if Message.msg = WM_MOUSEWHEEL then
  begin
    if ((ActiveControl is TDBgrid) or
      (ActiveControl is TwDataCombo)) then
    begin
      if Message.wParam > 0 then
      begin
        keybd_event(VK_UP, VK_UP, 0, 0);
      end
      else if Message.wParam < 0 then
      begin
        keybd_event(VK_DOWN, VK_DOWN, 0, 0);
      end;
    end;
  end;
end;