Save dialog coordinates then redisplay same place

Re: Save dialog coordinates then redisplay same place

Postby Antonio Linares » Tue Dec 09, 2014 10:24 am

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...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Save dialog coordinates then redisplay same place

Postby James Bott » Tue Dec 09, 2014 9:07 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Save dialog coordinates then redisplay same place

Postby Enrico Maria Giordano » Tue Dec 09, 2014 10:11 pm

James,

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

width = 101 - 100 = 1

or

width = 101 - 100 + 1 = 2

?

:-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Save dialog coordinates then redisplay same place

Postby James Bott » Tue Dec 09, 2014 10:30 pm

Enrico,

I guess you are confirming my point?

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

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Save dialog coordinates then redisplay same place

Postby Enrico Maria Giordano » Tue Dec 09, 2014 10:36 pm

James,

no! :-)

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Save dialog coordinates then redisplay same place

Postby James Bott » Tue Dec 09, 2014 10:51 pm

Enrico,

Ok, I see what you're saying, but my example seems to be working. I'll do more tests.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Save dialog coordinates then redisplay same place

Postby James Bott » Wed Dec 10, 2014 4:15 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Save dialog coordinates then redisplay same place

Postby Enrico Maria Giordano » Thu Dec 11, 2014 1:41 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Save dialog coordinates then redisplay same place

Postby James Bott » Thu Dec 11, 2014 8:37 pm

Enrico,

Thanks for finding that.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Save dialog coordinates then redisplay same place

Postby Antonio Linares » Sat Dec 13, 2014 8:35 am

Enrico, James,

Thanks!

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Save dialog coordinates then redisplay same place

Postby Enrico Maria Giordano » Sat Dec 13, 2014 9:35 am

Antonio,

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


Not that I'm aware of.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Save dialog coordinates then redisplay same place

Postby Antonio Linares » Sat Dec 13, 2014 9:39 am

Cool :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 79 guests