Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1138

 
Igor Makanu:

I haven't used SB for a long time, I don't remember half of it, but try making a software selection and deselecting by doing ChartRedraw() of the OBJ_EDIT object each time, you can get the names of the objects from SB, there must be a Name method

what if?

HH: and Sleep() is probably needed for ChartRedraw() , but Sleep() does not work in indicators

If you mean to make the object property OBJPROP_SELECTED TRUE, this is not the case. Because in this case the object will be highlighted on the chart, but the input box will not become active.
 
Maksym Mudrakov:
If you mean to make the object property OBJPROP_SELECTED TRUE, that's not it. Because in this case the object will be highlighted on the chart, but the input box will not become active.

checked on all panels, it doesn't work highlighting the OBJ_EDIT object

I don't know, search the forum:

"tab"

"tab"

"input focus"

 
Is there any way to update the MQL5/logs/*.log file without closing the terminal? To view its fresh contents.
 
ascerdfg:
Is there any way to update MQL5/logs/*.log file without closing the terminal? To view its fresh contents.

right-click in the terminal in the context menu - open , this allows access to the log file

not conveniently done

 
Igor Makanu:

right-click in the terminal in the context menu - open , this allows access to the log file

not convenient

Where do I click?
 
ascerdfg:
Where do I click?

Rzewski had to be shut up...


 
Maksym Mudrakov:

The graph has two objects of type OBJ_EDIT

The goal is to make the transition between these two input fields by pressing Tab.

The main problem is not reading the keyboard event, but how to make the input field active programmatically.

I understand that you need to use user32.dll, but since I'm not good at it, please help.

Thank you.

The solution is found:

#property strict

struct RECT
  {
   int               Left;   // x position of upper-left corner
   int               Top;    // y position of upper-left corner
   int               Right;  // x position of lower-right corner
   int               Bottom; // y position of lower-right corner
  };
struct POINT
  {
   int               posX;   // x position
   int               posY;   // y position
  };

#import "user32.dll"
void  mouse_event(int dwFlags,int dx,int dy,int dwData,int dwExtraInfo);
bool  GetWindowRect(int hWnd,RECT &lpRect);
int   GetSystemMetrics(int nIndex);
bool  GetCursorPos(POINT &lpPoint);
bool  SetCursorPos(int x,int y);
#import

string edits[], pref;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   pref="EA_EDIT_SELECT_";
   int size=6;
   ArrayResize(edits,size);

   int width=100, heigh=25;
   int x=width, y=heigh;
   for(int i=0; i<size; i++)
     {
      string num=(string)(i/2+1);
      string text="Name ";
      edits[i]=pref+(string)i;
      if(i%2==0)
        {
         text="First "+text+num;
         x=width;
         y+=heigh+5;
        }
      else
        {
         text="Last "+text+num;
         x=2*width+5;
        }
      EditCreate(edits[i],x,y,width,heigh,text);
     }
   EventEditSelect(edits);
   return(INIT_SUCCEEDED);

  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,pref,-1,-1);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id == CHARTEVENT_KEYDOWN)
      EventEditSelect(edits);
   else
      if(id == CHARTEVENT_OBJECT_ENDEDIT)
        {
         bool stateTab=TerminalInfoInteger(TERMINAL_KEYSTATE_TAB)<0;
         if(stateTab)
            EventEditSelect(edits);
        }
  }
//--------------------------------------------------------------------+
//      Create Edit                                                   |
//--------------------------------------------------------------------+
void EditCreate(string           name="Edit",              // object name
                int              x=0,                      // X coordinate
                int              y=0,                      // Y coordinate
                int              width=50,                 // width
                int              height=18,                // height
                string           text="Text")              // text
  {
   ObjectCreate(0,name,OBJ_EDIT,0,0,0) ;
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
   ObjectSetString(0,name,OBJPROP_TEXT,text);
   ObjectSetString(0,name,OBJPROP_FONT,"Arial");
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,12);
   ObjectSetInteger(0,name,OBJPROP_ALIGN,ALIGN_CENTER);
   ObjectSetInteger(0,name,OBJPROP_READONLY,false);
   ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetInteger(0,name,OBJPROP_COLOR,clrBlack);
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,clrWhite);
   ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,clrGray);
   ObjectSetInteger(0,name,OBJPROP_BACK,false);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
  }
//--------------------------------------------------------------------+
//      MOVE BETWEEN OBJ_EDIT BY TAB KEY                              |
//--------------------------------------------------------------------+
void EventEditSelect(string &editNames[])
  {
   bool back=TerminalInfoInteger(TERMINAL_KEYSTATE_SHIFT)<0;

   int size=ArraySize(editNames);
   if(size==0)
      return;
   static int index=0;

   if(!back)
     {
      if(index==size-1)
         index=0;
      else
         index++;
     }
   else
     {
      if(index==0)
         index=size-1;
      else
         index--;
     }

   string name=editNames[index];
   int x=(int)ObjectGetInteger(0,name,OBJPROP_XDISTANCE);
   int y=(int)ObjectGetInteger(0,name,OBJPROP_YDISTANCE);
   int width=(int)ObjectGetInteger(0,name,OBJPROP_XSIZE);
   int height=(int)ObjectGetInteger(0,name,OBJPROP_YSIZE);

   MouseClick(int ((2*x+width)/2),int((2*y+height)/2));
  }
void MouseClick(const int x, const int y)
  {
   Sleep(50);
   POINT currentPoint;
   GetCursorPos(currentPoint);
   POINT clickPoint=ConvertXY(x,y);
   mouse_event(0x8007,clickPoint.posX,clickPoint.posY,0,0);
   SetCursorPos(currentPoint.posX,currentPoint.posY);
   Sleep(50);
  }
POINT ConvertXY(const int x,const int y)
  {
   POINT AbsolutePoint;
   RECT  WndRect;
   int BorderX=5,BorderY=5;
   int screenX=GetSystemMetrics(0);
   int screenY=GetSystemMetrics(1);
   GetWindowRect(WindowHandle(_Symbol,_Period),WndRect);
   AbsolutePoint.posX=int ((x+WndRect.Left+BorderX)*65535/screenX);
   AbsolutePoint.posY=int ((y+WndRect.Top +BorderY)*65535/screenY);
   return(AbsolutePoint);
  }
 
MQL5, ObjectCreate doesn't draw anything, objects don't even appear in object list. Creation is done at OnInit, maybe that's the problem?
At the same time, if we remove the robot from the chart, the created objects will be displayed
 
Roman Sharanov:
MQL5, ObjectCreate doesn't draw anything, objects don't even appear in object list. Creation is done at OnInit, maybe that's the problem?
However, if we remove the robot from the chart, the created objects will be displayed

It's possible that the price and time for the object coordinates are equal to zero. Check it this way: Press Ctrl+B, in the dialog box that appears, press the "All" button and look at the list of existing objects. If there is one, open properties and see coordinates.

 
Artyom Trishkin:

Rzewski had to be shut up...


At what point do you have to right-click?
Reason: