How do you detect if chart window is active?

 

How do you detect if chart window is active?

If active chart window is maximized, one may think that all other background windows are maximized too, but actually they become windowed, and their width/height is changed. So if anyone using calculating each tick to place object in center, then, when you away from this window, the object is in not center, because width has changed. Then, when you switch to window back, you can see objects that is moved relative to center, and then it redraws, and objects 'jumps' to center again. And this movement is too noticeable and undesirable. Use timer to redraw too fast so you can not notice? Too obvious, and not suitable.

If not calculate center of window each tick, and calculate only on init, then, if multiple experts are opened, objects will be on the center only on one window, which was active at time of start, and on all other windows it will be shifted. It will not move, but it will not in the center. And if you intentionally change window size, the objects will be not in center.

So, there should be a way to not redraw window if chart window is not active, or save coordinates - which - what - are you sure that current are correct ones, and user is not changing window size intentionally?
 
//SCREEN CHANGE TRACKINMG 
int screen_entx,screen_enty,screen_pretx,screen_prety;
bool ChangeScreen=false;
uint ChangeTicks=0;
bool ScreenChanging=false;

int OnInit()
  {
  ScreenChanging=false;
  ChangeScreen=false;
  EventSetMillisecondTimer(100);
  return(INIT_SUCCEEDED);
  }

void OnTimer()
  {
  uint tnow=GetTickCount();
  if(ChangeScreen==true&&GetTickCount()>ChangeTicks&&ScreenChanging==false)
  {
  ScreenChanging=true;
  //Resize+Recenter Operations Go Here
    //...
  //Resize+Recenter Operations End Here 
   ChangeScreen=false;
   ScreenChanging=false;
  }   
  }

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
  //AUTO RESIZE CAPTURE 
 if(id==CHARTEVENT_CHART_CHANGE)
 {
   //if the window is active
     bool v=ChartGetInteger(0,CHART_BRING_TO_TOP);
     if(v)
     {
      screen_pretx=screen_entx;
      screen_prety=screen_enty;   
      screen_entx=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
      screen_enty=ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
      //and finally if the screen size has changed
      if(screen_entx!=screen_pretx||screen_enty!=screen_prety)
       {
       Print("Previous X :"+IntegerToString(screen_pretx)+" Y :"+IntegerToString(screen_prety));
       Print("Now      X :"+IntegerToString(screen_entx)+" Y :"+IntegerToString(screen_enty));
       ChangeScreen=true;
       ChangeTicks=GetTickCount()+300;
       }
      //and finally if the screen size has changed ends here 
    }
    //if the window is active ends here 
 }
//track changes in chart ends here   
}
 
Thank you. In documentation stated that CHART_BRING_TO_TOP is a write-only property, so I didn't tried it. But actually it works.
 
aura:
Thank you. In documentation stated that CHART_BRING_TO_TOP is a write-only property, so I didn't tried it. But actually it works.

indeed , it was the last thing i tried when i was looking for a solution too . 
I forgot you need to initialize screen_entx and screen_enty (with pixel data) on init as well.

Reason: