FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Save dialog coordinates then redisplay same place
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Save dialog coordinates then redisplay same place
Posted: 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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Save dialog coordinates then redisplay same place
Posted: Tue Dec 09, 2014 09: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Save dialog coordinates then redisplay same place
Posted: Tue Dec 09, 2014 10:11 PM

James,

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

width = 101 - 100 = 1

or

width = 101 - 100 + 1 = 2

?

EMG

:-)

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Save dialog coordinates then redisplay same place
Posted: 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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Save dialog coordinates then redisplay same place
Posted: Tue Dec 09, 2014 10:36 PM

James,

no! :-)

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

EMG

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Save dialog coordinates then redisplay same place
Posted: 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.

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Save dialog coordinates then redisplay same place
Posted: Wed Dec 10, 2014 04: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 (fw): Select all Collapse
/*
Purpose : Test showing how to save/restore dialog location
Author  : James Bott, <!-- e --><a href="mailto:jbott@compuserve.com">jbott@compuserve.com</a><!-- e -->
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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Save dialog coordinates then redisplay same place
Posted: Thu Dec 11, 2014 01: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Save dialog coordinates then redisplay same place
Posted: Thu Dec 11, 2014 08:37 PM

Enrico,

Thanks for finding that.

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Save dialog coordinates then redisplay same place
Posted: Sat Dec 13, 2014 08:35 AM

Enrico, James,

Thanks!

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Save dialog coordinates then redisplay same place
Posted: Sat Dec 13, 2014 09:35 AM
Antonio,

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


Not that I'm aware of.

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Save dialog coordinates then redisplay same place
Posted: Sat Dec 13, 2014 09:39 AM

Cool :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion