Dialog Box Save Last Position

 

Hello,

I have these functions:

void PositionSave()
  {

   int handle = FileOpen(__FILE__+".bin",FILE_WRITE|FILE_BIN);
   if(handle==INVALID_HANDLE)
     {
      Print("Handle Invalid");
      return;
     }

   else
     {
      FileWriteInteger(handle,MyDialog.Top());
      FileWriteInteger(handle,MyDialog.Left());
      FileClose(handle);

     }
  }
//+------------------------------------------------------------------+
void PositionGet()
  {
   int handle = FileOpen(__FILE__+".bin",FILE_READ|FILE_BIN);
   if(handle==INVALID_HANDLE)
     {
      Print("Handle Invalid");
      return;
     }

   else
     {

      AppDialogTop= FileReadInteger(handle);
      AppDialogLeft= FileReadInteger(handle);
      FileClose(handle);


     }

  }

I am trying to make the dialog box to open in the same place where it was last time before closed it. So I call PositionSave() in OnDeinit() and PositionGet() in the OnInit(). But something is wrong because is not working ( it is opening with diferent shape). I use the same functions on another dialog box in a indicator. This one is an EA. Kindly advice!

 
DannyBass:

Hello,

I have these functions:

I am trying to make the dialog box to open in the same place where it was last time before closed it. So I call PositionSave() in OnDeinit() and PositionGet() in the OnInit(). But something is wrong because is not working ( it is opening with diferent shape). I use the same functions on another dialog box in a indicator. This one is an EA. Kindly advice!

I don't know how the dialogs library updates the position of the dialog but it probably is on drag end so , if you place a change detector on the events code under the passing of the event to the dialog

if(AppDialogTop!=MyDialog.Top()||AppDialogLeft!=MyDialog.Left()){

}

 and do the save inside those.

If the dialogs library updates this on mouse move though you'll need to establish the drag end (if detectable) in a custom way.

(Also ,different shape as in the contents of the box have an offset ? If yes the above may not be the solution) 
 
Lorentzos Roussos #:

I don't know how the dialogs library updates the position of the dialog but it probably is on drag end so , if you place a change detector on the events code under the passing of the event to the dialog

 and do the save inside those.

If the dialogs library updates this on mouse move though you'll need to establish the drag end (if detectable) in a custom way.

(Also ,different shape as in the contents of the box have an offset ? If yes the above may not be the solution) 

This is what I got after I reopen

Files:
After.jpg  325 kb
Before.jpg  297 kb
 
DannyBass #:

This is what I got after I reopen

Are you creating the dialog before you load the coordinates ?

 
Lorentzos Roussos #:

Are you creating the dialog before you load the coordinates ?

I am sorry!

Found the mistake. When I created the Dialog Box, by mistake, I put Top coordonate under Left coordonate spot, and Left coordonate under Top coordonate spot. 

 
DannyBass #:

I am sorry!

Found the mistake. When I created the Dialog Box, by mistake, I put Top coordonate under Left coordonate spot, and Left coordonate under Top coordonate spot. 

Great , it happens :)