How to make bitmap object to behave like button - page 2

 

Simply swap the images it will need a bit more coding in that case.</i></pre>

Could you please tell more details ablout this.


Regarding the button, now it works when I release the mouse button, i.e. click mouse nothing happen, release mouse then the button pressed, execute the code and release button. Is there any way to make like this: click mouse- button press, release mouse - execute the code and release the button. 

I guess it should be done by CHARTEVENT_MOUSE_MOVE event. 


 

Yes only if you use two images one for on state and one for off state.

Otherwise you can just use one image for both states then it won't really matter.

You can also just use a OBJ_BUTTON directly.

Or if you want to go with the CHARTEVENT_MOUSE_MOVE then take that route.

There are many way's.

 
Marco vd Heijden:

Yes only if you use two images one for on state and one for off state.

Otherwise you can just use one image for both states then it won't really matter.

You can also just use a OBJ_BUTTON directly.

Or if you want to go with the CHARTEVENT_MOUSE_MOVE then take that route.

There are many way's.

Yes I am using button with two bitmap images for on and off states. 

How I can use CHARTEVENT_MOUSE_MOVE to realize this. 

There is no much informaiton about this. 

 
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 in the range of CHARTEVENT_CUSTOM to CHARTEVENT_CUSTOM_LAST inclusive. To generate a custom event, the EventChartCustom() function should be used. For each type of event, the input parameters of the...
 

I have seen this article but it doesn't explain properly how is it possible to capture left mouse down and change the state of the button. 

I need code sample to understand this. 

 

Have you tried to run this code:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- enable CHART_EVENT_MOUSE_MOVE messages
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1);
//--- forced updating of chart properties ensures readiness for event processing
   ChartRedraw();
  }
//+------------------------------------------------------------------+
//| MouseState                                                       |
//+------------------------------------------------------------------+
string MouseState(uint state)
  {
   string res;
   res+="\nML: "   +(((state& 1)== 1)?"DN":"UP");   // mouse left
   res+="\nMR: "   +(((state& 2)== 2)?"DN":"UP");   // mouse right 
   res+="\nMM: "   +(((state&16)==16)?"DN":"UP");   // mouse middle
   res+="\nMX: "   +(((state&32)==32)?"DN":"UP");   // mouse first X key
   res+="\nMY: "   +(((state&64)==64)?"DN":"UP");   // mouse second X key
   res+="\nSHIFT: "+(((state& 4)== 4)?"DN":"UP");   // shift key
   res+="\nCTRL: " +(((state& 8)== 8)?"DN":"UP");   // control key
   return(res);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(id==CHARTEVENT_MOUSE_MOVE)
      Comment("POINT: ",(int)lparam,",",(int)dparam,"\n",MouseState((uint)sparam));
  }
You can also talk to someone at Freelance.
Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • www.mql5.com
Making sure the 7 codes are working in EA supplied in a simplistic form in both buy and sell. (Noting at the moment on quick test 6 seem to be working possibly buySLC,sellSLC is not) Over the next 2 weeks more testing to be done so we can fine...
 

This code is using Ternary Operators. 

How I can integrate it to the code which @Marco vd Heijden posted before, i.e. to use the left mouse down (expression "DN" ) to change the button state to "pressed", then reset the button state to "released" when the left mouse button up (expression "UP" ) . 

Any idea?
Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
  • docs.mql4.com
, the third operand - "expression3" is performed. The second and third operands, i.e. "expression2" and "expression3" should return values of one type and should not be of void type. The result of the conditional operator execution is the result of expression2 or result of the expression3, depending on the result of expression1. Operator Use...
 

I do not know what you are trying to do but I never use it that way.

The OnChartEvent() and OBJ_BUTTON should suffice. 

If you want to use the MOUSE_MOVE then you also have to implement a means to id the object.

That is what the OBJECT_CLICK is for so why not use that ? 

 
Marco vd Heijden:

I do not know what you are trying to do but I never use it that way.

The OnChartEvent() and OBJ_BUTTON should suffice. 

If you want to use the MOUSE_MOVE then you also have to implement a means to id the object.

That is what the OBJECT_CLICK is for so why not use that ? 

I am trying to have button press experience like in any normal windows application, when “left mouse down“ changes the button appearance but don’t execute actions unless you “left Mouse up” on the button, if you make “left mouse down” on the button but “left mouse up” somewhere else it will not press the button. 

When I use OnChartEvent OBJECT CLICK, it is changing the button appearance to press and release and execute the action all after “left mouse up”, nothing happens on “left mouse down”. 

The code which you sent seems to be the one I am looking for, but I don’t know how to make OnChartEvent based on it. 

In other word, instead of EVENT OBJECT CLICK need to use EVENT MOUSE MOVE and take actions depending on mouse UP or Down. This is how I understand. 

 

Ok so it appears you want to make your own 

CHARTEVENT_CUSTOM 

Please see: https://www.mql5.com/en/code/19703

EasyAndFastGUI library for creating graphical interfaces
EasyAndFastGUI library for creating graphical interfaces
  • www.mql5.com
The EasyAndFastGUI library allows creating graphical interfaces for custom MQL programs.