Page 2 of 2

Re: Save dialog coordinates then redisplay same place

PostPosted: Tue Dec 09, 2014 10:24 am
by Antonio Linares
James,

it is just a guess. To properly calculate a dimension we need to use +1.

If +1 is not needed then somewhere there is a wrong code...

Re: Save dialog coordinates then redisplay same place

PostPosted: Tue Dec 09, 2014 9:07 pm
by James Bott
Sorry, I don't understand. The coordinates are aCoord := {100,100,300,500}, so the dimensions are:

width:= 500 - 100 = 400
height:= 300 - 100 = 200

Re: Save dialog coordinates then redisplay same place

PostPosted: Tue Dec 09, 2014 10:11 pm
by Enrico Maria Giordano
James,

aCoord := {100,100,101,101}

width = 101 - 100 = 1

or

width = 101 - 100 + 1 = 2

?

:-)

EMG

Re: Save dialog coordinates then redisplay same place

PostPosted: Tue Dec 09, 2014 10:30 pm
by James Bott
Enrico,

I guess you are confirming my point?

The +1 in not needed, at least in this instance.

James

Re: Save dialog coordinates then redisplay same place

PostPosted: Tue Dec 09, 2014 10:36 pm
by Enrico Maria Giordano
James,

no! :-)

Size of 100, 101 is 2 pixels (100 and 101) not 1 pixel.

EMG

Re: Save dialog coordinates then redisplay same place

PostPosted: Tue Dec 09, 2014 10:51 pm
by James Bott
Enrico,

Ok, I see what you're saying, but my example seems to be working. I'll do more tests.

Re: Save dialog coordinates then redisplay same place

PostPosted: Wed Dec 10, 2014 4:15 pm
by James Bott
Enrico,

OK, I have done some tests and if you add 1 to the width and height, each time you save and restore it, the values grow by one. Try the test code below.

Although 101-100 = 1 and the true width is 2 pixels, it seems that Windows (or FW, or (x)Harbour) draws it correctly when you specify the width as 1.

James

Code: Select all  Expand view
/*
Purpose : Test showing how to save/restore dialog location
Author  : James Bott, jbott@compuserve.com
Date    : 12/3/2014 2:09:38 PM
Language: Fivewin/xHarbour

Notes   : Drag the dialog to a new position, then close it, then press the button
          and the dialog will be restored in the last position.
         
          The location is saved using the VALID clause and restored using oDlg:Move()
         
          The location is saved in memory here, but you could use a file to restore
          it.
*/


#include "fivewin.ch"

static aCoord

Function main()
   local oWnd, oBar, oBtn

   aCoord := {100,100,300,500}
   
   define window oWnd
   
   define buttonbar oBar of oWnd
   define button oBtn of oBar action MakeDlg(saveRestore())
 
   activate window oWnd maximized on init makeDlg()
   
return nil

Function MakeDlg(aRect)
   local oDlg
   Local nTop,nLeft,nWidth,nHeight
   
   define dialog oDlg of wndMain()
   
   @ 2,4 BUTTON "Get Width/Height" ;
      ACTION ;
      msgInfo( cValToChar(getWndRect(oDlg:hWnd)[3]-getWndRect(oDlg:hWnd)[1] ) +"/"+;
       cValToChar(getWndRect(oDlg:hWnd)[4]-getWndRect(oDlg:hWnd)[2]) ) ;
      size 100,15
   
   aRect:= saveRestore()
   nTop:= aRect[1]      
   nLeft:= aRect[2]
   // test only. Trying adding +1
   nWidth:= aRect[4] - aRect[2] +1
   nHeight:= aRect[3] - aRect[1] +1
   
   activate dialog oDlg centered ;
     VALID ( saveRestore(getWndRect(oDlg:hWnd)), .t.);
     ON INIT oDlg:move(nTop, nLeft, nWidth, nHeight, .t.)
         
return nil

function saveRestore(aRect)
   if aRect != nil
      aCoord := aclone(aRect)
   endif
return aCoord



// eof

Re: Save dialog coordinates then redisplay same place

PostPosted: Thu Dec 11, 2014 1:41 pm
by Enrico Maria Giordano
James,

from the MSDN, GetWindowRect() function:

In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.


So, the +1 has been already taken into account.

EMG

Re: Save dialog coordinates then redisplay same place

PostPosted: Thu Dec 11, 2014 8:37 pm
by James Bott
Enrico,

Thanks for finding that.

Re: Save dialog coordinates then redisplay same place

PostPosted: Sat Dec 13, 2014 8:35 am
by Antonio Linares
Enrico, James,

Thanks!

So do we need to modify something in FWH regarding this ?

Re: Save dialog coordinates then redisplay same place

PostPosted: Sat Dec 13, 2014 9:35 am
by Enrico Maria Giordano
Antonio,

Antonio Linares wrote:So do we need to modify something in FWH regarding this ?


Not that I'm aware of.

EMG

Re: Save dialog coordinates then redisplay same place

PostPosted: Sat Dec 13, 2014 9:39 am
by Antonio Linares
Cool :-)