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.
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 strictstruct RECT
{
int Left; // x position of upper-left cornerint Top; // y position of upper-left cornerint Right; // x position of lower-right cornerint Bottom; // y position of lower-right corner
};
struct POINT
{
int posX; // x positionint 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)
voidOnStart()
{
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 secondsObjectDelete(0,NAME);
ChartRedraw();
}
void MouseClick(constint x, constint y)
{
Sleep(50);
POINT clickPoint=ConvertXY(x,y);
mouse_event(0x8007,clickPoint.posX,clickPoint.posY,0,0);
Sleep(50);
}
POINT ConvertXY(constint x,constint 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);
}
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.
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.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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.
It doesn't click inside the EDIT object on my side.
Yeah, it doesn't work for me either.
In this code I use GetWindowRect() to find out right coordinates. It would be great if you confirmed the functionality on your side. Thanks
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.
You can't use sleep in the indicator thread.
You can use Sleep() in indicator but it doesn't do anything.
lol, okay.
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.
Thank you for your reply ;-)