How to distinguish between mouse wheel move up/down directions?

 

Hello

I can check if the mouse wheel is moved when the cursor is in my interface area, but I didn't find a way to get the wheel moving direction.

Sorry I'm not sure if what I said was clear in English or not.

I mean I want to know if the user spins the wheel upside or downside.

Both of them gives the id of 9 and it seems there is no lparam, dparam and sparam passed to the OnChartEvent();

Here is the code I've written:

Thanks.

void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
  {
   panel.OnEvent(id,lparam,dparam,sparam);
//---
   static CPoint Mouse_Last;
   if(id == CHARTEVENT_MOUSE_MOVE)
     {
      Mouse_Last.x = (int)lparam; // X-coordinate
      Mouse_Last.y = (int)dparam; // Y-coordinate
     }
   int x1,x2,y1,y2;
   x1 = panel.Left();
   x2 = panel.Right();
   y1 = panel.Top();
   y2 = panel.Bottom();
 //---
   bool MouseIn = (Mouse_Last.x >x1  && Mouse_Last.x<x2  && Mouse_Last.y > y1 && Mouse_Last.y<y2);
   if(MouseIn && id==9)
     {
      ChartSetInteger(ChartID(),CHART_MOUSE_SCROLL,false);
      Comment("Mouse wheel has been used","\nMouse In the Interface area: ",MouseIn,"\nid : ",id,"\nlparam : ",lparam,"\ndparam : ",dparam,"\nsparam : ",sparam);
     }
   else
     {
      Comment("Mouse In : ",MouseIn,"\nlparam : ",lparam,"\ndparam : ",dparam,"\nsparam : ",sparam,"\nid : ",id);
      ChartSetInteger(ChartID(),CHART_MOUSE_SCROLL,true);
     }

  }
 
Reza nasimi:

Hello

I can check if the mouse wheel is moved when the cursor is in my interface area, but I didn't find a way to get the wheel moving direction.

Sorry I'm not sure if what I said was clear in English or not.

I mean I want to know if the user spins the wheel upside or downside.

Both of them gives the id of 9 and it seems there is no lparam, dparam and sparam passed to the OnChartEvent();

Here is the code I've written:

Thanks.

It seems that there is no way to get the direction of the mouse wheel and the value of how much it moved in MQL4.

I hope someone can help me with win32, as I do not know how it works.

I searched a lot, there are information about it, but each of them needs some other knowledge to be understood and I wasn't able understand how to use them yet.

I have found these but don't know how to use them.

int      WindowProc(int hwnd, uint uMsg, int wParam, int lParam);

#define WM_MOUSEWHEEL                   0x020A

GET_WHEEL_DELTA_WPARAM

Any help would be highly appreciated.

 
Reza nasimi:

Hello

I can check if the mouse wheel is moved when the cursor is in my interface area, but I didn't find a way to get the wheel moving direction.

Sorry I'm not sure if what I said was clear in English or not.

I mean I want to know if the user spins the wheel upside or downside.

Both of them gives the id of 9 and it seems there is no lparam, dparam and sparam passed to the OnChartEvent();

Here is the code I've written:

Thanks.

https://www.mql5.com/en/docs/constants/chartconstants/enum_chartevents#chartevent_mouse_wheel

In MT4 You can't use mouse wheel.

This is how you can detect wheel up or down in MT5

void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
{
        bool wheelUp    = dparam==120;
        bool wheelDown  = dparam==-120;
}
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
There are 11 types of events that can be processed using the predefined function OnChartEvent() . For custom events 65535 identifiers are provided...
Reason: