Disable Mouse Wheel

Is there a way of disabling the usage of the mousewheel throughout my program?
NarusegawaAsked:
Who is Participating?
 
Wim ten BrinkConnect With a Mentor Self-employed developerCommented:
There are many options. For application-wide solutions you could try to use to set an event handler for Application.OnMessage using either TApplicationEvents or by assigning the event in runtime.

The code itself is "Extremely complex"... :-)

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Not needed if you use TApplicationEvents on your form.
  Application.OnMessage := ApplicationEventsMessage;
end;

procedure TForm1.ApplicationEventsMessage( var Msg: tagMSG; var Handled: Boolean );
begin
  if ( Msg.message = WM_MOUSEWHEEL ) then Handled := True;
end;
0
 
Wim ten BrinkSelf-employed developerCommented:
Just capture the mouse-wheel event at application level. It is the WM_MOUSEWHEEL message that you have to ignore...
0
 
NarusegawaAuthor Commented:
Okay. Sounds simple enough. How do I go about capturing it? If you don't mind.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Ivanov_GCommented:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  private
    procedure OnMouseWheelMsg (var Msg: TWMMouseWheel); message WM_MOUSEWHEEL;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.OnMouseWheelMsg(var Msg: TWMMouseWheel);
begin
  Msg.Result := 0;
  Exit;
end;

end.
0
 
Wim ten BrinkSelf-employed developerCommented:
@Ivanov_G, I've tried something similar like that but it will only stop the form itself from responding to mousehweel messages. However, controls on the form might have their own messagehandlers that will respond to this event, which the form won't capture for them...

And the exit at the end of your function is a bit useless. You're already exiting the function on the next line.
0
 
Ivanov_GCommented:
Workshop_Alex, yep, I agree with you. :))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.