Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MOUSE_WHEEL delta always positive

Tags:

delphi

I am trying to detect the movement of the mouse wheel (while the CTRL key is pressed) using a TApplicationEvents.OnMessage event in Delphi 7. This is the code I am using:

if Msg.message = WM_MOUSEWHEEL then begin
 if Word(Msg.wParam) = MK_CONTROL then begin
  Edit1.Text := IntToStr(HiWord(Msg.wParam));
   if HiWord(Msg.wParam) < 0 then begin
    IncZoom;
   end else begin
    DecZoom;
   end;
 end;
end;

According to the MSDN resource (http://msdn.microsoft.com/en-us/library/windows/desktop/ms645617(v=vs.85).aspx ) a negative value for the HiWord of (Msg.wParam) indicates that the wheel has been moved backward, toward the user.

Problem is, I never receive a negative value when the wheel is moved backward. When I scroll backward, I get a value of 120. When I scroll forward, I get 65416.

What am I doing wrong?

like image 336
user1527613 Avatar asked Sep 15 '13 09:09

user1527613


People also ask

What is wheel delta?

The wheelDelta attribute value is an abstract value which indicates how far the wheel turned.

What is the rolling wheel on the top of the mouse used for?

The scroll wheel that is located in the middle of the mouse is used to scroll up and down on any page without using the vertical scroll bar on the right hand side of a document or webpage.

Which property gets a count of how many notches the mouse wheel has rotated?

Delta Property (System. Windows.

What is mouse wheel event?

The onwheel event occurs when the mouse wheel is rolled up or down over an element. The onwheel event also occurs when the user scrolls or zooms in or out of an element by using a touchpad (like the "mouse" of a laptop).


1 Answers

HiWord returns a Word which is an unsigned 16 bit integer. The documentation you linked states,

Use the following code to get the information in the wParam parameter:

  fwKeys = GET_KEYSTATE_WPARAM(wParam); 
  zDelta = GET_WHEEL_DELTA_WPARAM(wParam);

where GET_WHEEL_DELTA_WPARAM is defined in 'winuser.h' as follows:

#define GET_WHEEL_DELTA_WPARAM(wParam)  ((short)HIWORD(wParam))

As you can see the high-word is type-casted to a short. A SHORT as a windows data type is a 16 bit signed integer which corresponds to a Smallint in Delphi. So you can cast it like so:

if Smallint(HiWord(Msg.wParam)) < 0 then begin
like image 148
Sertac Akyuz Avatar answered Oct 17 '22 07:10

Sertac Akyuz