OBJ_EDIT focus - page 2

 
Alain Verleyen:

It doesn't click inside the EDIT object on my side.


Yeah, it doesn't work for me either.


OP, any reason you are trying to accomplish this with a script? It seems like a task better suited for an indicator or EA. 

 
Alain Verleyen:

It doesn't click inside the EDIT object on my side.

It was my fault. I've used GetWindowRect() instead of ClientToScreen() now and I believe it solves this problem. It is interesting that I tried successfully ClientToScreen() yesterday and it worked but today it does not work and its coordinates are confusing. I'll be glad if you confirm the functionality on your side. I'll post new code below.
 
nicholishen:

Yeah, it doesn't work for me either.

I've written my notes to Alain Verleyen and if you want you can try my new code.
 

In this code I use GetWindowRect() to find out right coordinates. It would be great if you confirmed the functionality on your side. Thanks

#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);
#import

#define NAME   "TMP_EDIT_FOCUS"
#define X      (50)
#define Y      (50)
#define WIDTH  (300)
#define HEIGHT (20)

void OnStart()
  {
   ObjectDelete(0,NAME);
   ResetLastError();
   if(!ObjectCreate(0,NAME,OBJ_EDIT,0,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create \"Edit\" object! Error code = ",GetLastError());
      return;
     }
   ObjectSetInteger(0,NAME,OBJPROP_XDISTANCE,X);
   ObjectSetInteger(0,NAME,OBJPROP_YDISTANCE,Y);
   ObjectSetInteger(0,NAME,OBJPROP_XSIZE,WIDTH);
   ObjectSetInteger(0,NAME,OBJPROP_YSIZE,HEIGHT);
   ObjectSetInteger(0,NAME,OBJPROP_HIDDEN,false);
   ObjectSetString(0,NAME,OBJPROP_TEXT,"Object Edit with focus after creating");
   ChartRedraw();
//--- Simulate a click inside the OBJ_EDIT to get focus
   MouseClick(int ((2*X+WIDTH)/2),int((2*Y+HEIGHT)/2));
//---
   Sleep(10000); // Wait for 10 seconds
//--- Simulate a click outside (Left-Top corner of chart) the OBJ_EDIT to lose focus
   MouseClick(0,0);
//---
   ChartRedraw();
   ObjectSetString(0,NAME,OBJPROP_TEXT,"In 10 seconds the object Edit will be deleted");
   ChartRedraw();
   Sleep(10000); // Wait for 10 seconds
   ObjectDelete(0,NAME);
   ChartRedraw();
  }

void MouseClick(const int x, const int y)
  {
   Sleep(50);
   POINT clickPoint=ConvertXY(x,y);
   mouse_event(0x8007,clickPoint.posX,clickPoint.posY,0,0);
   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);
  }

 
nicholishen:

OP, any reason you are trying to accomplish this with a script? It seems like a task better suited for an indicator or EA. 

It's just a draft. I will use this principle primarily in EA, but also in scripts. So far I will not use this in the indicators, but after a minor adjustment (Sleep ()), it will be possible to use this in the indicators too. I've tried to use kernel32::Sleep() instead of Sleep() but without success for now.
 
Petr Nosek:
It's just a draft. I will use this principle primarily in EA, but also in scripts. So far I will not use this in the indicators, but after a minor adjustment (Sleep ()), it will be possible to use this in the indicators too. I've tried to use kernel32::Sleep() instead of Sleep() but without success for now.
You can't use sleep in the indicator thread. 
 
nicholishen:
You can't use sleep in the indicator thread. 
You're not quite right. You can use Sleep() in indicator but it doesn't do anything. I don't care because I don't want to use this principle in indicators. As I wrote I've tried to use kernel32::Sleep() instead of build-in  Sleep() but it causes error even in script.
 
Petr Nosek:
You can use Sleep() in indicator but it doesn't do anything.

lol, okay. 

 
Petr Nosek:

In this code I use GetWindowRect() to find out right coordinates. It would be great if you confirmed the functionality on your side. Thanks

Yes it works. 
 
Alain Verleyen:
Yes it works. 

Thank you for your reply ;-)