Use CHARTEVENT_MOUSE_MOVE which gives you the X, Y coordinates and the mouse's buttons state.
I don't see where you are driving at, the CHARTEVENT_MOUSE_MOVE event
will be triggered whether you move on a chart or on the dialog...
If it helps I created this to distinguish between clicks inside panel to the rest of the chart. Its subject to improvements though.
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { panel.panelchartevent(id,lparam,dparam,sparam); if(id==CHARTEVENT_CLICK) { //--- Prepare variables int x =(int)lparam; int y =(int)dparam; datetime dt =0; double price =0; int window=0; if(panelClick(x,y)){ // do sth } } } bool panelClick(int x,int y) { int size=ObjectsTotal(0); for(int i=0; i<size; i++) { string name = ObjectName(0,i); if(ObjectGetInteger(0,name,OBJPROP_TYPE)!=OBJ_RECTANGLE_LABEL)continue; if(!StringFind(name,"Border"))continue; //If this ain't your case Go through objects list to find the name of the rectangle. //--- get label coordinates long obj_x=ObjectGetInteger(0,name,OBJPROP_XDISTANCE); long obj_y=ObjectGetInteger(0,name,OBJPROP_YDISTANCE); //--- get label size long obj_w=ObjectGetInteger(0,name,OBJPROP_XSIZE); long obj_h=ObjectGetInteger(0,name,OBJPROP_YSIZE); if(x>=obj_x && x<=(obj_x+obj_w) && y>=obj_y && y<=(obj_y+obj_h) )return true; //returns true if click is anywhere within the panel } return false; }
Mark531:
Hello,
Getting inspiration from the source example Controls.mq5, I created my own CDialogApp panel. It works, but I'm not wondering how to distinguish between events ocurring in the panel and events ocurring on the chart. To make it simple, I need to intercept both clicks on the chart and clicks on the panel's buttons.
My first attempt was the following:
But a click on a panel's button is also intercept by the CHARTEVENT_CLICK event handler, which is not desirable. How would you handle this?
Regards,
Mark
This is part of a project mine. Try this:
//+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- static bool ObjectClicked = false; switch(id) { case CHARTEVENT_CLICK : if(!ObjectClicked) OnChartClick(); ObjectClicked = false; break; case CHARTEVENT_OBJECT_CLICK : ObjectClicked = true; OnObjectClick(sparam); break; case CHARTEVENT_CHART_CHANGE : OnChartChange(); break; case CHARTEVENT_KEYDOWN : OnChartKeydown(lparam); break; case CHARTEVENT_MOUSE_MOVE : OnMouseMove(lparam, dparam, sparam); break; case CHARTEVENT_MOUSE_WHEEL : OnMouseWheel(lparam, dparam, sparam); break; default: if(id >= CHARTEVENT_CUSTOM) { const int custom_id = id - CHARTEVENT_CUSTOM; OnEventCustom(custom_id, lparam, dparam, sparam); } break; } gui.ChartEvent(id, lparam, dparam, sparam); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartClick(void) {Print(__FUNCSIG__);} //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnObjectClick(const string sparam) { bool is_gui_object = StringFind(sparam, gui.Name()) >= 0; if(is_gui_object) Print(__FUNCSIG__,", ",sparam," is gui object"); else Print(__FUNCSIG__,", ",sparam," is not gui object"); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
Getting inspiration from the source example Controls.mq5, I created my own CDialogApp panel. It works, but I'm not wondering how to distinguish between events ocurring in the panel and events ocurring on the chart. To make it simple, I need to intercept both clicks on the chart and clicks on the panel's buttons.
My first attempt was the following:
But a click on a panel's button is also intercept by the CHARTEVENT_CLICK event handler, which is not desirable. How would you handle this?
Regards,
Mark