Calculate position

Re: Calculate position

Postby ukoenig » Fri Jul 08, 2011 6:35 pm

Marco,

I got it working.
There is a Difference in saved / displayed Dlg-left and Bottom.
I have to detect where it comes from. With the adjustment, it works fine.

oDlg:Move( nDTop, nDLeft, nDRight - nDLeft - 18, nDBottom - nDTop - 38 ), oDlg:CoorsUpdate() )
( otherwise, these values are counted at Restart )

You can find out the Difference with using :

oDlg:Move( nDTop, nDLeft, nDRight - nDLeft, nDBottom - nDTop), oDlg:CoorsUpdate() )

Code: Select all  Expand view

#include "fivewin.ch"

STATIC oMain, oDlg, nDTop := 100, nDLeft := 200, nDBottom := 600, nDRight := 800, lActivated := .F., c_Path
STATIC cDTop := "100",   cDLeft := "200", cDBottom := "600", cDRight := "800"   

REQUEST HB_GT_GUI_DEFAULT
#define crlf CHR(13)+CHR(10)

FUNCTION Main()
LOCAL oBut1, oBut2
LOCAL oDTop, oDLeft
LOCAL oDBottom, oDRight

c_Path := CURDRIVE() + ":\" + GETCURDIR()
GET_INI()

DEFINE WINDOW oMain

@ 1 ,  1  BUTTON oBut1 PROMPT "
Dialog" ;
ACTION IIF( lActivated = .F., Dialogo( oDTop, oDLeft, oDBottom, oDRight ), NIL ) size 100 , 30

@ 1 , 90  BUTTON oBut2 PROMPT "
Reset"  ACTION ( nDTop := 100 , nDLeft := 100 , nDBottom := 600 , nDRight := 800 , ;
IIF( lActivated = .T., oDlg:End(), NIL ), ;
      DIALOGO( oDTop, oDLeft, oDBottom, oDRight ) ) SIZE 100 , 30

@ 1 ,  130  BUTTON oBut3 PROMPT "
Exit" ;
ACTION oMain:End() size 100 , 30

@ 1 , 20 GET oDTop  VAR nDTop  OF oMain  SIZE 50 , 20 UPDATE
@ 1 , 30 GET oDLeft  VAR nDLeft  OF oMain  SIZE 50 , 20 UPDATE
@ 1 , 40 GET oDBottom VAR nDBottom OF oMain  SIZE 50 , 20 UPDATE
@ 1 , 50 GET oDRight  VAR nDRight  OF oMain  SIZE 50 , 20 UPDATE

ACTIVATE WINDOW oMain MAXIMIZED

SAVE_INI()

RETURN NIL

//---------------

FUNCTION DIALOGO( oDTop, oDLeft, oDBottom, oDRight )

lActivated := .T.

// From Top / Left TO Height / Width
// ---------------------------------------------
DEFINE DIALOG oDlg FROM nDTop, nDLeft TO  nDBottom, nDRight OF oMain PIXEL ;
STYLE nOr( WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, WS_MINIMIZEBOX, WS_MAXIMIZEBOX ) ;
TITLE "
Dialog-position and Size : Top " + Alltrim( STR( nDTop )) + ;
          "
,  Left : "  + Alltrim( STR( nDLeft )) + ;
          "
,  Bottom : " + Alltrim( STR( nDBottom )) + ;
          "
,  Right : "  + Alltrim( STR( nDRight ))

oDlg:bResized = { || oDlg:CoorsUpdate(), AGGIORNA(oDTop, oDLeft, oDBottom, oDRight ) }
oDlg:bMoved := {|| oDlg:CoorsUpdate(), AGGIORNA(oDTop, oDLeft, oDBottom, oDRight ) }

ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT ( oDlg:Move( nDTop, nDLeft, nDRight - nDLeft - 18, nDBottom - nDTop - 38 ), oDlg:CoorsUpdate() )

// oDlg:Move Top / Left , Width / Height

RETURN NIL

// ----------------------------

FUNCTION AGGIORNA(oDTop, oDLeft, oDBottom, oDRight)

nDTop := oDlg:nTop
nDLeft := oDlg:nLeft
nDBottom := oDlg:nBottom
nDRight := oDlg:nRight

oDTop:Refresh()
oDLeft:Refresh()
oDBottom:Refresh()
oDRight:Refresh()

oDlg:cTitle := "
Dialog-position and Size : Top " + Alltrim( STR( nDTop )) + ;
          "
,  Left : "  + Alltrim( STR( nDLeft )) + ;
          "
,  Bottom : " + Alltrim( STR( nDBottom )) + ;
          "
,  Right : "  + Alltrim( STR( nDRight ))

RETURN NIL

//-------- Read INI ----------------------

FUNCTION GET_INI()
Local oInifile

IF !FILE ( c_path + "
\SETTINGS.ini" )
    SAVE_INI()
ELSE
    INI oInifile FILE c_path + "
\SETTINGS.ini"
        GET  cDTop      SECTION "
Dialog"    ENTRY "DlgTop"      OF oInifile DEFAULT "100"
        GET  cDLeft     SECTION "
Dialog"    ENTRY "DlgLeft"     OF oInifile DEFAULT "200"
        GET  cDBottom   SECTION "
Dialog"    ENTRY "DlgBottom"   OF oInifile DEFAULT "600"
        GET  cDRight        SECTION "
Dialog"    ENTRY "DlgRight"        OF oInifile DEFAULT "800"
    ENDINI
ENDIF
nDTop := VAL(cDTop)
nDLeft := VAL(cDLeft)
nDBottom := VAL(cDBottom)
nDRight := VAL(cDRight)

RETURN( NIL )

// ---------   Write INI ------------------------

FUNCTION SAVE_INI()
LOCAL cIniFile := c_path + "
\SETTINGS.INI"

lSysini := .T.

IF WritePProString( "
Dialog", "DlgTop", ALLTRIM(STR(nDTop)) ,  cIniFile ) = .F.
        lSysini := .F.
ENDIF
IF WritePProString( "
Dialog", "DlgLeft", ALLTRIM(STR(nDLeft)) ,  cIniFile ) = .F.
        lSysini := .F.
ENDIF
IF WritePProString( "
Dialog", "DlgBottom", ALLTRIM(STR(nDBottom)) ,  cIniFile ) = .F.
        lSysini := .F.
ENDIF
IF WritePProString( "
Dialog", "DlgRight", ALLTRIM(STR(nDRight)) ,  cIniFile ) = .F.
        lSysini := .F.
ENDIF

IF lSysini = .F. .or. !FILE( cInifile )
    MsgAlert("
Not possible, to write in  INI-File", "INI-File")
ENDIF

RETURN( NIL )


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Calculate position

Postby nageswaragunupudi » Sat Jul 09, 2011 5:51 pm

MarcoBoschi wrote:Enrico,
when I click the first time, If I dont' change the for values the dialog has to be created in 100 , 100 , 600 , 800
But it is positioned in 100 , 100 , 629 , 810
I Save these new positions and nex time I find the dialog in another position.
I have to calculate this delta 629 - 600 = 29 for Height and 810 - 800 = 10 for length
If I modified screen resolution or properties of windows desktop these two deltas are different.

Many thanks

marco

I understand that your requirement is to save the size and position of the dialog and when the dialog is created next time, to create at the same position with the same size.

For this purpose, I advise you to save and restore width and height but not right and bottom. Please do not save when minimized or maximized.

Here is a working sample:

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   @ 40,40 BUTTON "Dialog" OF oWnd SIZE 80,28 PIXEL ACTION CreateDlg()

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil

static function CreateDlg()

   static lOk  := .t.

   local oDlg
   local lInit := .t.

   if ! lOK
      return nil
   endif

   DEFINE DIALOG oDlg ;
      STYLE nOr( WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, ;
      WS_MINIMIZEBOX, WS_MAXIMIZEBOX )

   oDlg:bMoved    := { || If( ! lInit, SaveDlgPos( oDlg ), nil ) }
   oDlg:bResized  := { || SaveDlgPos( oDlg ) }

   ACTIVATE DIALOG oDlg ON INIT ( RestoreDlgPos( oDlg ), lInit := .f. ) ;
      VALID ( SaveDlgPos( oDlg ), lOK := .t. )

return nil

static function SaveDlgPos( oDlg )

   local oIni

   oIni     := TIni():New( ".\dlgpos.ini" )

   if ! oDlg:IsIconic() .and. ! IsZoomed( oDlg:hWnd )
      oDlg:CoorsUpdate()
      oIni:Set( "Dialog", "nTop",    oDlg:nTop    )
      oIni:Set( "Dialog", "nLeft",   oDlg:nLeft   )
      oIni:Set( "Dialog", "nWidth",  oDlg:nWidth  )
      oIni:Set( "Dialog", "nHeight", oDlg:nHeight )
   endif

return nil

static function RestoreDlgPos( oDlg )

   local oIni
   local nTop,nLeft, nHeight, nWidth, nSize

   oIni     := TIni():New( ".\dlgpos.ini" )
   nTop     := oIni:Get( "Dialog", "nTop",    100 )
   nLeft    := oIni:Get( "Dialog", "nLeft",   100 )
   nWidth   := oIni:Get( "Dialog", "nWidth",  700 )
   nHeight  := oIni:Get( "Dialog", "nHeight", 500 )

   oDlg:Move( nTop, nLeft, nWidth, nHeight )

return nil

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate position

Postby MarcoBoschi » Sun Jul 10, 2011 11:35 am

Probably I'm using an old version

Application
===========
Path and name: C:\Fwh\samples\nage.exe (32 bits)
Size: 1,904,128 bytes
Time from start: 0 hours 0 mins 2 secs
Error occurred at: 07/10/11, 13:33:51
Error description: Warning BASE/1004 Message not found: TDIALOG:ISICONIC
Args:


11/09/2009 10:15 543 readme.txt
29/09/2009 16:34 423.424 Fivehc.lib
18/10/2009 08:20 716.296 Fivehcm.lib
26/10/2009 07:47 1.880.576 Fiveh.lib
26/10/2009 07:47 2.957.968 Fivehm.lib
26/10/2009 07:47 3.085.878 Fivehmx.lib
26/10/2009 07:47 1.935.872 Fivehx.lib
17/03/2011 19:51 <DIR> .
17/03/2011 19:51 <DIR> ..
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby Daniel Garcia-Gil » Sun Jul 10, 2011 12:02 pm

Marco


change by IsIconic( oDlg:hWnd )
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Calculate position

Postby MarcoBoschi » Mon Jul 11, 2011 7:07 am

Thanks to all
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby MarcoBoschi » Mon Jul 11, 2011 11:15 am

To nage,
Please Try this modified version of your source code.
I think that we are close to solving the problem
Many thanks again

marco

Download nage.res at

http://www.marcoboschi.it/public/nage.zip

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   @ 40,40 BUTTON "Dialog" OF oWnd SIZE 80,28 PIXEL ACTION CreateDlg()

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil

static function CreateDlg()

   static lOk  := .t.

   local oDlg
   local lInit := .t.

   if ! lOK
      return nil
   endif

   DEFINE DIALOG oDlg RESOURCE "DIALOGO" RESOURCE "DIALOGO" ; // the problem is at this point
      STYLE nOr( WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, ;
      WS_MINIMIZEBOX, WS_MAXIMIZEBOX )

   oDlg:bMoved    := { || If( ! lInit, SaveDlgPos( oDlg ), nil ) }
   oDlg:bResized  := { || SaveDlgPos( oDlg ) }

   ACTIVATE DIALOG oDlg ON INIT ( RestoreDlgPos( oDlg ), lInit := .f. ) ;
      VALID ( SaveDlgPos( oDlg ), lOK := .t. )

return nil

static function SaveDlgPos( oDlg )

   local oIni

   oIni     := TIni():New( ".\dlgpos.ini" )

   if !  IsIconic( oDlg:hWnd ) .and. ! IsZoomed( oDlg:hWnd )
      oDlg:CoorsUpdate()
      oIni:Set( "Dialog", "nTop",    oDlg:nTop    )
      oIni:Set( "Dialog", "nLeft",   oDlg:nLeft   )
      oIni:Set( "Dialog", "nWidth",  oDlg:nWidth  )
      oIni:Set( "Dialog", "nHeight", oDlg:nHeight )
   endif

return nil

static function RestoreDlgPos( oDlg )

   local oIni
   local nTop,nLeft, nHeight, nWidth

   oIni     := TIni():New( ".\dlgpos.ini" )
   nTop     := oIni:Get( "Dialog", "nTop",    100 )
   nLeft    := oIni:Get( "Dialog", "nLeft",   100 )
   nWidth   := oIni:Get( "Dialog", "nWidth",  700 )
   nHeight  := oIni:Get( "Dialog", "nHeight", 500 )

   oDlg:Move( nTop, nLeft, nWidth, nHeight )

return nil

 
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby nageswaragunupudi » Mon Jul 11, 2011 11:57 am

This program is working fine here with your resources.

Please note that I have made this very minor modification to your code:
I have substituted your code:
Code: Select all  Expand view
DEFINE DIALOG oDlg RESOURCE "DIALOGO" RESOURCE "DIALOGO" ;

with
Code: Select all  Expand view
DEFINE DIALOG oDlg RESOURCE "DIALOGO"  ;

Probably this is just a typo in the code you posted.

I do not see any need to change the program
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate position

Postby MarcoBoschi » Mon Jul 11, 2011 12:03 pm

Ok,
I think it's a bug of my version

11/09/2009 10:15 543 readme.txt
29/09/2009 16:34 423.424 Fivehc.lib
18/10/2009 08:20 716.296 Fivehcm.lib
26/10/2009 07:47 1.880.576 Fiveh.lib
26/10/2009 07:47 2.957.968 Fivehm.lib
26/10/2009 07:47 3.085.878 Fivehmx.lib
26/10/2009 07:47 1.935.872 Fivehx.lib
Could you compile and send me exe?
Thanks again

marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby nageswaragunupudi » Mon Jul 11, 2011 1:04 pm

Please send me an email to nageswaragunupudi@gmail.com.
In reply I shall send you the application.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate position

Postby nageswaragunupudi » Tue Jul 12, 2011 12:15 pm

The above solution was not correct.
This appears to be the correct solution
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   @ 40,40 BUTTON "Dialog" OF oWnd SIZE 80,28 PIXEL ACTION CreateDlg()

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil

static function CreateDlg()

   static lOk  := .t.

   local oDlg
   local lInit := .t.

   if ! lOK
      return nil
   endif

   DEFINE DIALOG oDlg RESOURCE "DIALOGO" ;
      STYLE nOr( WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, ;
      WS_MINIMIZEBOX, WS_MAXIMIZEBOX )

   oDlg:bMoved    := { || If( ! lInit, SaveDlgPos( oDlg ), nil ) }
   oDlg:bResized  := { || SaveDlgPos( oDlg ) }

   ACTIVATE DIALOG oDlg ON INIT ( RestoreDlgPos( oDlg ), lInit := .f. ) ;
      VALID ( SaveDlgPos( oDlg ), lOK := .t. )

return nil

static function SaveDlgPos( oDlg )

   local oIni, oRect

   oIni     := TIni():New( ".\dlgpos.ini" )

   if ! IsIconic( oDlg:hWnd ) .and. ! IsZoomed( oDlg:hWnd )
      oRect    := oDlg:GetRect()
      oIni:Set( "Dialog", "nTop",    oRect:nTop    )
      oIni:Set( "Dialog", "nLeft",   oRect:nLeft   )
      oIni:Set( "Dialog", "nBottom", oRect:nBottom )
      oIni:Set( "Dialog", "nRight",  oRect:nRight  )
   endif

return nil

static function RestoreDlgPos( oDlg )

   local oIni
   local nTop,nLeft, nBottom, nRight

   oIni     := TIni():New( ".\dlgpos.ini" )
   nTop     := oIni:Get( "Dialog", "nTop",    100 )
   nLeft    := oIni:Get( "Dialog", "nLeft",   100 )
   nBottom  := oIni:Get( "Dialog", "nBottom", 600 )
   nRight   := oIni:Get( "Dialog", "nRight",  800 )

   oDlg:Move( nTop, nLeft, nRight - nLeft, nBottom - nTop )

return nil

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate position

Postby MarcoBoschi » Wed Jul 13, 2011 7:08 am

OK
Problem solved!

King regards

marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 63 guests